From 5e627641eac275a85294d754de006f9710645d61 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 1 Oct 2021 19:32:34 +0200 Subject: [PATCH] Added more tests ensuring any short URL can be fetched by using an admin API key --- .../Repository/ShortUrlRepositoryTest.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/module/Core/test-db/Repository/ShortUrlRepositoryTest.php b/module/Core/test-db/Repository/ShortUrlRepositoryTest.php index a614844f..d4ff42b8 100644 --- a/module/Core/test-db/Repository/ShortUrlRepositoryTest.php +++ b/module/Core/test-db/Repository/ShortUrlRepositoryTest.php @@ -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 */