1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2023 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
declare (strict_types=1 );
7
7
8
8
namespace Magento \GraphQl \App ;
9
9
10
+ use Magento \TestFramework \Helper \Bootstrap ;
11
+ use Magento \Customer \Api \AccountManagementInterface ;
12
+ use Magento \Framework \App \Area ;
13
+ use Magento \Framework \App \State ;
14
+ use Magento \Framework \Exception \SecurityViolationException ;
10
15
use Magento \Customer \Api \CustomerRepositoryInterface ;
11
16
use Magento \Framework \Exception \NoSuchEntityException ;
12
17
use Magento \Framework \Registry ;
@@ -118,7 +123,12 @@ public function testMergeCarts(): void
118
123
}
119
124
120
125
/**
126
+ * Test password reset email (security disabled)
127
+ *
121
128
* @magentoDataFixture Magento/Customer/_files/customer.php
129
+ * @magentoConfigFixture current_store customer/password/password_reset_protection_type 0
130
+ * @magentoConfigFixture current_store customer/password/max_number_password_reset_requests 0
131
+ * @magentoConfigFixture current_store customer/password/min_time_between_password_reset_requests 0
122
132
* @return void
123
133
*/
124
134
public function testRequestPasswordResetEmail (): void
@@ -136,7 +146,12 @@ public function testRequestPasswordResetEmail(): void
136
146
}
137
147
138
148
/**
149
+ * Test password reset (security disabled)
150
+ *
139
151
* @magentoDataFixture Magento/Customer/_files/customer.php
152
+ * @magentoConfigFixture current_store customer/password/password_reset_protection_type 0
153
+ * @magentoConfigFixture current_store customer/password/max_number_password_reset_requests 0
154
+ * @magentoConfigFixture current_store customer/password/min_time_between_password_reset_requests 0
140
155
* @return void
141
156
*/
142
157
public function testResetPassword (): void
@@ -155,6 +170,37 @@ public function testResetPassword(): void
155
170
);
156
171
}
157
172
173
+ /**
174
+ * Test that GraphQL password reset requests are subject to security checks (rate limiting)
175
+ * This test verifies our fix to include GraphQL area in security checks
176
+ *
177
+ * @magentoDataFixture Magento/Customer/_files/customer.php
178
+ * @magentoConfigFixture current_store customer/password/password_reset_protection_type 1
179
+ * @magentoConfigFixture current_store customer/password/max_number_password_reset_requests 1
180
+ * @magentoConfigFixture current_store customer/password/min_time_between_password_reset_requests 10
181
+ * @return void
182
+ */
183
+ public function testGraphQlPasswordResetSecurityLimiting (): void
184
+ {
185
+
186
+ $ query = $ this ->getRequestPasswordResetEmailMutation ();
187
+ $ this ->graphQlStateDiff ->testState (
188
+ $ query ,
189
+ ['email ' => $ email ],
190
+ [],
191
+ [],
192
+ 'requestPasswordResetEmail ' ,
193
+ '"data":{"requestPasswordResetEmail": ' ,
194
+ $ this
195
+ );
196
+ $ this ->expectException (SecurityViolationException::class);
197
+ $ objectManager = Bootstrap::getObjectManager ();
198
+ $ accountManagement = $ objectManager ->get (AccountManagementInterface::class);
199
+ $ appState = $ objectManager ->get (State::class);
200
+ $ appState ->setAreaCode (Area::AREA_GRAPHQL );
201
+ $ accountManagement ->initiatePasswordReset ($ email , 'reset_password_template ' );
202
+ }
203
+
158
204
/**
159
205
* @magentoDataFixture Magento/Customer/_files/customer.php
160
206
* @return void
0 commit comments