Skip to content

Commit 504fd42

Browse files
oshmyheliukshiftedreality
authored andcommitted
MAGECLOUD-4009: Error in UrlManager::getBaseUrl() when secured url isn't configured (#583)
1 parent e4f4ec9 commit 504fd42

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

src/Test/Unit/Util/UrlManagerTest.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,66 @@ public function testGetBaseUrlWithEmptyStoreUrls()
486486
);
487487
}
488488

489+
/**
490+
* @param array $routes
491+
* @param string $expectedUrl
492+
* @dataProvider getBaseUrlDataProvider
493+
*/
494+
public function testGetBaseUrlWithErrorFromDefaultUrlCommand(array $routes, string $expectedUrl)
495+
{
496+
$processMock = $this->getMockForAbstractClass(ProcessInterface::class);
497+
$processMock->expects($this->never())
498+
->method('getOutput');
499+
$this->magentoShellMock->expects($this->once())
500+
->method('execute')
501+
->with('config:show:default-url')
502+
->willThrowException(new ShellException('some error'));
503+
$this->environmentMock->expects($this->once())
504+
->method('getRoutes')
505+
->willReturn($routes);
506+
507+
$this->assertEquals($expectedUrl, $this->manager->getBaseUrl());
508+
}
509+
510+
/**
511+
* @return array
512+
*/
513+
public function getBaseUrlDataProvider(): array
514+
{
515+
return [
516+
[
517+
[
518+
'http://unsecure.com/' => ['original_url' => 'https://{all}', 'type' => 'upstream']
519+
],
520+
'https://unsecure.com/'
521+
],
522+
[
523+
[
524+
'http://unsecure.com/' => ['original_url' => 'https://{all}', 'type' => 'upstream'],
525+
'http://unsecure-default.com/' => ['original_url' => 'https://{default}', 'type' => 'upstream'],
526+
],
527+
'https://unsecure-default.com/'
528+
],
529+
[
530+
[
531+
'https://secure.com/' => ['original_url' => 'https://{all}', 'type' => 'upstream'],
532+
'http://unsecure.com/' => ['original_url' => 'https://{all}', 'type' => 'upstream'],
533+
'http://unsecure-default.com/' => ['original_url' => 'https://{default}', 'type' => 'upstream'],
534+
],
535+
'https://secure.com/'
536+
],
537+
[
538+
[
539+
'https://secure.com/' => ['original_url' => 'https://{all}', 'type' => 'upstream'],
540+
'https://secure-default.com/' => ['original_url' => 'https://{default}', 'type' => 'upstream'],
541+
'http://unsecure.com/' => ['original_url' => 'https://{all}', 'type' => 'upstream'],
542+
'http://unsecure-default.com/' => ['original_url' => 'https://{default}', 'type' => 'upstream'],
543+
],
544+
'https://secure-default.com/'
545+
],
546+
];
547+
}
548+
489549
public function testGetBaseUrls()
490550
{
491551
$processMock = $this->getMockForAbstractClass(ProcessInterface::class);

src/Util/UrlManager.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ public function getBaseUrl(): string
164164
'Instead, using the URL from the MAGENTO_CLOUD_ROUTES variable.'
165165
);
166166
$this->logger->debug($e->getMessage());
167-
$this->baseUrl = $this->getSecureUrls()[''];
167+
168+
$urls = $this->getSecureUrls() ?? $this->getUnSecureUrls();
169+
$this->baseUrl = $urls[''] ?? reset($urls);
168170
}
169171
}
170172

0 commit comments

Comments
 (0)