Skip to content

Commit 3d4243e

Browse files
committed
MAGETWO-57909: Automate MAGETWO-49034 - Password protection for adding new user
- Writing functional test for MAGETWO-49034
1 parent 3a43a25 commit 3d4243e

File tree

2 files changed

+158
-0
lines changed

2 files changed

+158
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Security\Test\TestCase;
8+
9+
10+
use Magento\User\Test\Page\Adminhtml\UserEdit;
11+
use Magento\User\Test\Page\Adminhtml\UserIndex;
12+
use Magento\Mtf\TestCase\Injectable;
13+
use Magento\User\Test\Fixture\User;
14+
use Magento\Backend\Test\Page\AdminAuthLogin;
15+
16+
/**
17+
* Preconditions:
18+
* 1. Create admin user.
19+
* 2. Configure 'Maximum Login Failures to Lockout Account'.
20+
*
21+
* Steps:
22+
* 1. Log in to backend as admin user.
23+
* 2. Navigate to System > User Roles.
24+
* 3. Start to create new User Role.
25+
* 4. Fill in all data according to data set (password is incorrect).
26+
* 5. Perform action 4 specified number of times.
27+
* 6. "You have entered an invalid password for current user." appears after each attempt.
28+
* 7. Perform all assertions.
29+
*
30+
* @ZephyrId MAGETWO-49036
31+
*/
32+
class LockAdminUserWhenCreatingNewUserTest extends Injectable
33+
{
34+
/* tags */
35+
const MVP = 'yes';
36+
/* end tags */
37+
38+
/**
39+
* User grid page
40+
*
41+
* @var UserIndex
42+
*/
43+
protected $userIndexPage;
44+
45+
/**
46+
* User new/edit page
47+
*
48+
* @var UserEdit
49+
*/
50+
protected $userEditPage;
51+
52+
/**
53+
* Configuration setting.
54+
*
55+
* @var string
56+
*/
57+
protected $configData;
58+
59+
/**
60+
* @var AdminAuthLogin page
61+
*/
62+
protected $adminAuthLogin;
63+
64+
/**
65+
* Setup data for test.
66+
* @param UserIndex $userIndex
67+
* @param UserEdit $userEdit
68+
* @param AdminAuthLogin $adminAuthLogin
69+
*/
70+
public function __inject(
71+
UserIndex $userIndex,
72+
UserEdit $userEdit,
73+
AdminAuthLogin $adminAuthLogin
74+
) {
75+
$this->userIndexPage = $userIndex;
76+
$this->userEditPage = $userEdit;
77+
$this->adminAuthLogin = $adminAuthLogin;
78+
}
79+
80+
/**
81+
* Runs Lock admin user when creating new user test.
82+
*
83+
* @param int $attempts
84+
* @param User $customAdmin,
85+
* @param User $user,
86+
* @param string $configData
87+
* @return void
88+
*/
89+
public function test(
90+
$attempts,
91+
User $customAdmin,
92+
User $user,
93+
$configData = null
94+
) {
95+
$this->configData = $configData;
96+
97+
// Preconditions
98+
$this->objectManager->create(
99+
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
100+
['configData' => $this->configData]
101+
)->run();
102+
$customAdmin->persist();
103+
104+
// Steps
105+
$this->adminAuthLogin->open();
106+
$this->adminAuthLogin->getLoginBlock()->fill($customAdmin);
107+
$this->adminAuthLogin->getLoginBlock()->submit();
108+
$this->userIndexPage->open();
109+
$this->userIndexPage->getPageActions()->addNew();
110+
for ($i = 0; $i < $attempts; $i++) {
111+
$this->userEditPage->getUserForm()->fill($user);
112+
sleep(3);
113+
$this->userEditPage->getPageActions()->save();
114+
}
115+
116+
// Reload
117+
$this->adminAuthLogin->open();
118+
$this->adminAuthLogin->getLoginBlock()->fill($customAdmin);
119+
$this->adminAuthLogin->getLoginBlock()->submit();
120+
}
121+
122+
/**
123+
* Clean data after running test.
124+
*
125+
* @return void
126+
*/
127+
public function tearDown()
128+
{
129+
$this->objectManager->create(
130+
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
131+
['configData' => $this->configData, 'rollback' => true]
132+
)->run();
133+
}
134+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/**
4+
* Copyright © 2016 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
9+
<testCase name="Magento\Security\Test\TestCase\LockAdminUserWhenCreatingNewUserTest" summary="Lock admin user after entering incorrect password while creating new User">
10+
<variation name="LockAdminUserWhenCreatingNewUserTestVariation1">
11+
<data name="configData" xsi:type="string">user_lockout_failures</data>
12+
<data name="customAdmin/dataset" xsi:type="string">custom_admin_with_default_role</data>
13+
<data name="user/data/username" xsi:type="string">AdminUser%isolation%</data>
14+
<data name="user/data/firstname" xsi:type="string">FirstName%isolation%</data>
15+
<data name="user/data/lastname" xsi:type="string">LastName%isolation%</data>
16+
<data name="user/data/email" xsi:type="string">email%isolation%@example.com</data>
17+
<data name="user/data/password" xsi:type="string">123123q</data>
18+
<data name="user/data/password_confirmation" xsi:type="string">123123q</data>
19+
<data name="user/data/current_password" xsi:type="string">incorrect password</data>
20+
<data name="attempts" xsi:type="string">4</data>
21+
<constraint name="Magento\Security\Test\Constraint\AssertUserIsLocked" />
22+
</variation>
23+
</testCase>
24+
</config>

0 commit comments

Comments
 (0)