Skip to content

Commit 003c652

Browse files
authored
MAGETWO-65606: [GitHub][PR] Bugfix: Fix for not respected alternative headers in maintenance mode #7864
2 parents a86e9b0 + aa5ba34 commit 003c652

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

lib/internal/Magento/Framework/App/Bootstrap.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
namespace Magento\Framework\App;
88

9-
use Magento\Framework\App\Filesystem\DirectoryList;
109
use Magento\Framework\AppInterface;
10+
use Magento\Framework\App\Filesystem\DirectoryList;
1111
use Magento\Framework\Autoload\AutoloaderRegistry;
1212
use Magento\Framework\Autoload\Populator;
1313
use Magento\Framework\Component\ComponentRegistrar;
14+
use Magento\Framework\Config\File\ConfigFilePool;
1415
use Magento\Framework\Filesystem\DriverPool;
1516
use Magento\Framework\Profiler;
16-
use Magento\Framework\Config\File\ConfigFilePool;
1717

1818
/**
1919
* A bootstrap of Magento application
@@ -284,7 +284,14 @@ protected function assertMaintenance()
284284
$this->initObjectManager();
285285
/** @var \Magento\Framework\App\MaintenanceMode $maintenance */
286286
$this->maintenance = $this->objectManager->get(\Magento\Framework\App\MaintenanceMode::class);
287-
$isOn = $this->maintenance->isOn(isset($this->server['REMOTE_ADDR']) ? $this->server['REMOTE_ADDR'] : '');
287+
288+
/** @var \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress $phpRemoteAddressEnvironment */
289+
$phpRemoteAddressEnvironment = $this->objectManager->get(
290+
\Magento\Framework\HTTP\PhpEnvironment\RemoteAddress::class
291+
);
292+
$remoteAddress = $phpRemoteAddressEnvironment->getRemoteAddress();
293+
$isOn = $this->maintenance->isOn($remoteAddress ? $remoteAddress : '');
294+
288295
if ($isOn && !$isExpected) {
289296
$this->errorCode = self::ERR_MAINTENANCE;
290297
throw new \Exception('Unable to proceed: the maintenance mode is enabled. ');
@@ -332,7 +339,7 @@ private function getIsExpected($key, $default)
332339
{
333340
if (array_key_exists($key, $this->server)) {
334341
if (isset($this->server[$key])) {
335-
return (bool)(int)$this->server[$key];
342+
return (bool) (int) $this->server[$key];
336343
}
337344
return null;
338345
}

lib/internal/Magento/Framework/App/Test/Unit/BootstrapTest.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88

99
namespace Magento\Framework\App\Test\Unit;
1010

11+
use Magento\Framework\App\Filesystem\DirectoryList;
1112
use \Magento\Framework\App\Bootstrap;
12-
use \Magento\Framework\App\State;
1313
use \Magento\Framework\App\MaintenanceMode;
14-
15-
use Magento\Framework\App\Filesystem\DirectoryList;
14+
use \Magento\Framework\App\State;
1615

1716
/**
1817
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -64,6 +63,11 @@ class BootstrapTest extends \PHPUnit_Framework_TestCase
6463
*/
6564
protected $bootstrapMock;
6665

66+
/**
67+
* @var \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress | \PHPUnit_Framework_MockObject_MockObject
68+
*/
69+
protected $remoteAddress;
70+
6771
protected function setUp()
6872
{
6973
$this->objectManagerFactory = $this->getMock(
@@ -82,6 +86,7 @@ protected function setUp()
8286
false
8387
);
8488
$this->maintenanceMode = $this->getMock(\Magento\Framework\App\MaintenanceMode::class, ['isOn'], [], '', false);
89+
$this->remoteAddress = $this->getMock('Magento\Framework\HTTP\PhpEnvironment\RemoteAddress', [], [], '', false);
8590
$filesystem = $this->getMock(\Magento\Framework\Filesystem::class, [], [], '', false);
8691

8792
$this->logger = $this->getMock(\Psr\Log\LoggerInterface::class);
@@ -91,6 +96,7 @@ protected function setUp()
9196
$mapObjectManager = [
9297
[\Magento\Framework\App\Filesystem\DirectoryList::class, $this->dirs],
9398
[\Magento\Framework\App\MaintenanceMode::class, $this->maintenanceMode],
99+
[\Magento\Framework\HTTP\PhpEnvironment\RemoteAddress::class, $this->remoteAddress],
94100
[\Magento\Framework\Filesystem::class, $filesystem],
95101
[\Magento\Framework\App\DeploymentConfig::class, $this->deploymentConfig],
96102
['Psr\Log\LoggerInterface', $this->logger],
@@ -205,7 +211,7 @@ public function testIsDeveloperModeDataProvider()
205211
[State::MODE_DEVELOPER, State::MODE_PRODUCTION, true],
206212
[State::MODE_PRODUCTION, State::MODE_DEVELOPER, false],
207213
[null, State::MODE_DEVELOPER, true],
208-
[null, State::MODE_PRODUCTION, false]
214+
[null, State::MODE_PRODUCTION, false],
209215
];
210216
}
211217

@@ -260,6 +266,7 @@ public function testAssertMaintenance($isOn, $isExpected)
260266
{
261267
$bootstrap = self::createBootstrap([Bootstrap::PARAM_REQUIRE_MAINTENANCE => $isExpected]);
262268
$this->maintenanceMode->expects($this->once())->method('isOn')->willReturn($isOn);
269+
$this->remoteAddress->expects($this->once())->method('getRemoteAddress')->willReturn(false);
263270
$this->application->expects($this->never())->method('launch');
264271
$this->application->expects($this->once())->method('catchException')->willReturn(true);
265272
$bootstrap->run($this->application);
@@ -273,7 +280,7 @@ public function assertMaintenanceDataProvider()
273280
{
274281
return [
275282
[true, false],
276-
[false, true]
283+
[false, true],
277284
];
278285
}
279286

0 commit comments

Comments
 (0)