1
0

SettingsPageTest.php 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Tests\Integration\Settings;
  4. use App\Auth\UserContext;
  5. use App\Tests\Integration\Support\AppTestCase;
  6. final class SettingsPageTest extends AppTestCase
  7. {
  8. protected function setUp(): void
  9. {
  10. $this->bootApp();
  11. }
  12. public function testAdminSeesConfigAndJobs(): void
  13. {
  14. $_SESSION['_user'] = (new UserContext(1, 'Admin', 'admin', null, UserContext::SOURCE_LOCAL))->toArray();
  15. $_SESSION['_last_active'] = time();
  16. $_SESSION['_authenticated_at'] = time();
  17. // First call: getConfig
  18. $this->enqueueApiResponse(200, [
  19. 'sections' => [
  20. 'app' => ['APP_ENV' => 'development', 'LOG_LEVEL' => 'Info'],
  21. 'database' => ['DB_DRIVER' => 'sqlite'],
  22. 'auth' => ['INTERNAL_JOB_TOKEN' => '***', 'UI_SERVICE_TOKEN' => 'irdb_svc...'],
  23. 'reputation' => ['SCORE_REPORT_HARD_CUTOFF_DAYS' => 365],
  24. 'jobs' => ['JOB_AUDIT_RETENTION_DAYS' => 180],
  25. 'geoip' => ['GEOIP_PROVIDER' => 'dbip', 'GEOIP_COUNTRY_DB' => '/data/geoip/country.mmdb', 'GEOIP_ASN_DB' => '/data/geoip/asn.mmdb', 'MAXMIND_LICENSE_KEY' => '', 'IPINFO_TOKEN' => ''],
  26. ],
  27. ]);
  28. // Second call: getJobsStatus
  29. $this->enqueueApiResponse(200, [
  30. 'now' => '2026-04-29T10:00:00Z',
  31. 'jobs' => [
  32. 'recompute-scores' => [
  33. 'name' => 'recompute-scores',
  34. 'default_interval_seconds' => 300,
  35. 'max_runtime_seconds' => 240,
  36. 'overdue' => false,
  37. 'lock' => null,
  38. 'last_run' => [
  39. 'id' => 1,
  40. 'status' => 'success',
  41. 'items_processed' => 0,
  42. 'triggered_by' => 'schedule',
  43. 'started_at' => '2026-04-29T09:55:00Z',
  44. 'finished_at' => '2026-04-29T09:55:01Z',
  45. 'error_message' => null,
  46. ],
  47. ],
  48. ],
  49. ]);
  50. // Third call: getAppSettings (audit toggles)
  51. $this->enqueueApiResponse(200, [
  52. 'audit_report_received_enabled' => true,
  53. 'audit_blocklist_request_enabled' => true,
  54. ]);
  55. $resp = $this->request('GET', '/app/settings');
  56. self::assertSame(200, $resp->getStatusCode());
  57. $body = (string) $resp->getBody();
  58. self::assertStringContainsString('Configuration', $body);
  59. self::assertStringContainsString('Jobs', $body);
  60. self::assertStringContainsString('GeoIP', $body);
  61. self::assertStringContainsString('recompute-scores', $body);
  62. self::assertStringContainsString('Run now', $body);
  63. self::assertStringContainsString('dbip', $body);
  64. }
  65. public function testViewerRedirectsToNoAccess(): void
  66. {
  67. $_SESSION['_user'] = (new UserContext(2, 'Viewer', 'viewer', null, UserContext::SOURCE_LOCAL))->toArray();
  68. $_SESSION['_last_active'] = time();
  69. $_SESSION['_authenticated_at'] = time();
  70. $resp = $this->request('GET', '/app/settings');
  71. self::assertSame(303, $resp->getStatusCode());
  72. self::assertSame('/no-access', $resp->getHeaderLine('Location'));
  73. }
  74. public function testAnonymousRedirectsToLogin(): void
  75. {
  76. $_SESSION = [];
  77. $resp = $this->request('GET', '/app/settings');
  78. self::assertSame(302, $resp->getStatusCode());
  79. self::assertSame('/login', $resp->getHeaderLine('Location'));
  80. }
  81. }