123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- namespace Tests\Feature\Http;
- use App\Models\User;
- use App\Services\ReleaseRadarService;
- use Illuminate\Foundation\Testing\WithoutMiddleware;
- use Tests\FeatureTestCase;
- /**
- * @covers \App\Http\Controllers\SystemController
- */
- class SystemControllerTest extends FeatureTestCase
- {
- use WithoutMiddleware;
- /**
- * @var \App\Models\User|\Illuminate\Contracts\Auth\Authenticatable
- */
- protected $user;
- /**
- * @test
- */
- public function setUp() : void
- {
- parent::setUp();
- $this->user = User::factory()->create();
- }
- /**
- * @test
- */
- public function test_infos_returns_only_base_collection()
- {
- $response = $this->json('GET', '/infos')
- ->assertOk()
- ->assertJsonStructure([
- 'common' => [
- 'Date',
- 'userAgent',
- 'Version',
- 'Environment',
- 'Install path',
- 'Debug',
- 'Cache driver',
- 'Log channel',
- 'Log level',
- 'DB driver',
- 'PHP version',
- 'Operating system',
- 'interface',
- ],
- ])
- ->assertJsonMissing([
- 'user_preferences',
- 'admin_settings',
- ]);
- }
- /**
- * @test
- */
- public function test_infos_returns_user_preferences_when_signed_in()
- {
- $response = $this->actingAs($this->user, 'api-guard')
- ->json('GET', '/infos')
- ->assertOk()
- ->assertJsonStructure([
- 'user_preferences' => [
- 'showTokenAsDot',
- 'closeOtpOnCopy',
- 'copyOtpOnDisplay',
- 'useBasicQrcodeReader',
- 'displayMode',
- 'showAccountsIcons',
- 'kickUserAfter',
- 'activeGroup',
- 'rememberActiveGroup',
- 'defaultGroup',
- 'defaultCaptureMode',
- 'useDirectCapture',
- 'useWebauthnAsDefault',
- 'useWebauthnOnly',
- 'getOfficialIcons',
- 'lang',
- ],
- ]);
- }
- /**
- * @test
- */
- public function test_infos_returns_admin_settings_when_signed_in_as_admin()
- {
- /**
- * @var \App\Models\User|\Illuminate\Contracts\Auth\Authenticatable
- */
- $admin = User::factory()->administrator()->create();
- $response = $this->actingAs($admin, 'api-guard')
- ->json('GET', '/infos')
- ->assertOk()
- ->assertJsonStructure([
- 'admin_settings' => [
- 'useEncryption',
- 'lastRadarScan',
- 'checkForUpdate',
- ],
- ]);
- }
- /**
- * @test
- */
- public function test_infos_returns_proxy_collection_when_signed_in_behind_proxy()
- {
- $response = $this->actingAs($this->user, 'reverse-proxy-guard')
- ->json('GET', '/infos')
- ->assertOk()
- ->assertJsonStructure([
- 'common' => [
- 'Auth proxy header for user',
- 'Auth proxy header for email',
- ],
- ]);
- }
- /**
- * @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',
- ]);
- }
- }
|