Setzt Phase 1 aus Visualization.md um: Vanilla-PHP-REST-API mit SQLite-Persistenz, statischen API-Keys pro Agent, Codeberg-Sync fuer Backlog/Done, PHPUnit-Tests und vollstaendiger API.md-Dokumentation - Vorgaben aus Detailantworten.md (F1-F16) umgesetzt. Entwicklung/Build/Test laufen komplett in Docker-Compose-Containern (PHP 8.2 + SQLite + Composer + PHPUnit/pcov), analog zum NC-Gantt-Projekt ist auf dem Host kein PHP/Composer noetig. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Monitor\Api\Tests\Auth;
|
|
|
|
use Monitor\Api\Auth\AdminAuthenticator;
|
|
use Monitor\Api\Http\Request;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class AdminAuthenticatorTest extends TestCase
|
|
{
|
|
public function testAuthenticateAcceptsCorrectKey(): void
|
|
{
|
|
$auth = new AdminAuthenticator('secret');
|
|
|
|
self::assertTrue($auth->authenticate(Request::create('POST', '/x', headers: ['X-Admin-Key' => 'secret'])));
|
|
}
|
|
|
|
public function testAuthenticateRejectsWrongKey(): void
|
|
{
|
|
$auth = new AdminAuthenticator('secret');
|
|
|
|
self::assertFalse($auth->authenticate(Request::create('POST', '/x', headers: ['X-Admin-Key' => 'wrong'])));
|
|
}
|
|
|
|
public function testAuthenticateRejectsWhenNoAdminKeyConfigured(): void
|
|
{
|
|
$auth = new AdminAuthenticator(null);
|
|
|
|
self::assertFalse($auth->authenticate(Request::create('POST', '/x', headers: ['X-Admin-Key' => 'anything'])));
|
|
}
|
|
|
|
public function testAuthenticateRejectsMissingHeader(): void
|
|
{
|
|
$auth = new AdminAuthenticator('secret');
|
|
|
|
self::assertFalse($auth->authenticate(Request::create('POST', '/x')));
|
|
}
|
|
}
|