Skip to content

Commit 1d16050

Browse files
MTO-144: [Test] Captcha and lockout for Storefront login page
- Functional test implemented
1 parent 7b5bb1f commit 1d16050

File tree

8 files changed

+437
-0
lines changed

8 files changed

+437
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Captcha\Test\Block\Form;
8+
9+
use Magento\Mtf\Client\Locator;
10+
use Magento\Customer\Test\Block\Form\Login;
11+
use Magento\Mtf\Client\ElementInterface;
12+
13+
/**
14+
* Form for storefront login with captcha.
15+
*/
16+
class LoginWithCaptcha extends Login
17+
{
18+
/**
19+
* Captcha image selector.
20+
*
21+
* @var string
22+
*/
23+
private $captchaImage = '.captcha-img';
24+
25+
/**
26+
* Captcha reload button selector.
27+
*
28+
* @var string
29+
*/
30+
private $captchaReload = '.captcha-reload';
31+
32+
/**
33+
* Get captcha element visibility.
34+
*
35+
* @return bool
36+
*/
37+
public function isVisibleCaptcha()
38+
{
39+
return $this->_rootElement->find($this->captchaImage, Locator::SELECTOR_CSS)->isVisible();
40+
}
41+
42+
/**
43+
* Get captcha reload button element visibility.
44+
*
45+
* @return bool
46+
*/
47+
public function isVisibleCaptchaReloadButton()
48+
{
49+
return $this->_rootElement->find($this->captchaReload, Locator::SELECTOR_CSS)->isVisible();
50+
}
51+
52+
/**
53+
* Get captcha reload button element.
54+
*
55+
* @return ElementInterface
56+
*/
57+
public function getCaptchaReloadButton()
58+
{
59+
return $this->_rootElement->find($this->captchaReload, Locator::SELECTOR_CSS);
60+
}
61+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" ?>
2+
<!--
3+
/**
4+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<mapping strict="1">
9+
<wrapper>login</wrapper>
10+
<fields>
11+
<email>
12+
<selector>[name='login[username]']</selector>
13+
</email>
14+
<password />
15+
<captcha>
16+
<selector>[name='captcha[user_login]']</selector>
17+
</captcha>
18+
</fields>
19+
</mapping>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/**
4+
* Copyright © 2013-2017 Magento, Inc. 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/pages.xsd">
9+
<page name="CustomerAccountLogin" mca="customer/account/login">
10+
<block name="loginBlockWithCaptcha" class="Magento\Captcha\Test\Block\Form\LoginWithCaptcha" locator="#login-form" strategy="css selector"/>
11+
</page>
12+
</config>

dev/tests/functional/tests/app/Magento/Captcha/Test/Repository/ConfigData.xml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,44 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/Magento/Mtf/Repository/etc/repository.xsd">
99
<repository class="Magento\Config\Test\Repository\ConfigData">
10+
<dataset name="captcha_storefront_login">
11+
<field name="customer/captcha/enable" xsi:type="array">
12+
<item name="scope_id" xsi:type="number">0</item>
13+
<item name="label" xsi:type="string">Yes</item>
14+
<item name="value" xsi:type="number">1</item>
15+
</field>
16+
<field name="customer/captcha/forms" xsi:type="array">
17+
<item name="scope_id" xsi:type="number">0</item>
18+
<item name="label" xsi:type="string">Login</item>
19+
<item name="value" xsi:type="string">user_login</item>
20+
</field>
21+
<field name="customer/captcha/mode" xsi:type="array">
22+
<item name="scope_id" xsi:type="number">0</item>
23+
<item name="label" xsi:type="string">Always</item>
24+
<item name="value" xsi:type="string">always</item>
25+
</field>
26+
<field name="customer/captcha/length" xsi:type="array">
27+
<item name="scope" xsi:type="string">admin</item>
28+
<item name="scope_id" xsi:type="number">1</item>
29+
<item name="label" xsi:type="string"/>
30+
<item name="value" xsi:type="number">3</item>
31+
</field>
32+
<field name="customer/captcha/symbols" xsi:type="array">
33+
<item name="scope" xsi:type="string">admin</item>
34+
<item name="scope_id" xsi:type="number">1</item>
35+
<item name="label" xsi:type="string"/>
36+
<item name="value" xsi:type="number">1</item>
37+
</field>
38+
</dataset>
39+
<dataset name="captcha_storefront_login_rollback">
40+
<field name="customer/captcha/enable" xsi:type="array">
41+
<item name="scope" xsi:type="string">default</item>
42+
<item name="scope_id" xsi:type="number">1</item>
43+
<item name="label" xsi:type="string">No</item>
44+
<item name="value" xsi:type="number">0</item>
45+
</field>
46+
</dataset>
47+
1048
<dataset name="captcha_storefront_register">
1149
<field name="customer/captcha/enable" xsi:type="array">
1250
<item name="scope_id" xsi:type="number">0</item>
@@ -82,5 +120,49 @@
82120
<item name="value" xsi:type="number">0</item>
83121
</field>
84122
</dataset>
123+
124+
<dataset name="captcha_storefront_login_failures_number">
125+
<field name="customer/captcha/enable" xsi:type="array">
126+
<item name="scope_id" xsi:type="number">0</item>
127+
<item name="label" xsi:type="string">Yes</item>
128+
<item name="value" xsi:type="number">1</item>
129+
</field>
130+
<field name="customer/captcha/forms" xsi:type="array">
131+
<item name="scope_id" xsi:type="number">0</item>
132+
<item name="label" xsi:type="string">Login</item>
133+
<item name="value" xsi:type="string">user_login</item>
134+
</field>
135+
<field name="customer/captcha/mode" xsi:type="array">
136+
<item name="scope_id" xsi:type="number">0</item>
137+
<item name="label" xsi:type="string">After number of attempts to login</item>
138+
<item name="value" xsi:type="string">after_fail</item>
139+
</field>
140+
<field name="customer/captcha/failed_attempts_login" xsi:type="array">
141+
<item name="scope" xsi:type="string">customer</item>
142+
<item name="scope_id" xsi:type="number">1</item>
143+
<item name="label" xsi:type="string"/>
144+
<item name="value" xsi:type="string">3</item>
145+
</field>
146+
<field name="customer/captcha/length" xsi:type="array">
147+
<item name="scope" xsi:type="string">customer</item>
148+
<item name="scope_id" xsi:type="number">1</item>
149+
<item name="label" xsi:type="string"/>
150+
<item name="value" xsi:type="number">3</item>
151+
</field>
152+
<field name="customer/captcha/symbols" xsi:type="array">
153+
<item name="scope" xsi:type="string">customer</item>
154+
<item name="scope_id" xsi:type="number">1</item>
155+
<item name="label" xsi:type="string"/>
156+
<item name="value" xsi:type="number">1</item>
157+
</field>
158+
</dataset>
159+
<dataset name="captcha_storefront_login_failures_number_rollback">
160+
<field name="customer/captcha/enable" xsi:type="array">
161+
<item name="scope" xsi:type="string">default</item>
162+
<item name="scope_id" xsi:type="number">1</item>
163+
<item name="label" xsi:type="string">No</item>
164+
<item name="value" xsi:type="number">0</item>
165+
</field>
166+
</dataset>
85167
</repository>
86168
</config>
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Captcha\Test\TestCase;
8+
9+
use Magento\Customer\Test\Block\Form\Login;
10+
use Magento\Mtf\TestCase\Injectable;
11+
use Magento\Mtf\TestStep\TestStepFactory;
12+
use Magento\Customer\Test\Fixture\Customer;
13+
use Magento\Customer\Test\Page\CustomerAccountLogin;
14+
use Magento\Mtf\Fixture\FixtureFactory;
15+
use Magento\Customer\Test\Page\Adminhtml\CustomerIndexEdit;
16+
17+
/**
18+
* Preconditions:
19+
* 1. Enable CAPTCHA for customer.
20+
* 2. Set Maximum Login Failures.
21+
* 3. Create customer.
22+
*
23+
* Test Flow:
24+
* 1. Open storefront login form.
25+
* 2. Log in customer with incorrect password 3 or more times.
26+
* 3. Log in customer with captcha and incorrect password 3 or more times.
27+
* 4. Log in customer with captcha and correct password.
28+
* 5. Perform asserts.
29+
*
30+
* @group Captcha
31+
* @ZephyrId MAGETWO-49048
32+
*/
33+
class CaptchaAndLockoutCustomerTest extends Injectable
34+
{
35+
/**
36+
* Step factory.
37+
*
38+
* @var TestStepFactory
39+
*/
40+
private $stepFactory;
41+
42+
/**
43+
* Fixture factory.
44+
*
45+
* @var FixtureFactory
46+
*/
47+
private $fixtureFactory;
48+
49+
/**
50+
* CustomerAccountLogin page.
51+
*
52+
* @var CustomerAccountLogin
53+
*/
54+
private $customerAccountLogin;
55+
56+
/**
57+
* Customer Edit page
58+
*
59+
* @var CustomerIndexEdit
60+
*/
61+
private $customerIndexEdit;
62+
63+
/**
64+
* Configuration setting.
65+
*
66+
* @var string
67+
*/
68+
private $configData;
69+
70+
/**
71+
* Injection data.
72+
*
73+
* @param TestStepFactory $stepFactory
74+
* @param FixtureFactory $fixtureFactory
75+
* @param CustomerAccountLogin $customerAccountLogin
76+
* @param CustomerIndexEdit $customerIndexEdit
77+
* @return void
78+
*/
79+
public function __inject(
80+
TestStepFactory $stepFactory,
81+
FixtureFactory $fixtureFactory,
82+
CustomerAccountLogin $customerAccountLogin,
83+
CustomerIndexEdit $customerIndexEdit
84+
) {
85+
$this->stepFactory = $stepFactory;
86+
$this->fixtureFactory = $fixtureFactory;
87+
$this->customerAccountLogin = $customerAccountLogin;
88+
$this->customerIndexEdit = $customerIndexEdit;
89+
}
90+
91+
/**
92+
* Test creation for customer login with captcha on storefront.
93+
*
94+
* @param Customer $customer
95+
* @param string $configData
96+
* @param string $captcha
97+
* @param string $incorrectPassword
98+
* @param int $attempts
99+
* @return void
100+
*/
101+
public function test(
102+
Customer $customer,
103+
$configData,
104+
$captcha,
105+
$incorrectPassword,
106+
$attempts
107+
) {
108+
$this->configData = $configData;
109+
110+
// Preconditions
111+
$this->stepFactory->create(
112+
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
113+
['configData' => $this->configData]
114+
)->run();
115+
$customer->persist();
116+
117+
$correctData = $customer->getData();
118+
$correctData['captcha'] = $captcha;
119+
$correctData['group_id'] = [
120+
'customerGroup' => $customer->getDataFieldConfig('group_id')['source']->getCustomerGroup()
121+
];
122+
$incorrectData = $correctData;
123+
$incorrectData['password'] = $incorrectPassword;
124+
125+
$customer = $this->fixtureFactory->createByCode('customer', ['data' => $incorrectData]);
126+
127+
// Steps
128+
$this->customerAccountLogin->open();
129+
130+
// Fill incorrect password 3 or more times.
131+
$this->customerLogin($customer, $this->customerAccountLogin->getLoginBlock(), $attempts);
132+
133+
// Fill correct captcha and incorrect password 3 or more times.
134+
$this->customerLogin($customer, $this->customerAccountLogin->getLoginBlockWithCaptcha(), $attempts);
135+
136+
// Log in customer with correct captcha and correct password.
137+
$customer = $this->fixtureFactory->createByCode('customer', ['data' => $correctData]);
138+
$this->customerLogin($customer, $this->customerAccountLogin->getLoginBlockWithCaptcha(), 1);
139+
}
140+
141+
/**
142+
* Set default configuration.
143+
*
144+
* @return void
145+
*/
146+
public function tearDown()
147+
{
148+
$this->stepFactory->create(
149+
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
150+
['configData' => $this->configData, 'rollback' => true]
151+
)->run();
152+
}
153+
154+
/**
155+
* Log in customer $attempts times.
156+
*
157+
* @param Customer $customer
158+
* @param Login $loginForm
159+
* @param int $attempts
160+
* @return void
161+
*/
162+
private function customerLogin(Customer $customer, Login $loginForm, $attempts)
163+
{
164+
for ($i = 0; $i < $attempts; $i++) {
165+
$loginForm->fill($customer);
166+
$loginForm->submit();
167+
}
168+
}
169+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/**
4+
* Copyright © 2013-2017 Magento, Inc. 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\Captcha\Test\TestCase\CaptchaAndLockoutCustomerTest" summary="Captcha and Lockout for Storefront Login Page" ticketId="MAGETWO-49048">
10+
<variation name="CaptchaAndLockoutCustomerTestVariation1">
11+
<data name="customer/dataset" xsi:type="string">default</data>
12+
<data name="incorrectPassword" xsi:type="string">incorrect password</data>
13+
<data name="attempts" xsi:type="number">3</data>
14+
<data name="captcha" xsi:type="string">111</data>
15+
<data name="configData" xsi:type="string">captcha_storefront_login_failures_number, customer_max_login_failures_number</data>
16+
<constraint name="Magento\Customer\Test\Constraint\AssertCustomerIsLockedOnBackend"/>
17+
</variation>
18+
</testCase>
19+
</config>

0 commit comments

Comments
 (0)