Skip to content

Commit 42dd708

Browse files
author
Dmytro Voskoboinikov
committed
Merge branch 'MAGETWO-81472' into 2.1.15-bugfixes-080618
2 parents 2722fea + 9515186 commit 42dd708

File tree

2 files changed

+52
-10
lines changed

2 files changed

+52
-10
lines changed

app/code/Magento/Config/App/Config/Type/System.php

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\Cache\FrontendInterface;
1313
use Magento\Framework\App\ObjectManager;
1414
use Magento\Config\App\Config\Type\System\Reader;
15+
use Magento\Framework\Encryption\EncryptorInterface;
1516
use Magento\Store\Model\Config\Processor\Fallback;
1617

1718
/**
@@ -101,6 +102,11 @@ class System implements ConfigTypeInterface
101102
*/
102103
private $availableDataScopes = null;
103104

105+
/**
106+
* @var EncryptorInterface
107+
*/
108+
private $encryptor;
109+
104110
/**
105111
* @param ConfigSourceInterface $source
106112
* @param PostProcessorInterface $postProcessor
@@ -110,6 +116,7 @@ class System implements ConfigTypeInterface
110116
* @param int $cachingNestedLevel
111117
* @param string $configType
112118
* @param Reader $reader
119+
* @param EncryptorInterface|null $encryptor
113120
*/
114121
public function __construct(
115122
ConfigSourceInterface $source,
@@ -119,7 +126,8 @@ public function __construct(
119126
PreProcessorInterface $preProcessor,
120127
$cachingNestedLevel = 1,
121128
$configType = self::CONFIG_TYPE,
122-
Reader $reader = null
129+
Reader $reader = null,
130+
EncryptorInterface $encryptor = null
123131
) {
124132
$this->source = $source;
125133
$this->postProcessor = $postProcessor;
@@ -129,6 +137,8 @@ public function __construct(
129137
$this->fallback = $fallback;
130138
$this->configType = $configType;
131139
$this->reader = $reader ?: ObjectManager::getInstance()->get(Reader::class);
140+
$this->encryptor = $encryptor ?: ObjectManager::getInstance()
141+
->get(EncryptorInterface::class);
132142
}
133143

134144
/**
@@ -193,7 +203,8 @@ private function loadAllData()
193203
if ($cachedData === false) {
194204
$data = $this->reader->read();
195205
} else {
196-
$data = unserialize($cachedData);
206+
207+
$data = unserialize($this->encryptor->decrypt($cachedData));
197208
}
198209

199210
return $data;
@@ -212,7 +223,11 @@ private function loadDefaultScopeData($scopeType)
212223
$data = $this->reader->read();
213224
$this->cacheData($data);
214225
} else {
215-
$data = [$scopeType => unserialize($cachedData)];
226+
$data = [
227+
$scopeType => unserialize(
228+
$this->encryptor->decrypt($cachedData)
229+
)
230+
];
216231
}
217232

218233
return $data;
@@ -232,7 +247,9 @@ private function loadScopeData($scopeType, $scopeId)
232247
if ($this->availableDataScopes === null) {
233248
$cachedScopeData = $this->cache->load($this->configType . '_scopes');
234249
if ($cachedScopeData !== false) {
235-
$this->availableDataScopes = unserialize($cachedScopeData);
250+
$this->availableDataScopes = unserialize(
251+
$this->encryptor->decrypt($cachedScopeData)
252+
);
236253
}
237254
}
238255
if (is_array($this->availableDataScopes) && !isset($this->availableDataScopes[$scopeType][$scopeId])) {
@@ -241,7 +258,13 @@ private function loadScopeData($scopeType, $scopeId)
241258
$data = $this->reader->read();
242259
$this->cacheData($data);
243260
} else {
244-
$data = [$scopeType => [$scopeId => unserialize($cachedData)]];
261+
$data = [
262+
$scopeType => [
263+
$scopeId => unserialize(
264+
$this->encryptor->decrypt($cachedData)
265+
)
266+
]
267+
];
245268
}
246269

247270
return $data;
@@ -257,12 +280,12 @@ private function loadScopeData($scopeType, $scopeId)
257280
private function cacheData(array $data)
258281
{
259282
$this->cache->save(
260-
serialize($data),
283+
$this->encryptor->encrypt(serialize($data)),
261284
$this->configType,
262285
[self::CACHE_TAG]
263286
);
264287
$this->cache->save(
265-
serialize($data['default']),
288+
$this->encryptor->encrypt(serialize($data['default'])),
266289
$this->configType . '_default',
267290
[self::CACHE_TAG]
268291
);
@@ -271,14 +294,14 @@ private function cacheData(array $data)
271294
foreach ($data[$curScopeType] as $curScopeId => $curScopeData) {
272295
$scopes[$curScopeType][$curScopeId] = 1;
273296
$this->cache->save(
274-
serialize($curScopeData),
297+
$this->encryptor->encrypt(serialize($curScopeData)),
275298
$this->configType . '_' . $curScopeType . '_' . $curScopeId,
276299
[self::CACHE_TAG]
277300
);
278301
}
279302
}
280303
$this->cache->save(
281-
serialize($scopes),
304+
$this->encryptor->encrypt(serialize($scopes)),
282305
$this->configType . "_scopes",
283306
[self::CACHE_TAG]
284307
);

app/code/Magento/Config/Test/Unit/App/Config/Type/SystemTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\App\Config\Spi\PostProcessorInterface;
1212
use Magento\Framework\App\Config\Spi\PreProcessorInterface;
1313
use Magento\Framework\Cache\FrontendInterface;
14+
use Magento\Framework\Encryption\EncryptorInterface;
1415
use Magento\Store\Model\Config\Processor\Fallback;
1516
use Magento\Config\App\Config\Type\System\Reader;
1617

@@ -55,6 +56,11 @@ class SystemTest extends \PHPUnit_Framework_TestCase
5556
*/
5657
private $reader;
5758

59+
/**
60+
* @var EncryptorInterface|\PHPUnit_Framework_MockObject_MockObject
61+
*/
62+
private $encryptorMock;
63+
5864
public function setUp()
5965
{
6066
$this->source = $this->getMockBuilder(ConfigSourceInterface::class)
@@ -71,6 +77,9 @@ public function setUp()
7177
$this->reader = $this->getMockBuilder(Reader::class)
7278
->disableOriginalConstructor()
7379
->getMock();
80+
$this->encryptorMock = $this->getMockBuilder(EncryptorInterface::class)
81+
->disableOriginalConstructor()
82+
->getMock();
7483

7584
$this->configType = new System(
7685
$this->source,
@@ -80,7 +89,8 @@ public function setUp()
8089
$this->preProcessor,
8190
1,
8291
'system',
83-
$this->reader
92+
$this->reader,
93+
$this->encryptorMock
8494
);
8595
}
8696

@@ -99,6 +109,9 @@ public function testGetCachedWithLoadDefaultScopeData()
99109
$this->cache->expects($this->once())
100110
->method('load')
101111
->willReturn(serialize($data));
112+
$this->encryptorMock->expects($this->once())
113+
->method('decrypt')
114+
->willReturnArgument(0);
102115
$this->assertEquals($url, $this->configType->get($path));
103116
}
104117

@@ -116,6 +129,9 @@ public function testGetCachedWithLoadAllData()
116129
$this->cache->expects($this->once())
117130
->method('load')
118131
->willReturn(serialize($data));
132+
$this->encryptorMock->expects($this->once())
133+
->method('decrypt')
134+
->willReturnArgument(0);
119135
$this->assertEquals($data, $this->configType->get(''));
120136
}
121137

@@ -147,6 +163,9 @@ public function testGetNotCached()
147163
$this->reader->expects($this->once())
148164
->method('read')
149165
->willReturn($data);
166+
$this->encryptorMock->expects($this->atLeastOnce())
167+
->method('encrypt')
168+
->willReturnArgument(0);
150169

151170
$this->assertEquals($url, $this->configType->get($path));
152171
}

0 commit comments

Comments
 (0)