Skip to content

Commit

Permalink
add MFTF tests for logging in and fix timezone issue (#22833: Short-t…
Browse files Browse the repository at this point in the history
…erm admin accounts)
  • Loading branch information
lfolco committed Sep 29, 2019
1 parent d8c8473 commit 0f91a9d
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 6 deletions.
10 changes: 8 additions & 2 deletions app/code/Magento/Security/Model/UserExpiration/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,21 @@ class Validator extends AbstractValidator
/**@var \Magento\Framework\Stdlib\DateTime\TimezoneInterface */
private $timezone;

/**@var \Magento\Framework\Stdlib\DateTime\DateTime */
private $dateTime;

/**
* Validator constructor.
*
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone
* @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime
*/
public function __construct(
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone,
\Magento\Framework\Stdlib\DateTime\DateTime $dateTime
) {
$this->timezone = $timezone;
$this->dateTime = $dateTime;
}

/**
Expand All @@ -45,7 +51,7 @@ public function isValid($value)
$expiresAt = $value;
$label = 'Expiration date';
if (\Zend_Validate::is($expiresAt, 'NotEmpty')) {
$currentTime = $this->timezone->date()->getTimestamp();
$currentTime = $this->dateTime->gmtTimestamp();
$utcExpiresAt = $this->timezone->convertConfigTimeToUtc($expiresAt);
$expiresAt = $this->timezone->date($utcExpiresAt)->getTimestamp();
if ($expiresAt < $currentTime) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<description value="Create new user with invalid expiration date."/>
<testCaseId value="" />
<severity value="CRITICAL"/>
<group value="security_userexpire"/>
<group value="security"/>
</annotations>

<before>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<description value="Create new user with valid expiration date."/>
<testCaseId value="" />
<severity value="CRITICAL"/>
<group value="security_userexpire"/>
<group value="security"/>
</annotations>
<before>
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
Expand All @@ -29,8 +29,6 @@
<actionGroup ref="AdminFillInUserWithExpirationActionGroup" stepKey="fillInNewUserWithValidExpiration">
<argument name="expires_at" value="{$expiresDateTime}"/>
</actionGroup>

<!-- TODO: get proper date format to match above -->
<actionGroup ref="AdminSaveUserSuccessActionGroup" stepKey="saveNewUserWithValidExpirationSuccess" />
</test>
</tests>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">

<test name="AdminLoginAdminUserWithInvalidExpiration">
<annotations>
<features value="Security"/>
<stories value="Try to login as a user with an invalid expiration date."/>
<title value="Try to login as a user with an invalid expiration date"/>
<description value="Try to login as a user with an invalid expiration date."/>
<testCaseId value=""/>
<severity value="CRITICAL"/>
<group value="security"/>
</annotations>

<before>
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
</before>

<actionGroup ref="AdminOpenNewUserPageActionGroup" stepKey="openNewUserPage" />
<generateDate date="+1 minute" format="M d, Y h:i:s" stepKey="expiresDateTime"/>
<actionGroup ref="AdminFillInUserWithExpirationActionGroup" stepKey="fillInNewUserWithValidExpiration">
<argument name="expires_at" value="{$expiresDateTime}"/>
</actionGroup>
<grabValueFrom selector="{{AdminNewUserFormSection.username}}" stepKey="grabUsername"/>
<grabValueFrom selector="{{AdminNewUserFormSection.password}}" stepKey="grabPassword"/>
<actionGroup ref="AdminSaveUserSuccessActionGroup" stepKey="saveNewUserWithValidExpirationSuccess"/>
<actionGroup ref="logout" stepKey="logout"/>
<wait time="60" stepKey="waitForUserToExpire"/>
<actionGroup ref="LoginAdminWithCredentialsActionGroup" stepKey="loginAsNewAdmin">
<argument name="adminUser" value="{$grabUsername}"/>
<argument name="adminPassword" value="{$grabPassword}"/>
</actionGroup>
<actionGroup ref="AssertMessageOnAdminLoginActionGroup" stepKey="checkLoginMessage" />

</test>
</tests>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">

<test name="AdminLoginAdminUserWithValidExpiration">
<annotations>
<features value="Security"/>
<stories value="Login as a user with a valid expiration date."/>
<title value="Login as a user with a valid expiration date"/>
<description value="Login as a user with a valid expiration date."/>
<testCaseId value=""/>
<severity value="CRITICAL"/>
<group value="security"/>
</annotations>

<before>
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
</before>
<after>
<actionGroup ref="logout" stepKey="logout"/>
</after>

<actionGroup ref="AdminOpenNewUserPageActionGroup" stepKey="openNewUserPage" />
<generateDate date="+5 day" format="M d, Y h:i:s" stepKey="expiresDateTime"/>
<actionGroup ref="AdminFillInUserWithExpirationActionGroup" stepKey="fillInNewUserWithValidExpiration">
<argument name="expires_at" value="{$expiresDateTime}"/>
</actionGroup>
<grabValueFrom selector="{{AdminNewUserFormSection.username}}" stepKey="grabUsername"/>
<grabValueFrom selector="{{AdminNewUserFormSection.password}}" stepKey="grabPassword"/>
<actionGroup ref="AdminSaveUserSuccessActionGroup" stepKey="saveNewUserWithValidExpirationSuccess"/>
<actionGroup ref="logout" stepKey="logout"/>
<actionGroup ref="LoginAdminWithCredentialsActionGroup" stepKey="loginAsNewAdmin">
<argument name="adminUser" value="{$grabUsername}"/>
<argument name="adminPassword" value="{$grabPassword}"/>
</actionGroup>
<actionGroup ref="AssertAdminDashboardPageIsVisibleActionGroup" stepKey="seeDashboardPage"/>

</test>
</tests>

0 comments on commit 0f91a9d

Please sign in to comment.