-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENGCOM-2220: [Port 2.3] Captcha: Added integration tests for checking…
… customer login attempts cleanup #16348
- Loading branch information
Showing
4 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...ion/testsuite/Magento/Captcha/Observer/ResetAttemptForFrontendAccountEditObserverTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Captcha\Observer; | ||
|
||
use Magento\Captcha\Model\ResourceModel\Log as CaptchaLog; | ||
use Magento\Captcha\Model\ResourceModel\LogFactory; | ||
use Magento\Framework\Event\ManagerInterface; | ||
use Magento\Framework\ObjectManagerInterface; | ||
|
||
/** | ||
* Class ResetAttemptForFrontendAccountEditObserverTest | ||
* | ||
* Test for checking that the customer login attempts are removed after account details edit | ||
*/ | ||
class ResetAttemptForFrontendAccountEditObserverTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @var ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
public function setUp() | ||
{ | ||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); | ||
} | ||
|
||
/** | ||
* @magentoDataFixture Magento/Captcha/_files/failed_logins_frontend.php | ||
*/ | ||
public function testAccountEditRemovesFailedAttempts() | ||
{ | ||
$customerEmail = 'mageuser@dummy.com'; | ||
$captchaLogFactory = $this->objectManager->get(LogFactory::class); | ||
$eventManager = $this->objectManager->get(ManagerInterface::class); | ||
|
||
$eventManager->dispatch( | ||
'customer_account_edited', | ||
['email' => $customerEmail] | ||
); | ||
|
||
/** | ||
* @var CaptchaLog $captchaLog | ||
*/ | ||
$captchaLog = $captchaLogFactory->create(); | ||
|
||
self::assertEquals(0, $captchaLog->countAttemptsByUserLogin($customerEmail)); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...ts/integration/testsuite/Magento/Captcha/Observer/ResetAttemptForFrontendObserverTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Captcha\Observer; | ||
|
||
use Magento\Captcha\Model\ResourceModel\Log as CaptchaLog; | ||
use Magento\Captcha\Model\ResourceModel\LogFactory; | ||
use Magento\Customer\Model\Customer; | ||
use Magento\Customer\Model\CustomerFactory; | ||
use Magento\Framework\Event\ManagerInterface; | ||
use Magento\Framework\ObjectManagerInterface; | ||
|
||
/** | ||
* Class ResetAttemptForFrontendObserverTest | ||
* | ||
* Test for checking that the customer login attempts are removed after a successful login | ||
*/ | ||
class ResetAttemptForFrontendObserverTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @var ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
public function setUp() | ||
{ | ||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); | ||
} | ||
|
||
/** | ||
* @magentoDataFixture Magento/Captcha/_files/failed_logins_frontend.php | ||
*/ | ||
public function testSuccesfulLoginRemovesFailedAttempts() | ||
{ | ||
$customerEmail = 'mageuser@dummy.com'; | ||
$customerFactory = $this->objectManager->get(CustomerFactory::class); | ||
$captchaLogFactory = $this->objectManager->get(LogFactory::class); | ||
$eventManager = $this->objectManager->get(ManagerInterface::class); | ||
|
||
/** @var Customer $customer */ | ||
$customer = $customerFactory->create(); | ||
$customer->setEmail($customerEmail); | ||
|
||
$eventManager->dispatch( | ||
'customer_customer_authenticated', | ||
['model' => $customer, 'password' => 'some_password'] | ||
); | ||
|
||
/** | ||
* @var CaptchaLog $captchaLog | ||
*/ | ||
$captchaLog = $captchaLogFactory->create(); | ||
|
||
self::assertEquals(0, $captchaLog->countAttemptsByUserLogin($customerEmail)); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
dev/tests/integration/testsuite/Magento/Captcha/_files/failed_logins_frontend.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\Captcha\Model\ResourceModel\LogFactory; | ||
use Magento\Captcha\Model\ResourceModel\Log; | ||
|
||
$objectManager = Bootstrap::getObjectManager(); | ||
$logFactory = $objectManager->get(LogFactory::class); | ||
|
||
/** @var Log $captchaLog */ | ||
$captchaLog = $logFactory->create(); | ||
$captchaLog->logAttempt('mageuser@dummy.com'); |
17 changes: 17 additions & 0 deletions
17
dev/tests/integration/testsuite/Magento/Captcha/_files/failed_logins_frontend_rollback.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\Captcha\Model\ResourceModel\LogFactory; | ||
use Magento\Captcha\Model\ResourceModel\Log; | ||
|
||
$objectManager = Bootstrap::getObjectManager(); | ||
$logFactory = $objectManager->get(LogFactory::class); | ||
|
||
/** @var Log $captchaLog */ | ||
$captchaLog = $logFactory->create(); | ||
$captchaLog->deleteUserAttempts('mageuser@dummy.com'); |