Skip to content

Commit 9fe820a

Browse files
akaashakaash
authored andcommitted
ACQE-5000 | Disable limit of reset requests (for Customers)
1 parent 5676386 commit 9fe820a

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

dev/tests/integration/testsuite/Magento/Customer/Controller/ForgotPasswordPostTest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Magento\TestFramework\Helper\Bootstrap;
1414
use Magento\TestFramework\Mail\Template\TransportBuilderMock;
1515
use Magento\TestFramework\TestCase\AbstractController;
16+
use Magento\Customer\Api\CustomerRepositoryInterface;
17+
use Magento\Framework\Api\SearchCriteriaBuilder;
1618

1719
/**
1820
* Class checks password forgot scenarios
@@ -28,6 +30,16 @@ class ForgotPasswordPostTest extends AbstractController
2830
/** @var TransportBuilderMock */
2931
private $transportBuilderMock;
3032

33+
/**
34+
* @var CustomerRepositoryInterface
35+
*/
36+
private $customerRepository;
37+
38+
/**
39+
* @var SearchCriteriaBuilder
40+
*/
41+
private $searchCriteriaBuilder;
42+
3143
/**
3244
* @inheritdoc
3345
*/
@@ -37,6 +49,8 @@ protected function setUp(): void
3749

3850
$this->objectManager = Bootstrap::getObjectManager();
3951
$this->transportBuilderMock = $this->objectManager->get(TransportBuilderMock::class);
52+
$this->customerRepository = $this->objectManager->get(CustomerRepositoryInterface::class);
53+
$this->searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class);
4054
}
4155

4256
/**
@@ -134,4 +148,46 @@ private function assertSuccessSessionMessage(string $email): void
134148
);
135149
$this->assertSessionMessages($this->equalTo([$message]), MessageInterface::TYPE_SUCCESS);
136150
}
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+
}
137193
}

0 commit comments

Comments
 (0)