Skip to content

Update Store.php #38717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions app/code/Magento/Store/Model/Store.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2011 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

namespace Magento\Store\Model;

use Laminas\Uri\UriFactory;
Expand Down Expand Up @@ -809,8 +811,16 @@ public function isCurrentlySecure()
return true;
}

$secureBaseUrl = $this->_config->getValue(self::XML_PATH_SECURE_BASE_URL, ScopeInterface::SCOPE_STORE);
$secureFrontend = $this->_config->getValue(self::XML_PATH_SECURE_IN_FRONTEND, ScopeInterface::SCOPE_STORE);
$secureBaseUrl = $this->_config->getValue(
self::XML_PATH_SECURE_BASE_URL,
ScopeInterface::SCOPE_STORE,
$this->getId()
);
$secureFrontend = $this->_config->getValue(
self::XML_PATH_SECURE_IN_FRONTEND,
ScopeInterface::SCOPE_STORE,
$this->getId()
);

if (!$secureBaseUrl || !$secureFrontend) {
return false;
Expand All @@ -819,8 +829,8 @@ public function isCurrentlySecure()
$uri = UriFactory::factory($secureBaseUrl);
$port = $uri->getPort();
$serverPort = $this->_request->getServer('SERVER_PORT');
$isSecure = $uri->getScheme() == 'https' && isset($serverPort) && $port == $serverPort;
return $isSecure;

return $uri->getScheme() === 'https' && $serverPort !== null && $port == $serverPort;
}

/*************************************************************************************
Expand Down
27 changes: 16 additions & 11 deletions app/code/Magento/Store/Test/Unit/Model/StoreTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2014 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand Down Expand Up @@ -624,33 +624,35 @@ public function testGetAllowedCurrencies()
* @dataProvider isCurrentlySecureDataProvider
*
* @param bool $expected
* @param array $value
* @param array|int|null $value
* @param bool $requestSecure
* @param bool $useSecureInFrontend
* @param string|null $secureBaseUrl
*/
public function testIsCurrentlySecure(
$expected,
$value,
$requestSecure = false,
$useSecureInFrontend = true,
$secureBaseUrl = 'https://example.com:443'
bool $expected,
array|int|null $value,
bool $requestSecure = false,
bool $useSecureInFrontend = true,
?string $secureBaseUrl = 'https://example.com:443'
) {
/* @var ReinitableConfigInterface|MockObject $configMock */
$configMock = $this->getMockForAbstractClass(ReinitableConfigInterface::class);
$configMock = $this->getMockBuilder(ReinitableConfigInterface::class)
->disableOriginalConstructor()
->getMock();
$configMock->expects($this->any())
->method('getValue')
->willReturnMap([
[
Store::XML_PATH_SECURE_BASE_URL,
ScopeInterface::SCOPE_STORE,
null,
2,
$secureBaseUrl
],
[
Store::XML_PATH_SECURE_IN_FRONTEND,
ScopeInterface::SCOPE_STORE,
null,
2,
$useSecureInFrontend
]
]);
Expand All @@ -670,6 +672,8 @@ public function testIsCurrentlySecure(
['config' => $configMock, 'request' => $this->requestMock]
);

$model->setStoreId(2);

if ($expected) {
$this->assertTrue($model->isCurrentlySecure(), "Was expecting this test to show as secure, but it wasn't");
} else {
Expand All @@ -690,6 +694,7 @@ public static function isCurrentlySecureDataProvider()
'unsecure request, using registered port, not using secure in frontend' => [false, 443, false, false],
'unsecure request, no secure base url, not using secure in frontend' => [false, 443, false, false, null],
'unsecure request, not using registered port, not using secure in frontend' => [false, 80, false, false],
'unsecure request, no server setting' => [false, null, false],
];
}

Expand Down