Skip to content

Commit 57b103c

Browse files
committed
MAGETWO-67736: Secure environment variables does not apply properly
1 parent c3834c5 commit 57b103c

File tree

4 files changed

+22
-30
lines changed

4 files changed

+22
-30
lines changed

app/code/Magento/Config/App/Config/Source/EnvironmentConfigSource.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ class EnvironmentConfigSource implements ConfigSourceInterface
3030
*/
3131
private $placeholder;
3232

33-
/**
34-
* Variable for caching loaded environment config.
35-
*
36-
* @var DataObject
37-
*/
38-
private $data;
39-
4033
/**
4134
* @param ArrayManager $arrayManager
4235
* @param PlaceholderFactory $placeholderFactory
@@ -54,11 +47,8 @@ public function __construct(
5447
*/
5548
public function get($path = '')
5649
{
57-
if ($this->data === null) {
58-
$this->data = new DataObject($this->loadConfig());
59-
}
60-
61-
return $this->data->getData($path) ?: [];
50+
$data = new DataObject($this->loadConfig());
51+
return $data->getData($path) ?: [];
6252
}
6353

6454
/**

app/etc/di.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,5 +1323,9 @@
13231323
<argument name="logCallStack" xsi:type="init_parameter">Magento\Framework\Config\ConfigOptionsListConstants::CONFIG_PATH_DB_LOGGER_INCLUDE_STACKTRACE</argument>
13241324
</arguments>
13251325
</type>
1326-
1326+
<type name="Magento\Framework\App\Config\MetadataConfigTypeProcessor">
1327+
<arguments>
1328+
<argument name="configSource" xsi:type="object">Magento\Config\App\Config\Source\EnvironmentConfigSource</argument>
1329+
</arguments>
1330+
</type>
13271331
</config>

lib/internal/Magento/Framework/App/Config/MetadataConfigTypeProcessor.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88
namespace Magento\Framework\App\Config;
99

10-
use Magento\Config\App\Config\Source\EnvironmentConfigSource;
1110
use Magento\Framework\App\Config\Data\ProcessorFactory;
1211
use Magento\Framework\App\Config\Spi\PostProcessorInterface;
1312
use Magento\Framework\App\ObjectManager;
@@ -25,11 +24,11 @@ class MetadataConfigTypeProcessor implements PostProcessorInterface
2524
protected $_metadata = [];
2625

2726
/**
28-
* The environment configuration
27+
* Source of configurations
2928
*
30-
* @var EnvironmentConfigSource
29+
* @var ConfigSourceInterface
3130
*/
32-
private $environmentConfigSource;
31+
private $configSource;
3332

3433
/**
3534
* The resolver for configuration paths
@@ -41,19 +40,19 @@ class MetadataConfigTypeProcessor implements PostProcessorInterface
4140
/**
4241
* @param ProcessorFactory $processorFactory
4342
* @param Initial $initialConfig
44-
* @param EnvironmentConfigSource $environmentConfigSource The environment configuration
43+
* @param ConfigSourceInterface $configSource Source of configurations
4544
* @param ConfigPathResolver $configPathResolver The resolver for configuration paths
4645
*/
4746
public function __construct(
4847
ProcessorFactory $processorFactory,
4948
Initial $initialConfig,
50-
EnvironmentConfigSource $environmentConfigSource = null,
49+
ConfigSourceInterface $configSource = null,
5150
ConfigPathResolver $configPathResolver = null
5251
) {
5352
$this->_processorFactory = $processorFactory;
5453
$this->_metadata = $initialConfig->getMetadata();
55-
$this->environmentConfigSource = $environmentConfigSource
56-
?: ObjectManager::getInstance()->get(EnvironmentConfigSource::class);
54+
$this->configSource = $configSource
55+
?: ObjectManager::getInstance()->get(ConfigSourceInterface::class);
5756
$this->configPathResolver = $configPathResolver
5857
?: ObjectManager::getInstance()->get(ConfigPathResolver::class);
5958
}
@@ -116,7 +115,7 @@ private function processScopeData(
116115
) {
117116
foreach ($this->_metadata as $path => $metadata) {
118117
$configPath = $this->configPathResolver->resolve($path, $scope, $scopeCode);
119-
if (!empty($this->environmentConfigSource->get($configPath))) {
118+
if (!empty($this->configSource->get($configPath))) {
120119
continue;
121120
}
122121
/** @var \Magento\Framework\App\Config\Data\ProcessorInterface $processor */

lib/internal/Magento/Framework/App/Test/Unit/Config/MetadataConfigTypeProcessorTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66
namespace Magento\Framework\App\Test\Unit\Config;
77

8-
use Magento\Config\App\Config\Source\EnvironmentConfigSource;
98
use Magento\Framework\App\Config\ConfigPathResolver;
9+
use Magento\Framework\App\Config\ConfigSourceInterface;
1010
use Magento\Framework\App\Config\Data\ProcessorFactory;
1111
use Magento\Framework\App\Config\Data\ProcessorInterface;
1212
use Magento\Framework\App\Config\Initial;
@@ -36,9 +36,9 @@ class MetadataConfigTypeProcessorTest extends \PHPUnit_Framework_TestCase
3636
protected $_backendModelMock;
3737

3838
/**
39-
* @var EnvironmentConfigSource|MockObject
39+
* @var ConfigSourceInterface|MockObject
4040
*/
41-
private $environmentConfigSourceMock;
41+
private $configSourceMock;
4242

4343
/**
4444
* @var ConfigPathResolver|MockObject
@@ -55,9 +55,8 @@ protected function setUp()
5555
->getMock();
5656
$this->_backendModelMock= $this->getMockBuilder(ProcessorInterface::class)
5757
->getMockForAbstractClass();
58-
$this->environmentConfigSourceMock = $this->getMockBuilder(EnvironmentConfigSource::class)
59-
->disableOriginalConstructor()
60-
->getMock();
58+
$this->configSourceMock = $this->getMockBuilder(ConfigSourceInterface::class)
59+
->getMockForAbstractClass();
6160
$this->configPathResolverMock = $this->getMockBuilder(ConfigPathResolver::class)
6261
->disableOriginalConstructor()
6362
->getMock();
@@ -72,7 +71,7 @@ protected function setUp()
7271
$this->_model = new MetadataConfigTypeProcessor(
7372
$this->_modelPoolMock,
7473
$this->_initialConfigMock,
75-
$this->environmentConfigSourceMock,
74+
$this->configSourceMock,
7675
$this->configPathResolverMock
7776
);
7877
}
@@ -97,7 +96,7 @@ public function testProcess()
9796
'websites/website_one/some/config/path2',
9897
'websites/website_one/some/config/path3'
9998
);
100-
$this->environmentConfigSourceMock->expects($this->exactly(6))
99+
$this->configSourceMock->expects($this->exactly(6))
101100
->method('get')
102101
->withConsecutive(
103102
['default/some/config/path1'],

0 commit comments

Comments
 (0)