Added more tests ensuring any short URL can be fetched by using an admin API key

This commit is contained in:
Alejandro Celaya 2021-10-01 19:32:34 +02:00
parent abc954aa47
commit 5e627641ea

View file

@ -355,6 +355,8 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
$this->getEntityManager()->persist($wrongDomainApiKey);
$rightDomainApiKey = ApiKey::fromMeta(ApiKeyMeta::withRoles(RoleDefinition::forDomain($rightDomain)));
$this->getEntityManager()->persist($rightDomainApiKey);
$adminApiKey = ApiKey::create();
$this->getEntityManager()->persist($adminApiKey);
$shortUrl = ShortUrl::fromMeta(ShortUrlMeta::fromRawData([
'validSince' => $start,
@ -365,6 +367,12 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
]), $this->relationResolver);
$this->getEntityManager()->persist($shortUrl);
$nonDomainShortUrl = ShortUrl::fromMeta(ShortUrlMeta::fromRawData([
'apiKey' => $apiKey,
'longUrl' => 'non-domain',
]), $this->relationResolver);
$this->getEntityManager()->persist($nonDomainShortUrl);
$this->getEntityManager()->flush();
self::assertSame(
@ -379,6 +387,12 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
'longUrl' => 'foo',
'tags' => ['foo', 'bar'],
])));
self::assertSame($shortUrl, $this->repo->findOneMatching(ShortUrlMeta::fromRawData([
'validSince' => $start,
'apiKey' => $adminApiKey,
'longUrl' => 'foo',
'tags' => ['foo', 'bar'],
])));
self::assertNull($this->repo->findOneMatching(ShortUrlMeta::fromRawData([
'validSince' => $start,
'apiKey' => $otherApiKey,
@ -424,6 +438,27 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
'tags' => ['foo', 'bar'],
])),
);
self::assertSame(
$nonDomainShortUrl,
$this->repo->findOneMatching(ShortUrlMeta::fromRawData([
'apiKey' => $apiKey,
'longUrl' => 'non-domain',
])),
);
self::assertSame(
$nonDomainShortUrl,
$this->repo->findOneMatching(ShortUrlMeta::fromRawData([
'apiKey' => $adminApiKey,
'longUrl' => 'non-domain',
])),
);
self::assertNull(
$this->repo->findOneMatching(ShortUrlMeta::fromRawData([
'apiKey' => $otherApiKey,
'longUrl' => 'non-domain',
])),
);
}
/** @test */