Skip to content

Commit fd02a30

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

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

app/code/Magento/Config/Console/Command/ConfigShow/ValueProcessor.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,17 @@ public function process($scope, $scopeCode, $value, $path)
8686
$backendModel = $field && $field->hasBackendModel()
8787
? $field->getBackendModel()
8888
: $this->configValueFactory->create();
89+
90+
if ($backendModel instanceof Encrypted) {
91+
return $value ? self::SAFE_PLACEHOLDER : null;
92+
}
93+
8994
$backendModel->setPath($path);
9095
$backendModel->setScope($scope);
9196
$backendModel->setScopeId($scopeCode);
9297
$backendModel->setValue($value);
9398
$backendModel->afterLoad();
9499

95-
return ($backendModel instanceof Encrypted) && !empty($backendModel->getValue())
96-
? self::SAFE_PLACEHOLDER
97-
: $backendModel->getValue();
100+
return $backendModel->getValue();
98101
}
99102
}

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

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ protected function setUp()
6666
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $expectsGetBackendModel
6767
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $expectsCreate
6868
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $expectsGetValue
69+
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $expectsSetPath
70+
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $expectsSetScope
71+
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $expectsSetScopeId
72+
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $expectsSetValue
73+
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $expectsAfterLoad
6974
* @param string $expectsValue
7075
* @param string $className
7176
* @dataProvider processDataProvider
@@ -75,9 +80,15 @@ public function testProcess(
7580
$expectsGetBackendModel,
7681
$expectsCreate,
7782
$expectsGetValue,
83+
$expectsSetPath,
84+
$expectsSetScope,
85+
$expectsSetScopeId,
86+
$expectsSetValue,
87+
$expectsAfterLoad,
7888
$expectsValue,
7989
$className
80-
) {
90+
)
91+
{
8192
$scope = 'someScope';
8293
$scopeCode = 'someScopeCode';
8394
$value = 'someValue';
@@ -107,23 +118,23 @@ public function testProcess(
107118
->disableOriginalConstructor()
108119
->setMethods(['setPath', 'setScope', 'setScopeId', 'setValue', 'getValue', 'afterLoad'])
109120
->getMock();
110-
$backendModelMock->expects($this->once())
121+
$backendModelMock->expects($expectsSetPath)
111122
->method('setPath')
112123
->with($path)
113124
->willReturnSelf();
114-
$backendModelMock->expects($this->once())
125+
$backendModelMock->expects($expectsSetScope)
115126
->method('setScope')
116127
->with($scope)
117128
->willReturnSelf();
118-
$backendModelMock->expects($this->once())
129+
$backendModelMock->expects($expectsSetScopeId)
119130
->method('setScopeId')
120131
->with($scopeCode)
121132
->willReturnSelf();
122-
$backendModelMock->expects($this->once())
133+
$backendModelMock->expects($expectsSetValue)
123134
->method('setValue')
124135
->with($value)
125136
->willReturnSelf();
126-
$backendModelMock->expects($this->once())
137+
$backendModelMock->expects($expectsAfterLoad)
127138
->method('afterLoad')
128139
->willReturnSelf();
129140
$backendModelMock->expects($expectsGetValue)
@@ -163,22 +174,38 @@ public function processDataProvider()
163174
'expectsGetBackendModel' => $this->once(),
164175
'expectsCreate' => $this->never(),
165176
'expectsGetValue' => $this->once(),
177+
'expectsSetPath' => $this->once(),
178+
'expectsSetScope' => $this->once(),
179+
'expectsSetScopeId' => $this->once(),
180+
'expectsSetValue' => $this->once(),
181+
'expectsAfterLoad' => $this->once(),
166182
'expectsValue' => 'someValue',
167-
'className' => Value::class
183+
'className' => Value::class,
184+
168185
],
169186
[
170187
'hasBackendModel' => false,
171188
'expectsGetBackendModel' => $this->never(),
172189
'expectsCreate' => $this->once(),
173190
'expectsGetValue' => $this->once(),
191+
'expectsSetPath' => $this->once(),
192+
'expectsSetScope' => $this->once(),
193+
'expectsSetScopeId' => $this->once(),
194+
'expectsSetValue' => $this->once(),
195+
'expectsAfterLoad' => $this->once(),
174196
'expectsValue' => 'someValue',
175197
'className' => Value::class
176198
],
177199
[
178200
'hasBackendModel' => true,
179201
'expectsGetBackendModel' => $this->once(),
180202
'expectsCreate' => $this->never(),
181-
'expectsGetValue' => $this->once(),
203+
'expectsGetValue' => $this->never(),
204+
'expectsSetPath' => $this->never(),
205+
'expectsSetScope' => $this->never(),
206+
'expectsSetScopeId' => $this->never(),
207+
'expectsSetValue' => $this->never(),
208+
'expectsAfterLoad' => $this->never(),
182209
'expectsValue' => ValueProcessor::SAFE_PLACEHOLDER,
183210
'className' => Encrypted::class,
184211
],

0 commit comments

Comments
 (0)