mirror of
https://github.com/shlinkio/shlink.git
synced 2026-02-28 04:03:12 +08:00
Add more tests for apiKeyName short URLs filtering
This commit is contained in:
@@ -156,6 +156,15 @@
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "apiKeyName",
|
||||
"in": "query",
|
||||
"description": "Only get short URLs created with this API key.<br />This value is **ignored** if the request is performed with a non-admin API key that does not match this name.",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"security": [
|
||||
|
||||
@@ -209,6 +209,7 @@ class ListShortUrlsCommandTest extends TestCase
|
||||
string|null $endDate = null,
|
||||
array $excludeTags = [],
|
||||
string $excludeTagsMode = TagsMode::ANY->value,
|
||||
string|null $apiKeyName = null,
|
||||
): void {
|
||||
$this->shortUrlService->expects($this->once())->method('listShortUrls')->with(ShortUrlsParams::fromRawData([
|
||||
'page' => $page,
|
||||
@@ -219,6 +220,7 @@ class ListShortUrlsCommandTest extends TestCase
|
||||
'endDate' => $endDate !== null ? Chronos::parse($endDate)->toAtomString() : null,
|
||||
'excludeTags' => $excludeTags,
|
||||
'excludeTagsMode' => $excludeTagsMode,
|
||||
'apiKeyName' => $apiKeyName,
|
||||
]))->willReturn(new Paginator(new ArrayAdapter([])));
|
||||
|
||||
$this->commandTester->setInputs(['n']);
|
||||
@@ -275,6 +277,18 @@ class ListShortUrlsCommandTest extends TestCase
|
||||
['foo', 'bar'],
|
||||
TagsMode::ALL->value,
|
||||
];
|
||||
yield [
|
||||
['--api-key-name' => 'foo'],
|
||||
1,
|
||||
null,
|
||||
[],
|
||||
TagsMode::ANY->value,
|
||||
null,
|
||||
null,
|
||||
[],
|
||||
TagsMode::ANY->value,
|
||||
'foo',
|
||||
];
|
||||
}
|
||||
|
||||
#[Test, DataProvider('provideOrderBy')]
|
||||
|
||||
@@ -297,6 +297,24 @@ class ListShortUrlsTest extends ApiTestCase
|
||||
self::SHORT_URL_DOCS,
|
||||
]];
|
||||
|
||||
// Filter by API key name
|
||||
yield [['apiKeyName' => 'author_api_key'], [
|
||||
self::SHORT_URL_CUSTOM_SLUG,
|
||||
self::SHORT_URL_META,
|
||||
self::SHORT_URL_SHLINK_WITH_TITLE,
|
||||
]];
|
||||
yield [['apiKeyName' => 'invalid'], []];
|
||||
yield [['apiKeyName' => 'valid_api_key'], [
|
||||
// If the author_api_key is used, the `apiKeyName` param is ignored
|
||||
self::SHORT_URL_CUSTOM_SLUG,
|
||||
self::SHORT_URL_META,
|
||||
self::SHORT_URL_SHLINK_WITH_TITLE,
|
||||
], 'author_api_key'];
|
||||
yield [['apiKeyName' => 'valid_api_key'], [
|
||||
// If the domain_api_key is used, the `apiKeyName` param is ignored
|
||||
self::SHORT_URL_CUSTOM_DOMAIN,
|
||||
], 'domain_api_key'];
|
||||
|
||||
// Different API keys
|
||||
yield [[], [
|
||||
self::SHORT_URL_CUSTOM_SLUG,
|
||||
|
||||
Reference in New Issue
Block a user