Skip to content

Commit 7acadb5

Browse files
Merge pull request #2680 from magento-qwerty/2.1.15-bugfixes-080618
Fixed issues: - MAGETWO-88593: [Backport for 2.1.x] Deleting Stores - MAGETWO-88605: [Backport for 2.1.x] Invalid Video Uploader Link - MAGETWO-81472: [Backport for 2.1.x] Cached Config is Different From DB - MAGETWO-88599: [Backport for 2.1.x] Varnish Config Access List
2 parents 4d1b832 + d56d6d8 commit 7acadb5

File tree

9 files changed

+226
-34
lines changed

9 files changed

+226
-34
lines changed

app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteGroupPost.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,28 @@
77
namespace Magento\Backend\Controller\Adminhtml\System\Store;
88

99
use Magento\Framework\Controller\ResultFactory;
10+
use Magento\Framework\App\Request\Http as HttpRequest;
11+
use Magento\Framework\Exception\NotFoundException;
1012

1113
class DeleteGroupPost extends \Magento\Backend\Controller\Adminhtml\System\Store
1214
{
1315
/**
1416
* @return \Magento\Backend\Model\View\Result\Redirect
17+
* @throws NotFoundException
1518
*/
1619
public function execute()
1720
{
18-
$itemId = $this->getRequest()->getParam('item_id');
19-
21+
/** @var HttpRequest $request */
22+
$request = $this->getRequest();
2023
/** @var \Magento\Backend\Model\View\Result\Redirect $redirectResult */
21-
$redirectResult = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
24+
$redirectResult = $this->resultFactory->create(
25+
ResultFactory::TYPE_REDIRECT
26+
);
27+
if (!$request->isPost()) {
28+
throw new NotFoundException(__('Page not found.'));
29+
}
2230

31+
$itemId = $request->getParam('item_id');
2332
if (!($model = $this->_objectManager->create('Magento\Store\Model\Group')->load($itemId))) {
2433
$this->messageManager->addError(__('Something went wrong. Please try again.'));
2534
return $redirectResult->setPath('adminhtml/*/');

app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteStorePost.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,31 @@
66
*/
77
namespace Magento\Backend\Controller\Adminhtml\System\Store;
88

9+
use Magento\Framework\App\Request\Http as HttpRequest;
910
use Magento\Framework\Controller\ResultFactory;
11+
use Magento\Framework\Exception\NotFoundException;
1012

1113
class DeleteStorePost extends \Magento\Backend\Controller\Adminhtml\System\Store
1214
{
1315
/**
1416
* Delete store view post action
1517
*
1618
* @return \Magento\Backend\Model\View\Result\Redirect
19+
* @throws NotFoundException
1720
*/
1821
public function execute()
1922
{
20-
$itemId = $this->getRequest()->getParam('item_id');
21-
23+
/** @var HttpRequest $request */
24+
$request = $this->getRequest();
2225
/** @var \Magento\Backend\Model\View\Result\Redirect $redirectResult */
23-
$redirectResult = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
26+
$redirectResult = $this->resultFactory->create(
27+
ResultFactory::TYPE_REDIRECT
28+
);
29+
if (!$request->isPost()) {
30+
throw new NotFoundException(__('Page not found.'));
31+
}
32+
33+
$itemId = $request->getParam('item_id');
2434
if (!($model = $this->_objectManager->create('Magento\Store\Model\Store')->load($itemId))) {
2535
$this->messageManager->addError(__('Something went wrong. Please try again.'));
2636
return $redirectResult->setPath('adminhtml/*/');

app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteWebsitePost.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,30 @@
77
namespace Magento\Backend\Controller\Adminhtml\System\Store;
88

99
use Magento\Framework\Controller\ResultFactory;
10+
use Magento\Framework\App\Request\Http as HttpRequest;
11+
use Magento\Framework\Exception\NotFoundException;
1012

1113
class DeleteWebsitePost extends \Magento\Backend\Controller\Adminhtml\System\Store
1214
{
1315
/**
1416
* @return \Magento\Backend\Model\View\Result\Redirect
17+
* @throws NotFoundException
1518
*/
1619
public function execute()
1720
{
18-
$itemId = $this->getRequest()->getParam('item_id');
19-
$model = $this->_objectManager->create('Magento\Store\Model\Website');
20-
$model->load($itemId);
21-
21+
/** @var HttpRequest $request */
22+
$request = $this->getRequest();
2223
/** @var \Magento\Backend\Model\View\Result\Redirect $redirectResult */
23-
$redirectResult = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
24+
$redirectResult = $this->resultFactory->create(
25+
ResultFactory::TYPE_REDIRECT
26+
);
27+
if (!$request->isPost()) {
28+
throw new NotFoundException(__('Page not found.'));
29+
}
2430

31+
$itemId = $request->getParam('item_id');
32+
$model = $this->_objectManager->create('Magento\Store\Model\Website');
33+
$model->load($itemId);
2534
if (!$model) {
2635
$this->messageManager->addError(__('Something went wrong. Please try again.'));
2736
return $redirectResult->setPath('adminhtml/*/');

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
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\PageCache\Model\System\Config\Backend;
8+
9+
use Magento\Framework\Exception\LocalizedException;
10+
use Magento\Framework\Phrase;
11+
12+
/**
13+
* Access List config field.
14+
*/
15+
class AccessList extends Varnish
16+
{
17+
/**
18+
* @inheritDoc
19+
*/
20+
public function beforeSave()
21+
{
22+
parent::beforeSave();
23+
24+
$value = $this->getValue();
25+
if (!is_string($value) || !preg_match('/^[\w\s\.\-\,\:]+$/', $value)) {
26+
throw new LocalizedException(
27+
new Phrase(
28+
'Access List value "%1" is not valid. '
29+
.'Please use only IP addresses and host names.',
30+
[$value]
31+
)
32+
);
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)