mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-14 04:00:57 +03:00
Added more tests ensuring any short URL can be fetched by using an admin API key
This commit is contained in:
parent
abc954aa47
commit
5e627641ea
1 changed files with 35 additions and 0 deletions
|
@ -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 */
|
||||
|
|
Loading…
Add table
Reference in a new issue