| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- declare(strict_types=1);
- namespace App\Tests\Integration\Auth;
- use App\Domain\Auth\TokenIssuer;
- use App\Domain\Auth\TokenKind;
- use App\Infrastructure\Auth\ServiceTokenBootstrap;
- use App\Tests\Integration\Support\AppTestCase;
- final class ServiceTokenBootstrapTest extends AppTestCase
- {
- public function testBootstrapInsertsServiceTokenRow(): void
- {
- /** @var ServiceTokenBootstrap $boot */
- $boot = $this->container->get(ServiceTokenBootstrap::class);
- /** @var TokenIssuer $issuer */
- $issuer = $this->container->get(TokenIssuer::class);
- $raw = $issuer->issue(TokenKind::Service);
- $boot->bootstrap($raw);
- $count = (int) $this->db->fetchOne(
- "SELECT COUNT(*) FROM api_tokens WHERE kind = 'service'"
- );
- self::assertSame(1, $count);
- }
- public function testBootstrapIsIdempotent(): void
- {
- /** @var ServiceTokenBootstrap $boot */
- $boot = $this->container->get(ServiceTokenBootstrap::class);
- /** @var TokenIssuer $issuer */
- $issuer = $this->container->get(TokenIssuer::class);
- $raw = $issuer->issue(TokenKind::Service);
- $boot->bootstrap($raw);
- $boot->bootstrap($raw);
- $boot->bootstrap($raw);
- self::assertSame(
- 1,
- (int) $this->db->fetchOne("SELECT COUNT(*) FROM api_tokens WHERE kind = 'service'")
- );
- }
- public function testBootstrapWithEmptyTokenIsNoOp(): void
- {
- /** @var ServiceTokenBootstrap $boot */
- $boot = $this->container->get(ServiceTokenBootstrap::class);
- $boot->bootstrap('');
- self::assertSame(
- 0,
- (int) $this->db->fetchOne("SELECT COUNT(*) FROM api_tokens WHERE kind = 'service'")
- );
- }
- public function testBootstrapWithMalformedTokenIsNoOp(): void
- {
- /** @var ServiceTokenBootstrap $boot */
- $boot = $this->container->get(ServiceTokenBootstrap::class);
- $boot->bootstrap('not-a-token');
- self::assertSame(
- 0,
- (int) $this->db->fetchOne("SELECT COUNT(*) FROM api_tokens WHERE kind = 'service'")
- );
- }
- public function testBootstrapWithDifferentTokenInsertsNewRow(): void
- {
- /** @var ServiceTokenBootstrap $boot */
- $boot = $this->container->get(ServiceTokenBootstrap::class);
- /** @var TokenIssuer $issuer */
- $issuer = $this->container->get(TokenIssuer::class);
- $first = $issuer->issue(TokenKind::Service);
- $second = $issuer->issue(TokenKind::Service);
- $boot->bootstrap($first);
- $boot->bootstrap($second);
- // Both rows should now exist; operator must revoke the old one manually.
- self::assertSame(
- 2,
- (int) $this->db->fetchOne("SELECT COUNT(*) FROM api_tokens WHERE kind = 'service'")
- );
- }
- }
|