mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-17 15:59:56 +03:00
Added api tests to cover implicit domain when creating short URLs with proper API key
This commit is contained in:
parent
ea05259bbe
commit
c56d56d38c
1 changed files with 24 additions and 2 deletions
|
@ -244,18 +244,40 @@ class CreateShortUrlActionTest extends ApiTestCase
|
|||
self::assertNull($payload['domain']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideDomains
|
||||
*/
|
||||
public function apiKeyDomainIsEnforced(?string $providedDomain): void
|
||||
{
|
||||
[$statusCode, ['domain' => $returnedDomain]] = $this->createShortUrl(
|
||||
['domain' => $providedDomain],
|
||||
'domain_api_key',
|
||||
);
|
||||
|
||||
self::assertEquals(self::STATUS_OK, $statusCode);
|
||||
self::assertEquals('example.com', $returnedDomain);
|
||||
}
|
||||
|
||||
public function provideDomains(): iterable
|
||||
{
|
||||
yield 'no domain' => [null];
|
||||
yield 'invalid domain' => ['this-will-be-overwritten.com'];
|
||||
yield 'example domain' => ['example.com'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array {
|
||||
* @var int $statusCode
|
||||
* @var array $payload
|
||||
* }
|
||||
*/
|
||||
private function createShortUrl(array $body = []): array
|
||||
private function createShortUrl(array $body = [], string $apiKey = 'valid_api_key'): array
|
||||
{
|
||||
if (! isset($body['longUrl'])) {
|
||||
$body['longUrl'] = 'https://app.shlink.io';
|
||||
}
|
||||
$resp = $this->callApiWithKey(self::METHOD_POST, '/short-urls', [RequestOptions::JSON => $body]);
|
||||
$resp = $this->callApiWithKey(self::METHOD_POST, '/short-urls', [RequestOptions::JSON => $body], $apiKey);
|
||||
$payload = $this->getJsonResponsePayload($resp);
|
||||
|
||||
return [$resp->getStatusCode(), $payload];
|
||||
|
|
Loading…
Add table
Reference in a new issue