2022-12-09 10:52:17 +01:00
|
|
|
<?php
|
|
|
|
|
2022-12-13 12:04:19 +01:00
|
|
|
namespace Tests\Feature\Http;
|
2022-12-09 10:52:17 +01:00
|
|
|
|
2023-08-01 11:28:27 +02:00
|
|
|
use App\Http\Controllers\SystemController;
|
2022-12-09 10:52:17 +01:00
|
|
|
use App\Models\User;
|
|
|
|
use App\Services\ReleaseRadarService;
|
2022-12-13 12:07:29 +01:00
|
|
|
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
2023-08-01 11:28:27 +02:00
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
2022-12-09 10:52:17 +01:00
|
|
|
use Tests\FeatureTestCase;
|
|
|
|
|
|
|
|
/**
|
2023-08-01 11:28:27 +02:00
|
|
|
* SystemControllerTest test class
|
2022-12-09 10:52:17 +01:00
|
|
|
*/
|
2023-08-01 11:28:27 +02:00
|
|
|
#[CoversClass(SystemController::class)]
|
2022-12-09 10:52:17 +01:00
|
|
|
class SystemControllerTest extends FeatureTestCase
|
|
|
|
{
|
2024-02-22 14:12:47 +01:00
|
|
|
//use WithoutMiddleware;
|
2022-12-09 10:52:17 +01:00
|
|
|
|
|
|
|
/**
|
2023-03-10 16:03:42 +01:00
|
|
|
* @var \App\Models\User|\Illuminate\Contracts\Auth\Authenticatable
|
2022-12-09 10:52:17 +01:00
|
|
|
*/
|
2024-02-22 14:12:47 +01:00
|
|
|
protected $user, $admin;
|
2022-12-09 10:52:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2022-12-13 12:07:29 +01:00
|
|
|
public function setUp() : void
|
2022-12-09 10:52:17 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->user = User::factory()->create();
|
2024-02-22 14:12:47 +01:00
|
|
|
$this->admin = User::factory()->administrator()->create();
|
2022-12-09 10:52:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2024-02-22 14:12:47 +01:00
|
|
|
public function test_infos_returns_unauthorized()
|
2022-12-09 10:52:17 +01:00
|
|
|
{
|
|
|
|
$response = $this->json('GET', '/infos')
|
2024-02-22 14:12:47 +01:00
|
|
|
->assertUnauthorized();
|
2022-12-09 10:52:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2024-02-22 14:12:47 +01:00
|
|
|
public function test_infos_returns_forbidden()
|
2022-12-09 10:52:17 +01:00
|
|
|
{
|
|
|
|
$response = $this->actingAs($this->user, 'api-guard')
|
|
|
|
->json('GET', '/infos')
|
2024-02-22 14:12:47 +01:00
|
|
|
->assertForbidden();
|
2022-12-09 10:52:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2024-02-22 14:12:47 +01:00
|
|
|
public function test_infos_returns_only_base_collection()
|
2023-03-10 16:03:42 +01:00
|
|
|
{
|
2024-02-22 14:12:47 +01:00
|
|
|
$response = $this->actingAs($this->admin, 'api-guard')
|
2023-03-10 16:03:42 +01:00
|
|
|
->json('GET', '/infos')
|
|
|
|
->assertOk()
|
|
|
|
->assertJsonStructure([
|
2024-02-22 14:12:47 +01:00
|
|
|
'common' => [
|
|
|
|
'Date',
|
|
|
|
'userAgent',
|
|
|
|
'Version',
|
|
|
|
'Environment',
|
|
|
|
'Install path',
|
|
|
|
'Debug',
|
|
|
|
'Cache driver',
|
|
|
|
'Log channel',
|
|
|
|
'Log level',
|
|
|
|
'DB driver',
|
|
|
|
'PHP version',
|
|
|
|
'Operating system',
|
|
|
|
'interface',
|
|
|
|
'Auth guard',
|
|
|
|
'webauthn user verification',
|
|
|
|
'Trusted proxies',
|
|
|
|
'lastRadarScan'
|
2023-03-10 22:59:46 +01:00
|
|
|
],
|
2023-03-10 16:03:42 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function test_infos_returns_proxy_collection_when_signed_in_behind_proxy()
|
2022-12-09 10:52:17 +01:00
|
|
|
{
|
2024-02-22 14:12:47 +01:00
|
|
|
$response = $this->actingAs($this->admin, 'reverse-proxy-guard')
|
2022-12-09 10:52:17 +01:00
|
|
|
->json('GET', '/infos')
|
|
|
|
->assertOk()
|
|
|
|
->assertJsonStructure([
|
2023-03-10 16:03:42 +01:00
|
|
|
'common' => [
|
2024-02-22 14:12:47 +01:00
|
|
|
'Auth proxy logout url',
|
2023-03-10 16:03:42 +01:00
|
|
|
'Auth proxy header for user',
|
|
|
|
'Auth proxy header for email',
|
2023-03-10 22:59:46 +01:00
|
|
|
],
|
2022-12-09 10:52:17 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function test_latestrelease_runs_manual_scan()
|
|
|
|
{
|
|
|
|
$releaseRadarService = $this->mock(ReleaseRadarService::class)->makePartial();
|
|
|
|
$releaseRadarService->shouldReceive('manualScan')
|
|
|
|
->once()
|
|
|
|
->andReturn('new_release');
|
|
|
|
|
|
|
|
$response = $this->json('GET', '/latestRelease')
|
|
|
|
->assertOk()
|
|
|
|
->assertJson([
|
|
|
|
'newRelease' => 'new_release',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|