Skip to content

Commit 2c6483a

Browse files
committed
Merge remote-tracking branch '38717/patch-21' into commpr-10131-1706
2 parents 19eb0b8 + d00c9c8 commit 2c6483a

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

app/code/Magento/Store/Model/Store.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2011 Adobe
4+
* All Rights Reserved.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Store\Model;
79

810
use Laminas\Uri\UriFactory;
@@ -809,8 +811,16 @@ public function isCurrentlySecure()
809811
return true;
810812
}
811813

812-
$secureBaseUrl = $this->_config->getValue(self::XML_PATH_SECURE_BASE_URL, ScopeInterface::SCOPE_STORE);
813-
$secureFrontend = $this->_config->getValue(self::XML_PATH_SECURE_IN_FRONTEND, ScopeInterface::SCOPE_STORE);
814+
$secureBaseUrl = $this->_config->getValue(
815+
self::XML_PATH_SECURE_BASE_URL,
816+
ScopeInterface::SCOPE_STORE,
817+
$this->getId()
818+
);
819+
$secureFrontend = $this->_config->getValue(
820+
self::XML_PATH_SECURE_IN_FRONTEND,
821+
ScopeInterface::SCOPE_STORE,
822+
$this->getId()
823+
);
814824

815825
if (!$secureBaseUrl || !$secureFrontend) {
816826
return false;
@@ -819,8 +829,8 @@ public function isCurrentlySecure()
819829
$uri = UriFactory::factory($secureBaseUrl);
820830
$port = $uri->getPort();
821831
$serverPort = $this->_request->getServer('SERVER_PORT');
822-
$isSecure = $uri->getScheme() == 'https' && isset($serverPort) && $port == $serverPort;
823-
return $isSecure;
832+
833+
return $uri->getScheme() === 'https' && $serverPort !== null && $port == $serverPort;
824834
}
825835

826836
/*************************************************************************************

app/code/Magento/Store/Test/Unit/Model/StoreTest.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -624,33 +624,35 @@ public function testGetAllowedCurrencies()
624624
* @dataProvider isCurrentlySecureDataProvider
625625
*
626626
* @param bool $expected
627-
* @param array $value
627+
* @param array|int|null $value
628628
* @param bool $requestSecure
629629
* @param bool $useSecureInFrontend
630630
* @param string|null $secureBaseUrl
631631
*/
632632
public function testIsCurrentlySecure(
633-
$expected,
634-
$value,
635-
$requestSecure = false,
636-
$useSecureInFrontend = true,
637-
$secureBaseUrl = 'https://example.com:443'
633+
bool $expected,
634+
array|int|null $value,
635+
bool $requestSecure = false,
636+
bool $useSecureInFrontend = true,
637+
?string $secureBaseUrl = 'https://example.com:443'
638638
) {
639639
/* @var ReinitableConfigInterface|MockObject $configMock */
640-
$configMock = $this->getMockForAbstractClass(ReinitableConfigInterface::class);
640+
$configMock = $this->getMockBuilder(ReinitableConfigInterface::class)
641+
->disableOriginalConstructor()
642+
->getMock();
641643
$configMock->expects($this->any())
642644
->method('getValue')
643645
->willReturnMap([
644646
[
645647
Store::XML_PATH_SECURE_BASE_URL,
646648
ScopeInterface::SCOPE_STORE,
647-
null,
649+
2,
648650
$secureBaseUrl
649651
],
650652
[
651653
Store::XML_PATH_SECURE_IN_FRONTEND,
652654
ScopeInterface::SCOPE_STORE,
653-
null,
655+
2,
654656
$useSecureInFrontend
655657
]
656658
]);
@@ -670,6 +672,8 @@ public function testIsCurrentlySecure(
670672
['config' => $configMock, 'request' => $this->requestMock]
671673
);
672674

675+
$model->setStoreId(2);
676+
673677
if ($expected) {
674678
$this->assertTrue($model->isCurrentlySecure(), "Was expecting this test to show as secure, but it wasn't");
675679
} else {
@@ -690,6 +694,7 @@ public static function isCurrentlySecureDataProvider()
690694
'unsecure request, using registered port, not using secure in frontend' => [false, 443, false, false],
691695
'unsecure request, no secure base url, not using secure in frontend' => [false, 443, false, false, null],
692696
'unsecure request, not using registered port, not using secure in frontend' => [false, 80, false, false],
697+
'unsecure request, no server setting' => [false, null, false],
693698
];
694699
}
695700

0 commit comments

Comments
 (0)