Skip to content

Commit 2e8c9eb

Browse files
author
Yevhen Miroshnychenko
committed
MAGETWO-64556: Configuration management - Hide sensitive values from config:show command
1 parent cd7eeb3 commit 2e8c9eb

File tree

4 files changed

+91
-16
lines changed

4 files changed

+91
-16
lines changed

app/code/Magento/Config/Test/Unit/Console/Command/ConfigShow/ValueProcessorTest.php

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Magento\Framework\Config\ScopeInterface;
1414
use Magento\Framework\App\Area;
1515
use Magento\Config\Console\Command\ConfigShow\ValueProcessor;
16+
use Magento\Config\Model\Config\Backend\Encrypted;
17+
1618

1719
class ValueProcessorTest extends \PHPUnit_Framework_TestCase
1820
{
@@ -59,10 +61,19 @@ protected function setUp()
5961
* @param bool $hasBackendModel
6062
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $expectsGetBackendModel
6163
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $expectsCreate
64+
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $expectsGetValue
65+
* @param string $expectsValue
66+
* @param string $className
6267
* @dataProvider processDataProvider
6368
*/
64-
public function testProcess($hasBackendModel, $expectsGetBackendModel, $expectsCreate)
65-
{
69+
public function testProcess(
70+
$hasBackendModel,
71+
$expectsGetBackendModel,
72+
$expectsCreate,
73+
$expectsGetValue,
74+
$expectsValue,
75+
$className
76+
) {
6677
$scope = 'someScope';
6778
$scopeCode = 'someScopeCode';
6879
$value = 'someValue';
@@ -87,8 +98,8 @@ public function testProcess($hasBackendModel, $expectsGetBackendModel, $expectsC
8798
->method('create')
8899
->willReturn($structureMock);
89100

90-
/** @var Value|\PHPUnit_Framework_MockObject_MockObject $valueMock */
91-
$backendModelMock = $this->getMockBuilder(Value::class)
101+
/** @var Value|Encrypted|\PHPUnit_Framework_MockObject_MockObject $valueMock */
102+
$backendModelMock = $this->getMockBuilder($className)
92103
->disableOriginalConstructor()
93104
->setMethods(['setPath', 'setScope', 'setScopeId', 'setValue', 'getValue', 'afterLoad'])
94105
->getMock();
@@ -111,7 +122,7 @@ public function testProcess($hasBackendModel, $expectsGetBackendModel, $expectsC
111122
$backendModelMock->expects($this->once())
112123
->method('afterLoad')
113124
->willReturnSelf();
114-
$backendModelMock->expects($this->once())
125+
$backendModelMock->expects($expectsGetValue)
115126
->method('getValue')
116127
->willReturn($value);
117128

@@ -134,7 +145,7 @@ public function testProcess($hasBackendModel, $expectsGetBackendModel, $expectsC
134145
->with($path)
135146
->willReturn($fieldMock);
136147

137-
$this->assertSame($value, $this->valueProcessor->process($scope, $scopeCode, $value, $path));
148+
$this->assertSame($expectsValue, $this->valueProcessor->process($scope, $scopeCode, $value, $path));
138149
}
139150

140151
/**
@@ -143,8 +154,30 @@ public function testProcess($hasBackendModel, $expectsGetBackendModel, $expectsC
143154
public function processDataProvider()
144155
{
145156
return [
146-
['hasBackendModel' => true, 'expectsGetBackendModel' => $this->once(), 'expectsCreate' => $this->never()],
147-
['hasBackendModel' => false, 'expectsGetBackendModel' => $this->never(), 'expectsCreate' => $this->once()],
157+
[
158+
'hasBackendModel' => true,
159+
'expectsGetBackendModel' => $this->once(),
160+
'expectsCreate' => $this->never(),
161+
'expectsGetValue' => $this->once(),
162+
'expectsValue' => 'someValue',
163+
'className' => Value::class
164+
],
165+
[
166+
'hasBackendModel' => false,
167+
'expectsGetBackendModel' => $this->never(),
168+
'expectsCreate' => $this->once(),
169+
'expectsGetValue' => $this->once(),
170+
'expectsValue' => 'someValue',
171+
'className' => Value::class
172+
],
173+
[
174+
'hasBackendModel' => true,
175+
'expectsGetBackendModel' => $this->once(),
176+
'expectsCreate' => $this->never(),
177+
'expectsGetValue' => $this->never(),
178+
'expectsValue' => ValueProcessor::SAFE_PLACEHOLDER,
179+
'className' => Encrypted::class,
180+
],
148181
];
149182
}
150183
}

dev/tests/integration/testsuite/Magento/Config/Console/Command/ConfigShowCommandTest.php

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,23 @@
55
*/
66
namespace Magento\Config\Console\Command;
77

8-
use Magento\Store\Model\ScopeInterface;
8+
use Symfony\Component\Console\Tester\CommandTester;
9+
use Magento\Store\Model\ScopeInterface as ModelScopeInterface;
910
use Magento\TestFramework\Helper\Bootstrap;
11+
use Magento\Config\Model\Config\Structure\Data;
12+
use Magento\Config\Model\Config\Structure;
13+
use Magento\Config\Model\Config\Structure\Reader as StructureReader;
1014
use Magento\Framework\Console\Cli;
1115
use Magento\Framework\ObjectManagerInterface;
12-
use Symfony\Component\Console\Tester\CommandTester;
1316
use Magento\Framework\Filesystem;
1417
use Magento\Framework\App\Filesystem\DirectoryList;
15-
use Magento\Framework\Config\File\ConfigFilePool;
16-
use Magento\Framework\App\DeploymentConfig\Reader;
18+
use Magento\Framework\App\DeploymentConfig\Reader as DeploymentConfigReader;
1719
use Magento\Framework\App\DeploymentConfig\Writer;
20+
use Magento\Framework\App\Area;
21+
use Magento\Framework\App\Config\FileResolver;
22+
use Magento\Framework\Config\File\ConfigFilePool;
23+
use Magento\Framework\Config\ScopeInterface as ConfigScopeInterface;
24+
use Magento\Framework\Config\FileIteratorFactory;
1825

1926
class ConfigShowCommandTest extends \PHPUnit_Framework_TestCase
2027
{
@@ -39,7 +46,7 @@ class ConfigShowCommandTest extends \PHPUnit_Framework_TestCase
3946
private $configFilePool;
4047

4148
/**
42-
* @var Reader
49+
* @var DeploymentConfigReader
4350
*/
4451
private $reader;
4552

@@ -61,9 +68,21 @@ class ConfigShowCommandTest extends \PHPUnit_Framework_TestCase
6168
public function setUp()
6269
{
6370
$this->objectManager = Bootstrap::getObjectManager();
71+
72+
$this->objectManager->get(ConfigScopeInterface::class)->setCurrentScope(Area::AREA_ADMINHTML);
73+
74+
$fileIteratorFactory = $this->objectManager->get(FileIteratorFactory::class);
75+
$fileIterator = $fileIteratorFactory->create([__DIR__ . '/../../_files/system.xml']);
76+
77+
$fileResolverMock = $this->getMockBuilder(FileResolver::class)->disableOriginalConstructor()->getMock();
78+
$fileResolverMock->expects($this->any())->method('get')->will($this->returnValue($fileIterator));
79+
$structureReader = $this->objectManager->create(StructureReader::class, ['fileResolver' => $fileResolverMock]);
80+
$structureData = $this->objectManager->create(Data::class, ['reader' => $structureReader]);
81+
$this->objectManager->create(Structure::class, ['structureData' => $structureData]);
82+
6483
$this->configFilePool = $this->objectManager->get(ConfigFilePool::class);
6584
$this->filesystem = $this->objectManager->get(Filesystem::class);
66-
$this->reader = $this->objectManager->get(Reader::class);
85+
$this->reader = $this->objectManager->get(DeploymentConfigReader::class);
6786
$this->writer = $this->objectManager->get(Writer::class);
6887

6988
$this->config = $this->loadConfig();
@@ -138,6 +157,7 @@ public function executeDataProvider()
138157
'web/test/test_value_2' => ['value2.local_config.default.test'],
139158
'web/test2/test_value_3' => ['value3.config.default.test'],
140159
'web/test2/test_value_4' => ['value4.env.default.test'],
160+
'web/test3/test_value_5' => ['******'],
141161
'web/test' => [
142162
'web/test/test_value_1 - value1.db.default.test',
143163
'web/test/test_value_2 - value2.local_config.default.test',
@@ -157,11 +177,12 @@ public function executeDataProvider()
157177
'web/test/test_value_2 - value2.local_config.default.test',
158178
'web/test2/test_value_3 - value3.config.default.test',
159179
'web/test2/test_value_4 - value4.env.default.test',
180+
'web/test3/test_value_5 - ******',
160181
],
161182
]
162183
],
163184
[
164-
ScopeInterface::SCOPE_WEBSITES,
185+
ModelScopeInterface::SCOPE_WEBSITES,
165186
'base',
166187
Cli::RETURN_SUCCESS,
167188
[
@@ -192,7 +213,7 @@ public function executeDataProvider()
192213
]
193214
],
194215
[
195-
ScopeInterface::SCOPE_STORES,
216+
ModelScopeInterface::SCOPE_STORES,
196217
'default',
197218
Cli::RETURN_SUCCESS,
198219
[

dev/tests/integration/testsuite/Magento/Config/_files/config_data.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
'web/test/test_value_2' => 'value2.db.default.test',
1717
'web/test2/test_value_3' => 'value3.db.default.test',
1818
'web/test2/test_value_4' => 'value4.db.default.test',
19+
'web/test3/test_value_5' => 'value5.db.hashed.value',
1920
]
2021
],
2122
ScopeInterface::SCOPE_WEBSITES => [
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
9+
<system>
10+
<section id="web">
11+
<group id="test3" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
12+
<label>Test Label</label>
13+
<field id="test_value_5" translate="label comment" type="obscure" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">
14+
<label>Test Value 5</label>
15+
<backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
16+
</field>
17+
</group>
18+
</section>
19+
</system>
20+
</config>

0 commit comments

Comments
 (0)