Skip to content

Commit 8b82a09

Browse files
Adding changes of ACQE-5068
2 parents 8e034a8 + c5e96f5 commit 8b82a09

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

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

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Framework\Exception\NoSuchEntityException;
1919
use Magento\Framework\Intl\DateTimeFactory;
2020
use Magento\Framework\Math\Random;
21+
use Magento\Framework\Exception\LocalizedException;
2122
use Magento\Framework\Message\MessageInterface;
2223
use Magento\Framework\ObjectManagerInterface;
2324
use Magento\Framework\Serialize\Serializer\Json;
@@ -523,4 +524,72 @@ private function clearCookieMessagesList(): void
523524
$jsonSerializer->serialize([])
524525
);
525526
}
527+
528+
/**
529+
* Test to enable password change frequency limit for customer
530+
*
531+
* @magentoDbIsolation disabled
532+
* @magentoConfigFixture current_store customer/password/min_time_between_password_reset_requests 0
533+
* @magentoConfigFixture current_store customer/captcha/enable 0
534+
* @magentoDataFixture Magento/Customer/_files/customer.php
535+
* @return void
536+
* @throws LocalizedException
537+
*/
538+
public function testEnablePasswordChangeFrequencyLimitForCustomer(): void
539+
{
540+
$email = 'customer@example.com';
541+
542+
// Resetting password multiple times
543+
for ($i = 0; $i < 5; $i++) {
544+
$this->getRequest()->setPostValue(['email' => $email]);
545+
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
546+
$this->dispatch('customer/account/forgotPasswordPost');
547+
}
548+
549+
// Asserting mail received after forgot password
550+
$sendMessage = $this->transportBuilderMock->getSentMessage()->getBody()->getParts()[0]->getRawContent();
551+
$this->assertStringContainsString(
552+
'There was recently a request to change the password for your account',
553+
$sendMessage
554+
);
555+
556+
// Updating the limit to greater than 0
557+
$this->resourceConfig->saveConfig(
558+
'customer/password/min_time_between_password_reset_requests',
559+
2,
560+
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
561+
0
562+
);
563+
564+
// Resetting password multiple times
565+
for ($i = 0; $i < 5; $i++) {
566+
$this->clearCookieMessagesList();
567+
$this->getRequest()->setPostValue('email', $email);
568+
$this->dispatch('customer/account/forgotPasswordPost');
569+
}
570+
571+
// Asserting the error message
572+
$this->assertSessionMessages(
573+
$this->equalTo(
574+
['We received too many requests for password resets.'
575+
. ' Please wait and try again later or contact hello@example.com.']
576+
),
577+
MessageInterface::TYPE_ERROR
578+
);
579+
580+
// Wait for 2 minutes before resetting password
581+
sleep(120);
582+
583+
// Clicking on the forgot password link
584+
$this->getRequest()->setPostValue('email', $email);
585+
$this->dispatch('customer/account/forgotPasswordPost');
586+
587+
// Asserting mail received after forgot password
588+
$sendMessage = $this->transportBuilderMock->getSentMessage()->getBody()->getParts()[0]->getRawContent();
589+
$this->assertStringContainsString(
590+
'There was recently a request to change the password for your account',
591+
$sendMessage
592+
);
593+
}
594+
526595
}

0 commit comments

Comments
 (0)