From 613bdd82b0cfb89d1a736815c95c3d03402525f1 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 14 Mar 2022 19:26:02 +0100 Subject: [PATCH] Ensured base path is not prefixed more than it should --- composer.json | 2 +- .../Command/ShortUrl/ListShortUrlsCommand.php | 2 +- module/Core/src/Config/BasePathPrefixer.php | 1 - .../Core/test/Config/BasePathPrefixerTest.php | 36 ++----------------- 4 files changed, 4 insertions(+), 37 deletions(-) diff --git a/composer.json b/composer.json index cdf26d6b..44b7ab91 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ "shlinkio/shlink-config": "^1.6", "shlinkio/shlink-event-dispatcher": "^2.3", "shlinkio/shlink-importer": "^2.5", - "shlinkio/shlink-installer": "dev-develop#ea5e967 as 7.1", + "shlinkio/shlink-installer": "dev-develop#d02f256 as 7.1", "shlinkio/shlink-ip-geolocation": "^2.2", "symfony/console": "^6.0", "symfony/filesystem": "^6.0", diff --git a/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php b/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php index 751006bf..ebc9e783 100644 --- a/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php +++ b/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php @@ -209,7 +209,7 @@ class ListShortUrlsCommand extends AbstractWithDateRangeCommand } if ($input->getOption('show-api-key')) { $columnsMap['API Key'] = static fn (array $_, ShortUrl $shortUrl): string => - (string) $shortUrl->authorApiKey(); + $shortUrl->authorApiKey()?->__toString() ?? ''; } if ($input->getOption('show-api-key-name')) { $columnsMap['API Key Name'] = static fn (array $_, ShortUrl $shortUrl): ?string => diff --git a/module/Core/src/Config/BasePathPrefixer.php b/module/Core/src/Config/BasePathPrefixer.php index 1ad4e23b..4a306287 100644 --- a/module/Core/src/Config/BasePathPrefixer.php +++ b/module/Core/src/Config/BasePathPrefixer.php @@ -13,7 +13,6 @@ class BasePathPrefixer public function __invoke(array $config): array { $basePath = $config['router']['base_path'] ?? ''; - $config['url_shortener']['domain']['hostname'] .= $basePath; foreach (self::ELEMENTS_WITH_PATH as $configKey) { $config[$configKey] = $this->prefixPathsWithBasePath($configKey, $config, $basePath); diff --git a/module/Core/test/Config/BasePathPrefixerTest.php b/module/Core/test/Config/BasePathPrefixerTest.php index f01b9195..36b038c8 100644 --- a/module/Core/test/Config/BasePathPrefixerTest.php +++ b/module/Core/test/Config/BasePathPrefixerTest.php @@ -24,42 +24,16 @@ class BasePathPrefixerTest extends TestCase array $originalConfig, array $expectedRoutes, array $expectedMiddlewares, - string $expectedHostname, ): void { - [ - 'routes' => $routes, - 'middleware_pipeline' => $middlewares, - 'url_shortener' => $urlShortener, - ] = ($this->prefixer)($originalConfig); + ['routes' => $routes, 'middleware_pipeline' => $middlewares] = ($this->prefixer)($originalConfig); self::assertEquals($expectedRoutes, $routes); self::assertEquals($expectedMiddlewares, $middlewares); - self::assertEquals([ - 'domain' => [ - 'hostname' => $expectedHostname, - ], - ], $urlShortener); } public function provideConfig(): iterable { - $urlShortener = [ - 'domain' => [ - 'hostname' => null, - ], - ]; - - yield 'without anything' => [['url_shortener' => $urlShortener], [], [], '']; - yield 'with empty options' => [ - [ - 'routes' => [], - 'middleware_pipeline' => [], - 'url_shortener' => $urlShortener, - ], - [], - [], - '', - ]; + yield 'with empty options' => [['routes' => []], [], []]; yield 'with non-empty options' => [ [ 'routes' => [ @@ -70,11 +44,6 @@ class BasePathPrefixerTest extends TestCase ['with' => 'no_path'], ['path' => '/rest', 'middleware' => []], ], - 'url_shortener' => [ - 'domain' => [ - 'hostname' => 'doma.in', - ], - ], 'router' => ['base_path' => '/foo/bar'], ], [ @@ -85,7 +54,6 @@ class BasePathPrefixerTest extends TestCase ['with' => 'no_path'], ['path' => '/foo/bar/rest', 'middleware' => []], ], - 'doma.in/foo/bar', ]; } }