32 lines
906 B
PHP
32 lines
906 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Security;
|
|
|
|
use App\Security\McpAccessTokenHandler;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
|
|
|
|
class McpAccessTokenHandlerTest extends TestCase
|
|
{
|
|
public function testTheConfiguredTokenAuthenticatesTheN8nUser(): void
|
|
{
|
|
self::assertSame(McpAccessTokenHandler::USER, (new McpAccessTokenHandler('s3cret'))->getUserBadgeFrom('s3cret')->getUserIdentifier());
|
|
}
|
|
|
|
public function testAWrongTokenIsRejected(): void
|
|
{
|
|
$this->expectException(BadCredentialsException::class);
|
|
|
|
(new McpAccessTokenHandler('s3cret'))->getUserBadgeFrom('guess');
|
|
}
|
|
|
|
public function testAnUnconfiguredTokenRejectsEverything(): void
|
|
{
|
|
$this->expectException(BadCredentialsException::class);
|
|
|
|
(new McpAccessTokenHandler(''))->getUserBadgeFrom('');
|
|
}
|
|
}
|