Skip to content

Commit be84235

Browse files
committed
[TASK] Respect the url scheme of configured api url
In a couple of places, `https` has been hardcoded enforced as request scheme, ignoring the scheme of the configured api url. This may seem to be a "security" enforcement, but these kind of overrides are not very user friendly and hidden magic is always a pain in the ass for debugging issues. This change now re-uses the configured api url scheme when building api requests. One test is adopted to do the same. The donated methods on the `Configuration` class to access api url parts are used for this.
1 parent f9a9701 commit be84235

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

Classes/Client.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ public function getGlossaryEntries(string $glossaryId): ResponseInterface
126126
private function buildBaseUrl(string $path): string
127127
{
128128
$url = sprintf(
129-
'https://%s/%s/%s',
129+
'%s://%s/%s/%s',
130+
$this->configuration->getApiScheme(),
130131
$this->configuration->getApiUrl(),
131132
self::API_VERSION,
132133
$path

Tests/Functional/ClientTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ protected function tearDown(): void
410410

411411
foreach ($this->glossaryIdStorage as $glossaryId) {
412412
$baseUrl = sprintf(
413-
'https://%s/v2/glossaries/%s',
413+
'%s://%s/v2/glossaries/%s',
414+
$configuration->getApiScheme(),
414415
$configuration->getApiUrl(),
415416
$glossaryId
416417
);

Tests/Functional/ConfigurationTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,15 @@ public function checkApiParseUrlAndGiveOnlyDomain(): void
3737
if (defined('DEEPL_API_KEY') && getenv('DEEPL_API_KEY') !== '') {
3838
static::assertSame('api-free.deepl.com', $configuration->getApiUrl());
3939
} else {
40-
static::assertSame('ddev-deepltranslate-deeplmockserver:3000', $configuration->getApiUrl());
40+
$parsedUrl = parse_url(
41+
$this->configurationToUseInTestInstance['EXTENSIONS']['wv_deepltranslate']['apiUrl']
42+
?? 'http://ddev-deepltranslate-deeplmockserver:3000'
43+
);
44+
$checkApiUrl = $parsedUrl['host'] . ($parsedUrl['port'] ? ':' . $parsedUrl['port'] : '');
45+
static::assertSame(
46+
$checkApiUrl,
47+
$configuration->getApiUrl()
48+
);
4149
}
4250
}
4351
}

0 commit comments

Comments
 (0)