From 3f01fad12fcdd5c7037cd3c71e3dfcaea3623223 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 18 Sep 2022 09:29:38 +0200 Subject: [PATCH] Ensured empty initial PAI keys are discarded --- module/Rest/src/ApiKey/InitialApiKeyDelegator.php | 2 +- module/Rest/test/ApiKey/InitialApiKeyDelegatorTest.php | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/module/Rest/src/ApiKey/InitialApiKeyDelegator.php b/module/Rest/src/ApiKey/InitialApiKeyDelegator.php index 9129d7d3..a5aa9d33 100644 --- a/module/Rest/src/ApiKey/InitialApiKeyDelegator.php +++ b/module/Rest/src/ApiKey/InitialApiKeyDelegator.php @@ -15,7 +15,7 @@ class InitialApiKeyDelegator public function __invoke(ContainerInterface $container, string $serviceName, callable $callback): Application { $initialApiKey = $container->get('config')['initial_api_key'] ?? null; - if ($initialApiKey !== null) { + if (! empty($initialApiKey)) { $this->createInitialApiKey($initialApiKey, $container); } diff --git a/module/Rest/test/ApiKey/InitialApiKeyDelegatorTest.php b/module/Rest/test/ApiKey/InitialApiKeyDelegatorTest.php index 7614fc9d..1db53b80 100644 --- a/module/Rest/test/ApiKey/InitialApiKeyDelegatorTest.php +++ b/module/Rest/test/ApiKey/InitialApiKeyDelegatorTest.php @@ -54,8 +54,9 @@ class InitialApiKeyDelegatorTest extends TestCase public function provideConfigs(): iterable { - yield [[], 0]; - yield [['initial_api_key' => null], 0]; - yield [['initial_api_key' => 'the_initial_key'], 1]; + yield 'no api key' => [[], 0]; + yield 'null api key' => [['initial_api_key' => null], 0]; + yield 'empty api key' => [['initial_api_key' => ''], 0]; + yield 'valid api key' => [['initial_api_key' => 'the_initial_key'], 1]; } }