Skip to content

Commit 74e60e3

Browse files
ENGCOM-2142: [Backport 2.1] Captcha: Added integration tests for checking customer login attempts cleanup #16403
- Merge Pull Request #16403 from rogyar/magento2:2.1-captcha-reset-frontend-it - Merged commits: 1. a83ec42
2 parents c20946e + a83ec42 commit 74e60e3

File tree

4 files changed

+141
-0
lines changed

4 files changed

+141
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Captcha\Observer;
7+
8+
use Magento\Captcha\Model\ResourceModel\Log as CaptchaLog;
9+
use Magento\Captcha\Model\ResourceModel\LogFactory;
10+
use Magento\Framework\Event\ManagerInterface;
11+
use Magento\Framework\ObjectManagerInterface;
12+
13+
/**
14+
* Class ResetAttemptForFrontendAccountEditObserverTest
15+
*
16+
* Test for checking that the customer login attempts are removed after account details edit
17+
*/
18+
class ResetAttemptForFrontendAccountEditObserverTest extends \PHPUnit_Framework_TestCase
19+
{
20+
/**
21+
* @var ObjectManagerInterface
22+
*/
23+
private $objectManager;
24+
25+
public function setUp()
26+
{
27+
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
28+
}
29+
30+
/**
31+
* @magentoDataFixture Magento/Captcha/_files/failed_logins_frontend.php
32+
*/
33+
public function testAccountEditRemovesFailedAttempts()
34+
{
35+
$customerEmail = 'mageuser@dummy.com';
36+
$captchaLogFactory = $this->objectManager->get(LogFactory::class);
37+
$eventManager = $this->objectManager->get(ManagerInterface::class);
38+
39+
$eventManager->dispatch(
40+
'customer_account_edited',
41+
['email' => $customerEmail]
42+
);
43+
44+
/**
45+
* @var CaptchaLog $captchaLog
46+
*/
47+
$captchaLog = $captchaLogFactory->create();
48+
49+
self::assertEquals(0, $captchaLog->countAttemptsByUserLogin($customerEmail));
50+
}
51+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Captcha\Observer;
7+
8+
use Magento\Captcha\Model\ResourceModel\Log as CaptchaLog;
9+
use Magento\Captcha\Model\ResourceModel\LogFactory;
10+
use Magento\Customer\Model\Customer;
11+
use Magento\Customer\Model\CustomerFactory;
12+
use Magento\Framework\Event\ManagerInterface;
13+
use Magento\Framework\ObjectManagerInterface;
14+
15+
/**
16+
* Class ResetAttemptForFrontendObserverTest
17+
*
18+
* Test for checking that the customer login attempts are removed after a successful login
19+
*/
20+
class ResetAttemptForFrontendObserverTest extends \PHPUnit_Framework_TestCase
21+
{
22+
/**
23+
* @var ObjectManagerInterface
24+
*/
25+
private $objectManager;
26+
27+
public function setUp()
28+
{
29+
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
30+
}
31+
32+
/**
33+
* @magentoDataFixture Magento/Captcha/_files/failed_logins_frontend.php
34+
*/
35+
public function testSuccesfulLoginRemovesFailedAttempts()
36+
{
37+
$customerEmail = 'mageuser@dummy.com';
38+
$customerFactory = $this->objectManager->get(CustomerFactory::class);
39+
$captchaLogFactory = $this->objectManager->get(LogFactory::class);
40+
$eventManager = $this->objectManager->get(ManagerInterface::class);
41+
42+
/** @var Customer $customer */
43+
$customer = $customerFactory->create();
44+
$customer->setEmail($customerEmail);
45+
46+
$eventManager->dispatch(
47+
'customer_customer_authenticated',
48+
['model' => $customer, 'password' => 'some_password']
49+
);
50+
51+
/**
52+
* @var CaptchaLog $captchaLog
53+
*/
54+
$captchaLog = $captchaLogFactory->create();
55+
56+
self::assertEquals(0, $captchaLog->countAttemptsByUserLogin($customerEmail));
57+
}
58+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\TestFramework\Helper\Bootstrap;
8+
use Magento\Captcha\Model\ResourceModel\LogFactory;
9+
use Magento\Captcha\Model\ResourceModel\Log;
10+
11+
$objectManager = Bootstrap::getObjectManager();
12+
$logFactory = $objectManager->get(LogFactory::class);
13+
14+
/** @var Log $captchaLog */
15+
$captchaLog = $logFactory->create();
16+
$captchaLog->logAttempt('mageuser@dummy.com');
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\TestFramework\Helper\Bootstrap;
8+
use Magento\Captcha\Model\ResourceModel\LogFactory;
9+
use Magento\Captcha\Model\ResourceModel\Log;
10+
11+
$objectManager = Bootstrap::getObjectManager();
12+
$logFactory = $objectManager->get(LogFactory::class);
13+
14+
/** @var Log $captchaLog */
15+
$captchaLog = $logFactory->create();
16+
$captchaLog->deleteUserAttempts('mageuser@dummy.com');

0 commit comments

Comments
 (0)