Files
portal/app/tests/Feature/Admin/EnsureSaasAdminGateTest.php
T

39 lines
1.3 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
use Illuminate\Foundation\Testing\DatabaseTransactions;
uses(DatabaseTransactions::class);
/**
* M-1 (приёмка 21.06): fail-closed гейт админ-зоны по REMOTE_USER + allowlist.
* Закрывает обходы /index.php/api/admin и /API/admin (front-controller PATH_INFO),
* где nginx basic-auth не применяется и REMOTE_USER пуст.
*/
beforeEach(function () {
config(['admin.basic_auth_gate' => true]);
config(['admin.basic_auth_allowlist' => ['admin']]);
});
test('гейт включён + нет REMOTE_USER → 403', function () {
$this->getJson('/api/admin/tenants')->assertStatus(403);
});
test('гейт включён + REMOTE_USER в allowlist → пройден (не 403)', function () {
$this->withServerVariables(['REMOTE_USER' => 'admin'])
->getJson('/api/admin/tenants')
->assertOk();
});
test('гейт включён + REMOTE_USER не в allowlist → 403', function () {
$this->withServerVariables(['REMOTE_USER' => 'eve'])
->getJson('/api/admin/tenants')
->assertStatus(403);
});
test('гейт выключен (дефолт testing) + нет REMOTE_USER → не 403 (регрессия)', function () {
config(['admin.basic_auth_gate' => false]);
$this->getJson('/api/admin/tenants')->assertOk();
});