SystemControllerTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace Tests\Feature\Http;
  3. use App\Models\User;
  4. use App\Services\ReleaseRadarService;
  5. use Illuminate\Foundation\Testing\WithoutMiddleware;
  6. use Tests\FeatureTestCase;
  7. /**
  8. * @covers \App\Http\Controllers\SystemController
  9. */
  10. class SystemControllerTest extends FeatureTestCase
  11. {
  12. use WithoutMiddleware;
  13. /**
  14. * @var \App\Models\User|\Illuminate\Contracts\Auth\Authenticatable
  15. */
  16. protected $user;
  17. /**
  18. * @test
  19. */
  20. public function setUp() : void
  21. {
  22. parent::setUp();
  23. $this->user = User::factory()->create();
  24. }
  25. /**
  26. * @test
  27. */
  28. public function test_infos_returns_only_base_collection()
  29. {
  30. $response = $this->json('GET', '/infos')
  31. ->assertOk()
  32. ->assertJsonStructure([
  33. 'common' => [
  34. 'Date',
  35. 'userAgent',
  36. 'Version',
  37. 'Environment',
  38. 'Install path',
  39. 'Debug',
  40. 'Cache driver',
  41. 'Log channel',
  42. 'Log level',
  43. 'DB driver',
  44. 'PHP version',
  45. 'Operating system',
  46. 'interface',
  47. ],
  48. ])
  49. ->assertJsonMissing([
  50. 'user_preferences',
  51. 'admin_settings',
  52. ]);
  53. }
  54. /**
  55. * @test
  56. */
  57. public function test_infos_returns_user_preferences_when_signed_in()
  58. {
  59. $response = $this->actingAs($this->user, 'api-guard')
  60. ->json('GET', '/infos')
  61. ->assertOk()
  62. ->assertJsonStructure([
  63. 'user_preferences' => [
  64. 'showTokenAsDot',
  65. 'closeOtpOnCopy',
  66. 'copyOtpOnDisplay',
  67. 'useBasicQrcodeReader',
  68. 'displayMode',
  69. 'showAccountsIcons',
  70. 'kickUserAfter',
  71. 'activeGroup',
  72. 'rememberActiveGroup',
  73. 'defaultGroup',
  74. 'defaultCaptureMode',
  75. 'useDirectCapture',
  76. 'useWebauthnAsDefault',
  77. 'useWebauthnOnly',
  78. 'getOfficialIcons',
  79. 'lang',
  80. ],
  81. ]);
  82. }
  83. /**
  84. * @test
  85. */
  86. public function test_infos_returns_admin_settings_when_signed_in_as_admin()
  87. {
  88. /**
  89. * @var \App\Models\User|\Illuminate\Contracts\Auth\Authenticatable
  90. */
  91. $admin = User::factory()->administrator()->create();
  92. $response = $this->actingAs($admin, 'api-guard')
  93. ->json('GET', '/infos')
  94. ->assertOk()
  95. ->assertJsonStructure([
  96. 'admin_settings' => [
  97. 'useEncryption',
  98. 'lastRadarScan',
  99. 'checkForUpdate',
  100. ],
  101. ]);
  102. }
  103. /**
  104. * @test
  105. */
  106. public function test_infos_returns_proxy_collection_when_signed_in_behind_proxy()
  107. {
  108. $response = $this->actingAs($this->user, 'reverse-proxy-guard')
  109. ->json('GET', '/infos')
  110. ->assertOk()
  111. ->assertJsonStructure([
  112. 'common' => [
  113. 'Auth proxy header for user',
  114. 'Auth proxy header for email',
  115. ],
  116. ]);
  117. }
  118. /**
  119. * @test
  120. */
  121. public function test_latestrelease_runs_manual_scan()
  122. {
  123. $releaseRadarService = $this->mock(ReleaseRadarService::class)->makePartial();
  124. $releaseRadarService->shouldReceive('manualScan')
  125. ->once()
  126. ->andReturn('new_release');
  127. $response = $this->json('GET', '/latestRelease')
  128. ->assertOk()
  129. ->assertJson([
  130. 'newRelease' => 'new_release',
  131. ]);
  132. }
  133. }