Skip to content

Commit 001994d

Browse files
Merge pull request #6190 from magento-borg/cia-2.3.7
[CIA] Bugfixes
2 parents 46e2216 + 81d0450 commit 001994d

File tree

32 files changed

+34152
-31352
lines changed

32 files changed

+34152
-31352
lines changed

app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,37 @@
55
*/
66
namespace Magento\Backend\Controller\Adminhtml\System\Account;
77

8+
use Magento\Backend\App\Action\Context;
9+
use Magento\Framework\App\Action\HttpPostActionInterface;
10+
use Magento\Framework\App\ObjectManager;
811
use Magento\Framework\Validator\Exception as ValidatorException;
9-
use Magento\Framework\Exception\AuthenticationException;
1012
use Magento\Framework\Exception\LocalizedException;
1113
use Magento\Framework\Controller\ResultFactory;
1214
use Magento\Framework\Exception\State\UserLockedException;
1315
use Magento\Security\Model\SecurityCookie;
1416

1517
/**
18+
* Saving an admin user info.
19+
*
1620
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1721
*/
18-
class Save extends \Magento\Backend\Controller\Adminhtml\System\Account
22+
class Save extends \Magento\Backend\Controller\Adminhtml\System\Account implements HttpPostActionInterface
1923
{
2024
/**
2125
* @var SecurityCookie
2226
*/
2327
private $securityCookie;
2428

2529
/**
26-
* Get security cookie
30+
* Save controller constructor.
2731
*
28-
* @return SecurityCookie
29-
* @deprecated 100.1.0
32+
* @param Context $context
33+
* @param SecurityCookie|null $securityCookie
3034
*/
31-
private function getSecurityCookie()
35+
public function __construct(Context $context, ?SecurityCookie $securityCookie = null)
3236
{
33-
if (!($this->securityCookie instanceof SecurityCookie)) {
34-
return \Magento\Framework\App\ObjectManager::getInstance()->get(SecurityCookie::class);
35-
}
36-
return $this->securityCookie;
37+
parent::__construct($context);
38+
$this->securityCookie = $securityCookie ?? ObjectManager::getInstance()->get(SecurityCookie::class);
3739
}
3840

3941
/**
@@ -71,7 +73,7 @@ public function execute()
7173
$user->performIdentityCheck($currentUserPassword);
7274
if ($password !== '') {
7375
$user->setPassword($password);
74-
$user->setPasswordConfirmation($passwordConfirmation);
76+
$user->setData('password_confirmation', $passwordConfirmation);
7577
}
7678
$errors = $user->validate();
7779
if ($errors !== true && !empty($errors)) {
@@ -85,7 +87,7 @@ public function execute()
8587
}
8688
} catch (UserLockedException $e) {
8789
$this->_auth->logout();
88-
$this->getSecurityCookie()->setLogoutReasonCookie(
90+
$this->securityCookie->setLogoutReasonCookie(
8991
\Magento\Security\Model\AdminSessionsManager::LOGOUT_REASON_USER_LOCKED
9092
);
9193
} catch (ValidatorException $e) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,9 @@
198198
<argument name="anchorRenderer" xsi:type="object">Magento\Backend\Block\AnchorRenderer</argument>
199199
</arguments>
200200
</type>
201+
<type name="Magento\Backend\Controller\Adminhtml\System\Account\Save">
202+
<arguments>
203+
<argument name="securityCookie" xsi:type="object">Magento\Security\Model\SecurityCookie\Proxy</argument>
204+
</arguments>
205+
</type>
201206
</config>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Captcha\Api;
9+
10+
/**
11+
* Interface contains methods for post processing and modifies client-side CAPTCHA config
12+
*/
13+
interface CaptchaConfigPostProcessorInterface
14+
{
15+
/**
16+
* Filters the data object by a filter list
17+
*
18+
* @param array $config
19+
* @return array
20+
*/
21+
public function process(array $config): array;
22+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Captcha\Model\Filter;
9+
10+
use Magento\Captcha\Api\CaptchaConfigPostProcessorInterface;
11+
12+
/**
13+
* Composite class for post processing captcha configuration
14+
*/
15+
class CaptchaConfigPostProcessorComposite implements CaptchaConfigPostProcessorInterface
16+
{
17+
/**
18+
* @var CaptchaConfigPostProcessorInterface[] $processors
19+
*/
20+
private $processors = [];
21+
22+
/**
23+
* @param CaptchaConfigPostProcessorInterface[] $processors
24+
*/
25+
public function __construct(
26+
$processors = []
27+
) {
28+
$this->processors = $processors;
29+
}
30+
31+
/**
32+
* Loops through all leafs of the composite and calls process method
33+
*
34+
* @param array $config
35+
* @return array
36+
*/
37+
public function process(array $config): array
38+
{
39+
$result = [];
40+
foreach ($this->processors as $processor) {
41+
$result = array_merge_recursive($result, $processor->process($config));
42+
}
43+
return $result;
44+
}
45+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Captcha\Model\Filter;
9+
10+
use Magento\Captcha\Api\CaptchaConfigPostProcessorInterface;
11+
12+
/**
13+
* Class QuoteDataConfigFilter used for filtering config quote data based on filter list
14+
*/
15+
class QuoteDataConfigFilter implements CaptchaConfigPostProcessorInterface
16+
{
17+
/**
18+
* @var array $filterList
19+
*/
20+
private $filterList;
21+
22+
/**
23+
* @param array $filterList
24+
*/
25+
public function __construct(
26+
array $filterList = []
27+
) {
28+
$this->filterList = $filterList;
29+
}
30+
31+
/**
32+
* Filters the quote config with values from a filter list
33+
*
34+
* @param array $config
35+
* @return array
36+
*/
37+
public function process(array $config): array
38+
{
39+
foreach ($this->filterList as $filterKey) {
40+
/** @var string $filterKey */
41+
if (isset($config['quoteData']) && array_key_exists($filterKey, $config['quoteData'])) {
42+
unset($config['quoteData'][$filterKey]);
43+
}
44+
}
45+
return $config;
46+
}
47+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Captcha\Test\Unit\Model\Filter;
9+
10+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
11+
use PHPUnit\Framework\TestCase;
12+
use Magento\Captcha\Api\CaptchaConfigPostProcessorInterface;
13+
use Magento\Captcha\Model\Filter\CaptchaConfigPostProcessorComposite;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
16+
/**
17+
* Test for Class \Magento\Captcha\Model\Filter\CaptchaConfigPostProcessorComposite
18+
*/
19+
class CaptchaConfigPostProcessorCompositeTest extends TestCase
20+
{
21+
/**
22+
* @var CaptchaConfigPostProcessorComposite
23+
*/
24+
private $model;
25+
26+
/**
27+
* @var ObjectManager
28+
*/
29+
private $objectManager;
30+
31+
/**
32+
* @var MockObject
33+
*/
34+
private $processorMock1;
35+
36+
/**
37+
* @var MockObject
38+
*/
39+
private $processorMock2;
40+
41+
/**
42+
* Initialize Class Dependencies
43+
*/
44+
protected function setUp(): void
45+
{
46+
$this->objectManager = new ObjectManager($this);
47+
48+
$this->processorMock1 = $this->getMockBuilder(CaptchaConfigPostProcessorInterface::class)
49+
->disableOriginalConstructor()
50+
->setMethods(['process'])
51+
->getMock();
52+
$this->processorMock2 = $this->getMockBuilder(CaptchaConfigPostProcessorInterface::class)
53+
->disableOriginalConstructor()
54+
->setMethods(['process'])
55+
->getMock();
56+
57+
$processors = [$this->processorMock1, $this->processorMock2];
58+
59+
$this->model = $this->objectManager->getObject(
60+
CaptchaConfigPostProcessorComposite::class,
61+
[
62+
'processors' => $processors,
63+
]
64+
);
65+
}
66+
67+
/**
68+
* Test for Composite
69+
*
70+
* @return void
71+
*/
72+
public function testProcess(): void
73+
{
74+
$config = ['test1','test2', 'test3'];
75+
76+
$this->processorMock1->expects($this->atLeastOnce())
77+
->method('process')
78+
->with($config)
79+
->willReturn(['test1', 'test2']);
80+
$this->processorMock2->expects($this->atLeastOnce())
81+
->method('process')
82+
->with($config)
83+
->willReturn(['test3']);
84+
85+
$this->assertEquals(['test1','test2', 'test3'], $this->model->process($config));
86+
}
87+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Captcha\Test\Unit\Model\Filter;
9+
10+
use Magento\Captcha\Model\Filter\QuoteDataConfigFilter;
11+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
12+
use PHPUnit\Framework\TestCase;
13+
14+
/**
15+
* Test for Class \Magento\Captcha\Model\Filter\QuoteDataConfigFilter
16+
*/
17+
class QuoteDataConfigFilterTest extends TestCase
18+
{
19+
20+
/**
21+
* @var QuoteDataConfigFilter
22+
*/
23+
private $model;
24+
25+
/**
26+
* @var ObjectManager
27+
*/
28+
private $objectManager;
29+
30+
/**
31+
* Initialize Class Dependencies
32+
*/
33+
protected function setUp()
34+
{
35+
$this->objectManager = new ObjectManager($this);
36+
37+
$this->model = $this->objectManager->getObject(
38+
QuoteDataConfigFilter::class,
39+
[
40+
'filterList' => ['test1', 'test2'],
41+
]
42+
);
43+
}
44+
45+
/**
46+
* Test Process method
47+
*
48+
* @return void
49+
*/
50+
public function testProcess(): void
51+
{
52+
$config = [
53+
'quoteData' =>
54+
[
55+
'test1' => 1,
56+
'test2' => 2,
57+
'test3' => 3
58+
]
59+
];
60+
61+
$expected = [
62+
'quoteData' =>
63+
[
64+
'test3' => 3
65+
]
66+
];
67+
68+
$this->assertEquals($expected, $this->model->process($config));
69+
}
70+
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<preference for="Magento\Captcha\Api\CaptchaConfigPostProcessorInterface" type="Magento\Captcha\Model\Filter\CaptchaConfigPostProcessorComposite"/>
910
<type name="Magento\Captcha\Model\DefaultModel">
1011
<arguments>
1112
<argument name="session" xsi:type="object">Magento\Customer\Model\Session</argument>
@@ -39,4 +40,19 @@
3940
<type name="Magento\Checkout\Block\Cart\Sidebar">
4041
<plugin name="login_captcha" type="Magento\Captcha\Model\Cart\ConfigPlugin" sortOrder="50" />
4142
</type>
43+
<type name="Magento\Captcha\Model\Filter\CaptchaConfigPostProcessorComposite">
44+
<arguments>
45+
<argument name="processors" xsi:type="array">
46+
<item name="processor" xsi:type="object">Magento\Captcha\Model\Filter\QuoteDataConfigFilter</item>
47+
</argument>
48+
</arguments>
49+
</type>
50+
<type name="Magento\Captcha\Model\Filter\QuoteDataConfigFilter">
51+
<arguments>
52+
<argument name="filterList" xsi:type="array">
53+
<item name="remote_ip" xsi:type="string">remote_ip</item>
54+
<item name="x_forwarded_for" xsi:type="string">x_forwarded_for</item>
55+
</argument>
56+
</arguments>
57+
</type>
4258
</config>

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ public function execute()
185185
}
186186

187187
$attributeId = $this->getRequest()->getParam('attribute_id');
188+
if (!empty($data['attribute_id']) && $data['attribute_id'] != $attributeId) {
189+
$attributeId = $data['attribute_id'];
190+
}
188191

189192
/** @var ProductAttributeInterface $model */
190193
$model = $this->attributeFactory->create();

0 commit comments

Comments
 (0)