mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-06 23:33:13 +08:00
Fall back API key names to auto-generated keys
This commit is contained in:
@@ -36,7 +36,7 @@ class GenerateKeyCommandTest extends TestCase
|
||||
public function noExpirationDateIsDefinedIfNotProvided(): void
|
||||
{
|
||||
$this->apiKeyService->expects($this->once())->method('create')->with(
|
||||
$this->callback(fn (ApiKeyMeta $meta) => $meta->name === null && $meta->expirationDate === null),
|
||||
$this->callback(fn (ApiKeyMeta $meta) => $meta->expirationDate === null),
|
||||
)->willReturn(ApiKey::create());
|
||||
|
||||
$this->commandTester->execute([]);
|
||||
|
||||
@@ -52,15 +52,15 @@ class ListKeysCommandTest extends TestCase
|
||||
],
|
||||
false,
|
||||
<<<OUTPUT
|
||||
+--------------------------------------+------+------------+---------------------------+-------+
|
||||
| Key | Name | Is enabled | Expiration date | Roles |
|
||||
+--------------------------------------+------+------------+---------------------------+-------+
|
||||
| {$apiKey1->key} | - | --- | - | Admin |
|
||||
+--------------------------------------+------+------------+---------------------------+-------+
|
||||
| {$apiKey2->key} | - | --- | 2020-01-01T00:00:00+00:00 | Admin |
|
||||
+--------------------------------------+------+------------+---------------------------+-------+
|
||||
| {$apiKey3->key} | - | +++ | - | Admin |
|
||||
+--------------------------------------+------+------------+---------------------------+-------+
|
||||
+--------------------------------------+------------+---------------------------+-------+
|
||||
| Name | Is enabled | Expiration date | Roles |
|
||||
+--------------------------------------+------------+---------------------------+-------+
|
||||
| {$apiKey1->name} | --- | - | Admin |
|
||||
+--------------------------------------+------------+---------------------------+-------+
|
||||
| {$apiKey2->name} | --- | 2020-01-01T00:00:00+00:00 | Admin |
|
||||
+--------------------------------------+------------+---------------------------+-------+
|
||||
| {$apiKey3->name} | +++ | - | Admin |
|
||||
+--------------------------------------+------------+---------------------------+-------+
|
||||
|
||||
OUTPUT,
|
||||
];
|
||||
@@ -68,13 +68,13 @@ class ListKeysCommandTest extends TestCase
|
||||
[$apiKey1 = ApiKey::create()->disable(), $apiKey2 = ApiKey::create()],
|
||||
true,
|
||||
<<<OUTPUT
|
||||
+--------------------------------------+------+-----------------+-------+
|
||||
| Key | Name | Expiration date | Roles |
|
||||
+--------------------------------------+------+-----------------+-------+
|
||||
| {$apiKey1->key} | - | - | Admin |
|
||||
+--------------------------------------+------+-----------------+-------+
|
||||
| {$apiKey2->key} | - | - | Admin |
|
||||
+--------------------------------------+------+-----------------+-------+
|
||||
+--------------------------------------+-----------------+-------+
|
||||
| Name | Expiration date | Roles |
|
||||
+--------------------------------------+-----------------+-------+
|
||||
| {$apiKey1->name} | - | Admin |
|
||||
+--------------------------------------+-----------------+-------+
|
||||
| {$apiKey2->name} | - | Admin |
|
||||
+--------------------------------------+-----------------+-------+
|
||||
|
||||
OUTPUT,
|
||||
];
|
||||
@@ -94,45 +94,45 @@ class ListKeysCommandTest extends TestCase
|
||||
],
|
||||
true,
|
||||
<<<OUTPUT
|
||||
+--------------------------------------+------+-----------------+--------------------------+
|
||||
| Key | Name | Expiration date | Roles |
|
||||
+--------------------------------------+------+-----------------+--------------------------+
|
||||
| {$apiKey1->key} | - | - | Admin |
|
||||
+--------------------------------------+------+-----------------+--------------------------+
|
||||
| {$apiKey2->key} | - | - | Author only |
|
||||
+--------------------------------------+------+-----------------+--------------------------+
|
||||
| {$apiKey3->key} | - | - | Domain only: example.com |
|
||||
+--------------------------------------+------+-----------------+--------------------------+
|
||||
| {$apiKey4->key} | - | - | Admin |
|
||||
+--------------------------------------+------+-----------------+--------------------------+
|
||||
| {$apiKey5->key} | - | - | Author only |
|
||||
| | | | Domain only: example.com |
|
||||
+--------------------------------------+------+-----------------+--------------------------+
|
||||
| {$apiKey6->key} | - | - | Admin |
|
||||
+--------------------------------------+------+-----------------+--------------------------+
|
||||
+--------------------------------------+-----------------+--------------------------+
|
||||
| Name | Expiration date | Roles |
|
||||
+--------------------------------------+-----------------+--------------------------+
|
||||
| {$apiKey1->name} | - | Admin |
|
||||
+--------------------------------------+-----------------+--------------------------+
|
||||
| {$apiKey2->name} | - | Author only |
|
||||
+--------------------------------------+-----------------+--------------------------+
|
||||
| {$apiKey3->name} | - | Domain only: example.com |
|
||||
+--------------------------------------+-----------------+--------------------------+
|
||||
| {$apiKey4->name} | - | Admin |
|
||||
+--------------------------------------+-----------------+--------------------------+
|
||||
| {$apiKey5->name} | - | Author only |
|
||||
| | | Domain only: example.com |
|
||||
+--------------------------------------+-----------------+--------------------------+
|
||||
| {$apiKey6->name} | - | Admin |
|
||||
+--------------------------------------+-----------------+--------------------------+
|
||||
|
||||
OUTPUT,
|
||||
];
|
||||
yield 'with names' => [
|
||||
[
|
||||
$apiKey1 = ApiKey::fromMeta(ApiKeyMeta::fromParams(name: 'Alice')),
|
||||
$apiKey2 = ApiKey::fromMeta(ApiKeyMeta::fromParams(name: 'Alice and Bob')),
|
||||
ApiKey::fromMeta(ApiKeyMeta::fromParams(name: 'Alice')),
|
||||
ApiKey::fromMeta(ApiKeyMeta::fromParams(name: 'Alice and Bob')),
|
||||
$apiKey3 = ApiKey::fromMeta(ApiKeyMeta::fromParams(name: '')),
|
||||
$apiKey4 = ApiKey::create(),
|
||||
],
|
||||
true,
|
||||
<<<OUTPUT
|
||||
+--------------------------------------+---------------+-----------------+-------+
|
||||
| Key | Name | Expiration date | Roles |
|
||||
+--------------------------------------+---------------+-----------------+-------+
|
||||
| {$apiKey1->key} | Alice | - | Admin |
|
||||
+--------------------------------------+---------------+-----------------+-------+
|
||||
| {$apiKey2->key} | Alice and Bob | - | Admin |
|
||||
+--------------------------------------+---------------+-----------------+-------+
|
||||
| {$apiKey3->key} | | - | Admin |
|
||||
+--------------------------------------+---------------+-----------------+-------+
|
||||
| {$apiKey4->key} | - | - | Admin |
|
||||
+--------------------------------------+---------------+-----------------+-------+
|
||||
+--------------------------------------+-----------------+-------+
|
||||
| Name | Expiration date | Roles |
|
||||
+--------------------------------------+-----------------+-------+
|
||||
| Alice | - | Admin |
|
||||
+--------------------------------------+-----------------+-------+
|
||||
| Alice and Bob | - | Admin |
|
||||
+--------------------------------------+-----------------+-------+
|
||||
| {$apiKey3->name} | - | Admin |
|
||||
+--------------------------------------+-----------------+-------+
|
||||
| {$apiKey4->name} | - | Admin |
|
||||
+--------------------------------------+-----------------+-------+
|
||||
|
||||
OUTPUT,
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user