Skip to content

Commit 90074e7

Browse files
Merge pull request #1809 from magento-engcom/2.1-develop-prs
[EngCom] Public Pull Requests - 2.1-develop - MAGETWO-85104: Fixes #8009 #12548 - MAGETWO-84861: [Backport 2.1-develop] #11409: Too many password reset requests even when disabled in settings #11436
2 parents de95b3e + bebeb53 commit 90074e7

File tree

8 files changed

+153
-69
lines changed

8 files changed

+153
-69
lines changed

app/code/Magento/CatalogInventory/Model/Indexer/Stock/AbstractAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ protected function _reindexRows($productIds = [])
248248
}
249249
}
250250

251-
$this->cacheContext->registerEntities(Product::CACHE_TAG, $productIds);
251+
$this->cacheContext->registerEntities(Product::CACHE_TAG, $processIds);
252252
$this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this->cacheContext]);
253253

254254
return $this;

app/code/Magento/Security/Model/Config.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,17 @@ class Config implements ConfigInterface
2424
*/
2525
const XML_PATH_ADMIN_AREA = 'admin/security/';
2626

27+
/**
28+
* Configuration path to frontend area
29+
*/
30+
const XML_PATH_FRONTEND_AREA = 'customer/password/';
31+
2732
/**
2833
* Configuration path to fronted area
34+
* @deprecated
35+
* @see \Magento\Security\Model\Config::XML_PATH_FRONTEND_AREA
2936
*/
30-
const XML_PATH_FRONTED_AREA = 'customer/password/';
37+
const XML_PATH_FRONTED_AREA = self::XML_PATH_FRONTEND_AREA;
3138

3239
/**
3340
* Configuration path to admin account sharing
@@ -134,7 +141,7 @@ protected function getXmlPathPrefix()
134141
if ($this->scope->getCurrentScope() == \Magento\Framework\App\Area::AREA_ADMINHTML) {
135142
return self::XML_PATH_ADMIN_AREA;
136143
}
137-
return self::XML_PATH_FRONTED_AREA;
144+
return self::XML_PATH_FRONTEND_AREA;
138145
}
139146

140147
/**

app/code/Magento/Security/Model/Plugin/AccountManagement.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
*/
66
namespace Magento\Security\Model\Plugin;
77

8-
use Magento\Security\Model\SecurityManager;
98
use Magento\Customer\Model\AccountManagement as AccountManagementOriginal;
9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\Config\ScopeInterface;
1011
use Magento\Framework\Exception\SecurityViolationException;
1112
use Magento\Security\Model\PasswordResetRequestEvent;
13+
use Magento\Security\Model\SecurityManager;
1214

1315
/**
1416
* Magento\Customer\Model\AccountManagement decorator
@@ -30,21 +32,29 @@ class AccountManagement
3032
*/
3133
protected $passwordRequestEvent;
3234

35+
/**
36+
* @var ScopeInterface
37+
*/
38+
private $scope;
39+
3340
/**
3441
* AccountManagement constructor.
3542
*
3643
* @param \Magento\Framework\App\RequestInterface $request
3744
* @param SecurityManager $securityManager
3845
* @param int $passwordRequestEvent
46+
* @param ScopeInterface $scope
3947
*/
4048
public function __construct(
4149
\Magento\Framework\App\RequestInterface $request,
4250
\Magento\Security\Model\SecurityManager $securityManager,
43-
$passwordRequestEvent = PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST
51+
$passwordRequestEvent = PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST,
52+
ScopeInterface $scope = null
4453
) {
4554
$this->request = $request;
4655
$this->securityManager = $securityManager;
4756
$this->passwordRequestEvent = $passwordRequestEvent;
57+
$this->scope = $scope ?: ObjectManager::getInstance()->get(ScopeInterface::class);
4858
}
4959

5060
/**
@@ -63,10 +73,14 @@ public function beforeInitiatePasswordReset(
6373
$template,
6474
$websiteId = null
6575
) {
66-
$this->securityManager->performSecurityCheck(
67-
$this->passwordRequestEvent,
68-
$email
69-
);
76+
if ($this->scope->getCurrentScope() == \Magento\Framework\App\Area::AREA_FRONTEND
77+
|| $this->passwordRequestEvent == PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST) {
78+
$this->securityManager->performSecurityCheck(
79+
$this->passwordRequestEvent,
80+
$email
81+
);
82+
}
83+
7084
return [$email, $template, $websiteId];
7185
}
7286
}

app/code/Magento/Security/Test/Unit/Model/ConfigTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ protected function getXmlPathPrefix($scope)
176176
if ($scope == \Magento\Framework\App\Area::AREA_ADMINHTML) {
177177
return \Magento\Security\Model\Config::XML_PATH_ADMIN_AREA;
178178
}
179-
return \Magento\Security\Model\Config::XML_PATH_FRONTED_AREA;
179+
return \Magento\Security\Model\Config::XML_PATH_FRONTEND_AREA;
180180
}
181181

182182
/**

app/code/Magento/Security/Test/Unit/Model/Plugin/AccountManagementTest.php

Lines changed: 58 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
namespace Magento\Security\Test\Unit\Model\Plugin;
87

8+
use Magento\Customer\Model\AccountManagement;
9+
use Magento\Framework\App\Area;
10+
use Magento\Framework\Config\ScopeInterface;
911
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
12+
use Magento\Security\Model\PasswordResetRequestEvent;
1013

1114
/**
1215
* Test class for \Magento\Security\Model\Plugin\AccountManagement testing
@@ -19,20 +22,25 @@ class AccountManagementTest extends \PHPUnit_Framework_TestCase
1922
protected $model;
2023

2124
/**
22-
* @var \Magento\Framework\App\RequestInterface
25+
* @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject
2326
*/
2427
protected $request;
2528

2629
/**
27-
* @var \Magento\Security\Model\SecurityManager
30+
* @var \Magento\Security\Model\SecurityManager|\PHPUnit_Framework_MockObject_MockObject
2831
*/
2932
protected $securityManager;
3033

3134
/**
32-
* @var \Magento\Customer\Model\AccountManagement
35+
* @var AccountManagement|\PHPUnit_Framework_MockObject_MockObject
3336
*/
3437
protected $accountManagement;
3538

39+
/**
40+
* @var ScopeInterface|\PHPUnit_Framework_MockObject_MockObject
41+
*/
42+
private $scope;
43+
3644
/**
3745
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
3846
*/
@@ -46,50 +54,49 @@ public function setUp()
4654
{
4755
$this->objectManager = new ObjectManager($this);
4856

49-
$this->request = $this->getMock(
50-
'\Magento\Framework\App\RequestInterface',
51-
[],
52-
[],
53-
'',
54-
false
55-
);
57+
$this->request = $this->getMock(\Magento\Framework\App\RequestInterface::class);
5658

57-
$this->securityManager = $this->getMock(
58-
'\Magento\Security\Model\SecurityManager',
59-
['performSecurityCheck'],
60-
[],
61-
'',
62-
false
63-
);
59+
$this->securityManager = $this->getMockBuilder(
60+
\Magento\Security\Model\SecurityManager::class
61+
)->setMethods(
62+
['performSecurityCheck']
63+
)->disableOriginalConstructor()->getMock();
6464

65-
$this->accountManagement = $this->getMock(
66-
'\Magento\Customer\Model\AccountManagement',
67-
[],
68-
[],
69-
'',
70-
false
71-
);
65+
$this->accountManagement = $this->getMockBuilder(
66+
AccountManagement::class
67+
)->disableOriginalConstructor()->getMock();
7268

73-
$this->model = $this->objectManager->getObject(
74-
'\Magento\Security\Model\Plugin\AccountManagement',
75-
[
76-
'request' => $this->request,
77-
'securityManager' => $this->securityManager
78-
]
79-
);
69+
$this->scope = $this->getMock(ScopeInterface::class);
8070
}
8171

8272
/**
83-
* @return void
73+
* @param $area
74+
* @param $passwordRequestEvent
75+
* @param $expectedTimes
76+
* @dataProvider beforeInitiatePasswordResetDataProvider
8477
*/
85-
public function testBeforeInitiatePasswordReset()
78+
public function testBeforeInitiatePasswordReset($area, $passwordRequestEvent, $expectedTimes)
8679
{
8780
$email = '[email protected]';
88-
$template = \Magento\Customer\Model\AccountManagement::EMAIL_RESET;
81+
$template = AccountManagement::EMAIL_RESET;
8982

90-
$this->securityManager->expects($this->once())
83+
$this->model = $this->objectManager->getObject(
84+
\Magento\Security\Model\Plugin\AccountManagement::class,
85+
[
86+
'passwordRequestEvent' => $passwordRequestEvent,
87+
'request' => $this->request,
88+
'securityManager' => $this->securityManager,
89+
'scope' => $this->scope
90+
]
91+
);
92+
93+
$this->scope->expects($this->once())
94+
->method('getCurrentScope')
95+
->willReturn($area);
96+
97+
$this->securityManager->expects($this->exactly($expectedTimes))
9198
->method('performSecurityCheck')
92-
->with(\Magento\Security\Model\PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST, $email)
99+
->with($passwordRequestEvent, $email)
93100
->willReturnSelf();
94101

95102
$this->model->beforeInitiatePasswordReset(
@@ -98,4 +105,18 @@ public function testBeforeInitiatePasswordReset()
98105
$template
99106
);
100107
}
108+
109+
/**
110+
* @return array
111+
*/
112+
public function beforeInitiatePasswordResetDataProvider()
113+
{
114+
return [
115+
[Area::AREA_ADMINHTML, PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST, 0],
116+
[Area::AREA_ADMINHTML, PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST, 1],
117+
[Area::AREA_FRONTEND, PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST, 1],
118+
// This should never happen, but let's cover it with tests
119+
[Area::AREA_FRONTEND, PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST, 1],
120+
];
121+
}
101122
}

app/code/Magento/Security/etc/adminhtml/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</type>
1818
<type name="Magento\Security\Model\Plugin\AccountManagement">
1919
<arguments>
20-
<argument name="passwordRequestEvent" xsi:type="const">Magento\Security\Model\PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST</argument>
20+
<argument name="passwordRequestEvent" xsi:type="const">Magento\Security\Model\PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST</argument>
2121
</arguments>
2222
</type>
2323
<type name="Magento\Security\Model\SecurityManager">

dev/tests/api-functional/testsuite/Magento/Customer/Api/AccountManagementTest.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@
88
use Magento\Customer\Api\Data\CustomerInterface as Customer;
99
use Magento\Customer\Model\AccountManagement;
1010
use Magento\Framework\Exception\InputException;
11-
use Magento\Framework\Exception\NoSuchEntityException;
11+
use Magento\Framework\Webapi\Exception as HTTPExceptionCodes;
12+
use Magento\Newsletter\Model\Subscriber;
13+
use Magento\Security\Model\Config;
1214
use Magento\TestFramework\Helper\Bootstrap;
1315
use Magento\TestFramework\Helper\Customer as CustomerHelper;
1416
use Magento\TestFramework\TestCase\WebapiAbstract;
15-
use Magento\Framework\Webapi\Exception as HTTPExceptionCodes;
16-
use Magento\Security\Model\Config;
17-
use Magento\Newsletter\Model\Plugin\CustomerPlugin;
18-
use Magento\Framework\Webapi\Rest\Request as RestRequest;
19-
use Magento\Newsletter\Model\Subscriber;
20-
use Magento\Customer\Model\Data\Customer as CustomerData;
2117

2218
/**
2319
* Test class for Magento\Customer\Api\AccountManagementInterface
@@ -112,16 +108,16 @@ public function setUp()
112108
$this->initSubscriber();
113109

114110
if ($this->config->getConfigDataValue(
115-
Config::XML_PATH_FRONTED_AREA .
111+
Config::XML_PATH_FRONTEND_AREA .
116112
Config::XML_PATH_PASSWORD_RESET_PROTECTION_TYPE
117113
) != 0) {
118114
$this->configValue = $this->config
119115
->getConfigDataValue(
120-
Config::XML_PATH_FRONTED_AREA .
116+
Config::XML_PATH_FRONTEND_AREA .
121117
Config::XML_PATH_PASSWORD_RESET_PROTECTION_TYPE
122118
);
123119
$this->config->setDataByPath(
124-
Config::XML_PATH_FRONTED_AREA . Config::XML_PATH_PASSWORD_RESET_PROTECTION_TYPE,
120+
Config::XML_PATH_FRONTEND_AREA . Config::XML_PATH_PASSWORD_RESET_PROTECTION_TYPE,
125121
0
126122
);
127123
$this->config->save();
@@ -150,15 +146,16 @@ public function tearDown()
150146
}
151147
}
152148
$this->config->setDataByPath(
153-
Config::XML_PATH_FRONTED_AREA . Config::XML_PATH_PASSWORD_RESET_PROTECTION_TYPE,
149+
Config::XML_PATH_FRONTEND_AREA . Config::XML_PATH_PASSWORD_RESET_PROTECTION_TYPE,
154150
$this->configValue
155151
);
156152
$this->config->save();
157153
unset($this->accountManagement);
158154
unset($this->subscriber);
159155
}
160156

161-
private function initSubscriber() {
157+
private function initSubscriber()
158+
{
162159
$this->subscriber = Bootstrap::getObjectManager()->create(
163160
'Magento\Newsletter\Model\Subscriber'
164161
);

0 commit comments

Comments
 (0)