Skip to content

Commit 9912388

Browse files
committed
Added integration test for checking admin login attempts cleanup
1 parent b8528ae commit 9912388

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
use Magento\User\Model\User;
13+
use Magento\User\Model\UserFactory;
14+
15+
/**
16+
* Class ResetAttemptForBackendObserverTest
17+
*
18+
* Test for checking that the admin login attempts are removed after a successful login
19+
*/
20+
class ResetAttemptForBackendObserverTest 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_backend.php
34+
*/
35+
public function testBackendLoginActionWithInvalidCaptchaReturnsError()
36+
{
37+
$userFactory = $this->objectManager->get(UserFactory::class);
38+
$captchaLogFactory = $this->objectManager->get(LogFactory::class);
39+
$eventManager = $this->objectManager->get(ManagerInterface::class);
40+
41+
/** @var User $user */
42+
$user = $userFactory->create();
43+
$user->setUserName('mageadmin');
44+
45+
$eventManager->dispatch(
46+
'backend_auth_user_login_success',
47+
['user' => $user]
48+
);
49+
50+
/**
51+
* @var CaptchaLog $captchaLog
52+
*/
53+
$captchaLog = $captchaLogFactory->create();
54+
55+
self::assertEquals(0, $captchaLog->countAttemptsByUserLogin('mageadmin'));
56+
}
57+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
use Magento\TestFramework\Helper\Bootstrap;
4+
use Magento\Captcha\Model\ResourceModel\LogFactory;
5+
use Magento\Captcha\Model\ResourceModel\Log;
6+
7+
$objectManager = Bootstrap::getObjectManager();
8+
$logFactory = $objectManager->get(LogFactory::class);
9+
10+
/** @var Log $captchaLog */
11+
$captchaLog = $logFactory->create();
12+
$captchaLog->logAttempt('mageadmin');
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
use Magento\TestFramework\Helper\Bootstrap;
4+
use Magento\Captcha\Model\ResourceModel\LogFactory;
5+
use Magento\Captcha\Model\ResourceModel\Log;
6+
7+
$objectManager = Bootstrap::getObjectManager();
8+
$logFactory = $objectManager->get(LogFactory::class);
9+
10+
/** @var Log $captchaLog */
11+
$captchaLog = $logFactory->create();
12+
$captchaLog->deleteUserAttempts('mageadmin');

0 commit comments

Comments
 (0)