Skip to content

Commit f33dd60

Browse files
MAGETWO-59809: Scrub sensitive data during app:dump
1 parent 0f97776 commit f33dd60

File tree

9 files changed

+107
-14
lines changed

9 files changed

+107
-14
lines changed

app/code/Magento/Config/Model/Config/Export/Comment.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Magento\Config\App\Config\Source\DumpConfigSourceInterface;
99
use Magento\Config\Model\Placeholder\PlaceholderFactory;
1010
use Magento\Config\Model\Placeholder\PlaceholderInterface;
11-
use Magento\Config\Model\Placeholder\Environment;
1211
use Magento\Framework\App\Config\CommentInterface;
1312

1413
/**
@@ -35,7 +34,7 @@ public function __construct(
3534
PlaceholderFactory $placeholderFactory,
3635
DumpConfigSourceInterface $source
3736
) {
38-
$this->placeholder = $placeholderFactory->create(Environment::class);
37+
$this->placeholder = $placeholderFactory->create(PlaceholderFactory::TYPE_ENVIRONMENT);
3938
$this->source = $source;
4039
}
4140

app/code/Magento/Config/Model/Config/Processor/EnvironmentPlaceholder.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
namespace Magento\Config\Model\Config\Processor;
77

8-
use Magento\Config\Model\Placeholder\Environment;
98
use Magento\Config\Model\Placeholder\PlaceholderFactory;
109
use Magento\Config\Model\Placeholder\PlaceholderInterface;
1110
use Magento\Framework\App\Config\Spi\PreProcessorInterface;
@@ -38,7 +37,7 @@ public function __construct(
3837
) {
3938
$this->placeholderFactory = $placeholderFactory;
4039
$this->arrayManager = $arrayManager;
41-
$this->placeholder = $placeholderFactory->create(Environment::class);
40+
$this->placeholder = $placeholderFactory->create(PlaceholderFactory::TYPE_ENVIRONMENT);
4241
}
4342

4443
/**

app/code/Magento/Config/Model/Config/Reader/Source/Deployed/SettingChecker.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Magento\Framework\App\DeploymentConfig;
1111
use Magento\Config\Model\Placeholder\PlaceholderInterface;
1212
use Magento\Config\Model\Placeholder\PlaceholderFactory;
13-
use Magento\Config\Model\Placeholder\Environment;
1413
use Magento\Framework\App\Config\ScopeCodeResolver;
1514

1615
/**
@@ -50,7 +49,7 @@ public function __construct(
5049
) {
5150
$this->config = $config;
5251
$this->scopeCodeResolver = $scopeCodeResolver;
53-
$this->placeholder = $placeholderFactory->create(Environment::class);
52+
$this->placeholder = $placeholderFactory->create(PlaceholderFactory::TYPE_ENVIRONMENT);
5453
}
5554

5655
/**

app/code/Magento/Config/Model/Placeholder/PlaceholderFactory.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,53 @@
55
*/
66
namespace Magento\Config\Model\Placeholder;
77

8+
use Magento\Framework\Exception\LocalizedException;
89
use Magento\Framework\ObjectManagerInterface;
910

1011
class PlaceholderFactory
1112
{
13+
/**
14+
* @const string Environment type
15+
*/
16+
const TYPE_ENVIRONMENT = 'environment';
17+
1218
/**
1319
* @var ObjectManagerInterface
1420
*/
1521
private $objectManager;
1622

23+
/**
24+
* @var array
25+
*/
26+
private $types;
27+
1728
/**
1829
* @param ObjectManagerInterface $objectManager
30+
* @param array $types
1931
*/
20-
public function __construct(ObjectManagerInterface $objectManager)
32+
public function __construct(ObjectManagerInterface $objectManager, array $types = [])
2133
{
2234
$this->objectManager = $objectManager;
35+
$this->types = $types;
2336
}
2437

2538
/**
2639
* Create placeholder
2740
*
2841
* @param string $type
2942
* @return PlaceholderInterface
43+
* @throws LocalizedException
3044
*/
3145
public function create($type)
3246
{
33-
$object = $this->objectManager->create($type);
47+
if (!isset($this->types[$type])) {
48+
throw new LocalizedException(__('There is no defined type ' . $type));
49+
}
50+
51+
$object = $this->objectManager->create($this->types[$type]);
3452

3553
if (!$object instanceof PlaceholderInterface) {
36-
throw new \LogicException('Object is not instance of ' . PlaceholderInterface::class);
54+
throw new LocalizedException(__('Object is not instance of ' . PlaceholderInterface::class));
3755
}
3856

3957
return $object;

app/code/Magento/Config/Test/Unit/Model/Config/Export/CommentTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ protected function setUp()
4242
->getMock();
4343
$placeholderFactoryMock->expects($this->once())
4444
->method('create')
45+
->with(PlaceholderFactory::TYPE_ENVIRONMENT)
4546
->willReturn($this->placeholderMock);
4647

4748
$this->configSourceMock = $this->getMockBuilder(DumpConfigSourceInterface::class)

app/code/Magento/Config/Test/Unit/Model/Config/Processor/EnvironmentPlaceholderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace Magento\Config\Test\Unit\Model\Config\Processor;
77

88
use Magento\Config\Model\Config\Processor\EnvironmentPlaceholder;
9-
use Magento\Config\Model\Placeholder\Environment;
109
use Magento\Config\Model\Placeholder\PlaceholderFactory;
1110
use Magento\Config\Model\Placeholder\PlaceholderInterface;
1211
use Magento\Framework\Stdlib\ArrayManager;
@@ -53,6 +52,7 @@ protected function setUp()
5352

5453
$this->placeholderFactoryMock->expects($this->any())
5554
->method('create')
55+
->with(PlaceholderFactory::TYPE_ENVIRONMENT)
5656
->willReturn($this->placeholderMock);
5757

5858
$this->model = new EnvironmentPlaceholder(

app/code/Magento/Config/Test/Unit/Model/Config/Reader/Source/Deployed/SettingCheckerTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Magento\Framework\App\DeploymentConfig;
1212
use Magento\Config\Model\Placeholder\PlaceholderInterface;
1313
use Magento\Config\Model\Placeholder\PlaceholderFactory;
14-
use Magento\Config\Model\Placeholder\Environment;
1514

1615
/**
1716
* Test class for checking settings that defined in config file
@@ -60,7 +59,7 @@ public function setUp()
6059

6160
$placeholderFactoryMock->expects($this->once())
6261
->method('create')
63-
->with(Environment::class)
62+
->with(PlaceholderFactory::TYPE_ENVIRONMENT)
6463
->willReturn($this->placeholderMock);
6564

6665
$this->checker = new SettingChecker($this->configMock, $placeholderFactoryMock, $this->scopeCodeResolverMock);
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Config\Test\Unit\Model\Placeholder;
7+
8+
use Magento\Config\Model\Placeholder\Environment;
9+
use Magento\Config\Model\Placeholder\PlaceholderFactory;
10+
use Magento\Framework\ObjectManagerInterface;
11+
12+
class PlaceholderFactoryTest extends \PHPUnit_Framework_TestCase
13+
{
14+
/**
15+
* @var PlaceholderFactory
16+
*/
17+
private $model;
18+
19+
/**
20+
* @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
21+
*/
22+
private $objectManagerMock;
23+
24+
/**
25+
* @var Environment|\PHPUnit_Framework_MockObject_MockObject
26+
*/
27+
private $environmentMock;
28+
29+
protected function setUp()
30+
{
31+
$this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
32+
->getMockForAbstractClass();
33+
$this->environmentMock = $this->getMockBuilder(Environment::class)
34+
->disableOriginalConstructor()
35+
->getMock();
36+
37+
$this->model = new PlaceholderFactory(
38+
$this->objectManagerMock,
39+
[
40+
PlaceholderFactory::TYPE_ENVIRONMENT => Environment::class,
41+
'wrongClass' => \stdClass::class,
42+
]
43+
);
44+
}
45+
46+
public function testCreate()
47+
{
48+
$this->objectManagerMock->expects($this->once())
49+
->method('create')
50+
->with(Environment::class)
51+
->willReturn($this->environmentMock);
52+
53+
$this->assertInstanceOf(
54+
Environment::class,
55+
$this->model->create(PlaceholderFactory::TYPE_ENVIRONMENT)
56+
);
57+
}
58+
59+
/**
60+
* @expectedException \Magento\Framework\Exception\LocalizedException
61+
* @expectedExceptionMessage There is no defined type dummyClass
62+
*/
63+
public function testCreateNonExisted()
64+
{
65+
$this->model->create('dummyClass');
66+
}
67+
68+
/**
69+
* @expectedException \Magento\Framework\Exception\LocalizedException
70+
* @expectedExceptionMessage Object is not instance of Magento\Config\Model\Placeholder\PlaceholderInterface
71+
*/
72+
public function testCreateWrongImplementation()
73+
{
74+
$this->model->create('wrongClass');
75+
}
76+
}

app/code/Magento/Config/etc/di.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,11 @@
176176
<argument name="source" xsi:type="object">appDumpSystemSource</argument>
177177
</arguments>
178178
</type>
179-
<type name="Magento\Config\Model\Config\Structure">
179+
<type name="Magento\Config\Model\Placeholder\PlaceholderFactory">
180180
<arguments>
181-
<argument name="tabIterator" xsi:type="object">Magento\Config\Model\Config\Structure\Element\Iterator\Tab\Proxy</argument>
181+
<argument name="types" xsi:type="array">
182+
<item name="environment" xsi:type="string">Magento\Config\Model\Placeholder\Environment</item>
183+
</argument>
182184
</arguments>
183185
</type>
184186
</config>

0 commit comments

Comments
 (0)