Skip to content

Commit 0f91a9d

Browse files
committed
add MFTF tests for logging in and fix timezone issue (#22833: Short-term admin accounts)
1 parent d8c8473 commit 0f91a9d

5 files changed

+86
-6
lines changed

app/code/Magento/Security/Model/UserExpiration/Validator.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,21 @@ class Validator extends AbstractValidator
2020
/**@var \Magento\Framework\Stdlib\DateTime\TimezoneInterface */
2121
private $timezone;
2222

23+
/**@var \Magento\Framework\Stdlib\DateTime\DateTime */
24+
private $dateTime;
25+
2326
/**
2427
* Validator constructor.
2528
*
2629
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone
30+
* @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime
2731
*/
2832
public function __construct(
29-
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone
33+
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone,
34+
\Magento\Framework\Stdlib\DateTime\DateTime $dateTime
3035
) {
3136
$this->timezone = $timezone;
37+
$this->dateTime = $dateTime;
3238
}
3339

3440
/**
@@ -45,7 +51,7 @@ public function isValid($value)
4551
$expiresAt = $value;
4652
$label = 'Expiration date';
4753
if (\Zend_Validate::is($expiresAt, 'NotEmpty')) {
48-
$currentTime = $this->timezone->date()->getTimestamp();
54+
$currentTime = $this->dateTime->gmtTimestamp();
4955
$utcExpiresAt = $this->timezone->convertConfigTimeToUtc($expiresAt);
5056
$expiresAt = $this->timezone->date($utcExpiresAt)->getTimestamp();
5157
if ($expiresAt < $currentTime) {

app/code/Magento/Security/Test/Mftf/Test/AdminCreateNewUserWithInvalidExpirationTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<description value="Create new user with invalid expiration date."/>
1616
<testCaseId value="" />
1717
<severity value="CRITICAL"/>
18-
<group value="security_userexpire"/>
18+
<group value="security"/>
1919
</annotations>
2020

2121
<before>

app/code/Magento/Security/Test/Mftf/Test/AdminCreateNewUserWithValidExpirationTest.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<description value="Create new user with valid expiration date."/>
1616
<testCaseId value="" />
1717
<severity value="CRITICAL"/>
18-
<group value="security_userexpire"/>
18+
<group value="security"/>
1919
</annotations>
2020
<before>
2121
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
@@ -29,8 +29,6 @@
2929
<actionGroup ref="AdminFillInUserWithExpirationActionGroup" stepKey="fillInNewUserWithValidExpiration">
3030
<argument name="expires_at" value="{$expiresDateTime}"/>
3131
</actionGroup>
32-
33-
<!-- TODO: get proper date format to match above -->
3432
<actionGroup ref="AdminSaveUserSuccessActionGroup" stepKey="saveNewUserWithValidExpirationSuccess" />
3533
</test>
3634
</tests>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
4+
5+
<test name="AdminLoginAdminUserWithInvalidExpiration">
6+
<annotations>
7+
<features value="Security"/>
8+
<stories value="Try to login as a user with an invalid expiration date."/>
9+
<title value="Try to login as a user with an invalid expiration date"/>
10+
<description value="Try to login as a user with an invalid expiration date."/>
11+
<testCaseId value=""/>
12+
<severity value="CRITICAL"/>
13+
<group value="security"/>
14+
</annotations>
15+
16+
<before>
17+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
18+
</before>
19+
20+
<actionGroup ref="AdminOpenNewUserPageActionGroup" stepKey="openNewUserPage" />
21+
<generateDate date="+1 minute" format="M d, Y h:i:s" stepKey="expiresDateTime"/>
22+
<actionGroup ref="AdminFillInUserWithExpirationActionGroup" stepKey="fillInNewUserWithValidExpiration">
23+
<argument name="expires_at" value="{$expiresDateTime}"/>
24+
</actionGroup>
25+
<grabValueFrom selector="{{AdminNewUserFormSection.username}}" stepKey="grabUsername"/>
26+
<grabValueFrom selector="{{AdminNewUserFormSection.password}}" stepKey="grabPassword"/>
27+
<actionGroup ref="AdminSaveUserSuccessActionGroup" stepKey="saveNewUserWithValidExpirationSuccess"/>
28+
<actionGroup ref="logout" stepKey="logout"/>
29+
<wait time="60" stepKey="waitForUserToExpire"/>
30+
<actionGroup ref="LoginAdminWithCredentialsActionGroup" stepKey="loginAsNewAdmin">
31+
<argument name="adminUser" value="{$grabUsername}"/>
32+
<argument name="adminPassword" value="{$grabPassword}"/>
33+
</actionGroup>
34+
<actionGroup ref="AssertMessageOnAdminLoginActionGroup" stepKey="checkLoginMessage" />
35+
36+
</test>
37+
</tests>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
4+
5+
<test name="AdminLoginAdminUserWithValidExpiration">
6+
<annotations>
7+
<features value="Security"/>
8+
<stories value="Login as a user with a valid expiration date."/>
9+
<title value="Login as a user with a valid expiration date"/>
10+
<description value="Login as a user with a valid expiration date."/>
11+
<testCaseId value=""/>
12+
<severity value="CRITICAL"/>
13+
<group value="security"/>
14+
</annotations>
15+
16+
<before>
17+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
18+
</before>
19+
<after>
20+
<actionGroup ref="logout" stepKey="logout"/>
21+
</after>
22+
23+
<actionGroup ref="AdminOpenNewUserPageActionGroup" stepKey="openNewUserPage" />
24+
<generateDate date="+5 day" format="M d, Y h:i:s" stepKey="expiresDateTime"/>
25+
<actionGroup ref="AdminFillInUserWithExpirationActionGroup" stepKey="fillInNewUserWithValidExpiration">
26+
<argument name="expires_at" value="{$expiresDateTime}"/>
27+
</actionGroup>
28+
<grabValueFrom selector="{{AdminNewUserFormSection.username}}" stepKey="grabUsername"/>
29+
<grabValueFrom selector="{{AdminNewUserFormSection.password}}" stepKey="grabPassword"/>
30+
<actionGroup ref="AdminSaveUserSuccessActionGroup" stepKey="saveNewUserWithValidExpirationSuccess"/>
31+
<actionGroup ref="logout" stepKey="logout"/>
32+
<actionGroup ref="LoginAdminWithCredentialsActionGroup" stepKey="loginAsNewAdmin">
33+
<argument name="adminUser" value="{$grabUsername}"/>
34+
<argument name="adminPassword" value="{$grabPassword}"/>
35+
</actionGroup>
36+
<actionGroup ref="AssertAdminDashboardPageIsVisibleActionGroup" stepKey="seeDashboardPage"/>
37+
38+
</test>
39+
</tests>

0 commit comments

Comments
 (0)