13
13
use Magento \TestFramework \Helper \Bootstrap ;
14
14
use Magento \TestFramework \Mail \Template \TransportBuilderMock ;
15
15
use Magento \TestFramework \TestCase \AbstractController ;
16
+ use Magento \Customer \Api \CustomerRepositoryInterface ;
17
+ use Magento \Framework \Api \SearchCriteriaBuilder ;
16
18
17
19
/**
18
20
* Class checks password forgot scenarios
@@ -28,6 +30,16 @@ class ForgotPasswordPostTest extends AbstractController
28
30
/** @var TransportBuilderMock */
29
31
private $ transportBuilderMock ;
30
32
33
+ /**
34
+ * @var CustomerRepositoryInterface
35
+ */
36
+ private $ customerRepository ;
37
+
38
+ /**
39
+ * @var SearchCriteriaBuilder
40
+ */
41
+ private $ searchCriteriaBuilder ;
42
+
31
43
/**
32
44
* @inheritdoc
33
45
*/
@@ -37,6 +49,8 @@ protected function setUp(): void
37
49
38
50
$ this ->objectManager = Bootstrap::getObjectManager ();
39
51
$ this ->transportBuilderMock = $ this ->objectManager ->get (TransportBuilderMock::class);
52
+ $ this ->customerRepository = $ this ->objectManager ->get (CustomerRepositoryInterface::class);
53
+ $ this ->searchCriteriaBuilder = $ this ->objectManager ->get (SearchCriteriaBuilder::class);
40
54
}
41
55
42
56
/**
@@ -134,4 +148,46 @@ private function assertSuccessSessionMessage(string $email): void
134
148
);
135
149
$ this ->assertSessionMessages ($ this ->equalTo ([$ message ]), MessageInterface::TYPE_SUCCESS );
136
150
}
151
+
152
+ /**
153
+ * @magentoConfigFixture current_store customer/password/password_reset_protection_type 0
154
+ * @magentoConfigFixture current_store customer/captcha/enable 0
155
+ * @magentoDataFixture Magento/Customer/_files/customer.php
156
+ *
157
+ * @return void
158
+ * @throws \Magento\Framework\Exception\LocalizedException
159
+ */
160
+ public function testDisableLimitOfResetRequests (): void
161
+ {
162
+ $ searchCriteria = $ this ->searchCriteriaBuilder ->create ();
163
+ $ searchResults = $ this ->customerRepository ->getList ($ searchCriteria );
164
+
165
+ foreach ($ searchResults ->getItems () as $ customer ) {
166
+ $ customAttributes = $ customer ->getCustomAttributes ();
167
+ $ numberOfRequests = $ customAttributes ['rp_token_lifetime ' ] ?? null ;
168
+
169
+ $ this ->assertNull ($ numberOfRequests );
170
+ }
171
+
172
+ $ email = 'customer@example.com ' ;
173
+ $ this ->getRequest ()->setPostValue (['email ' => $ email ]);
174
+ $ this ->getRequest ()->setMethod (HttpRequest::METHOD_POST );
175
+
176
+ for ($ i = 0 ; $ i < 10 ; $ i ++) {
177
+ $ this ->dispatch ('customer/account/forgotPasswordPost ' );
178
+ $ this ->assertRedirect ($ this ->stringContains ('customer/account/ ' ));
179
+
180
+ $ sendMessage = $ this ->transportBuilderMock ->getSentMessage ()->getBody ()->getParts ()[0 ]->getRawContent ();
181
+
182
+ $ this ->assertStringContainsString (
183
+ 'There was recently a request to change the password for your account ' ,
184
+ $ sendMessage
185
+ );
186
+
187
+ $ this ->assertSessionMessages (
188
+ $ this ->equalTo ([]),
189
+ MessageInterface::TYPE_ERROR
190
+ );
191
+ }
192
+ }
137
193
}
0 commit comments