Skip to content

Commit aac0d40

Browse files
Merge branch 'MTO-144' into pr3
2 parents 8fd754d + d85b27d commit aac0d40

File tree

8 files changed

+429
-0
lines changed

8 files changed

+429
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
}
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: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
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\Fixture\FixtureInterface;
11+
use Magento\Mtf\TestCase\Injectable;
12+
use Magento\Mtf\TestStep\TestStepFactory;
13+
use Magento\Customer\Test\Fixture\Customer;
14+
use Magento\Customer\Test\Page\CustomerAccountLogin;
15+
use Magento\Mtf\Fixture\FixtureFactory;
16+
use Magento\Customer\Test\Page\Adminhtml\CustomerIndexEdit;
17+
18+
/**
19+
* Preconditions:
20+
* 1. Enable CAPTCHA for customer.
21+
* 2. Set Maximum Login Failures.
22+
* 3. Create customer.
23+
*
24+
* Test Flow:
25+
* 1. Open storefront login form.
26+
* 2. Log in customer with incorrect password 3 or more times.
27+
* 3. Log in customer with captcha and incorrect password 3 or more times.
28+
* 4. Log in customer with captcha and correct password.
29+
* 5. Perform asserts.
30+
*
31+
* @group Captcha
32+
* @ZephyrId MAGETWO-49048
33+
*/
34+
class CaptchaAndLockoutCustomerTest extends Injectable
35+
{
36+
/**
37+
* Step factory.
38+
*
39+
* @var TestStepFactory
40+
*/
41+
private $stepFactory;
42+
43+
/**
44+
* Fixture factory.
45+
*
46+
* @var FixtureFactory
47+
*/
48+
private $fixtureFactory;
49+
50+
/**
51+
* CustomerAccountLogin page.
52+
*
53+
* @var CustomerAccountLogin
54+
*/
55+
private $customerAccountLogin;
56+
57+
/**
58+
* CustomerIndexEdit page.
59+
*
60+
* @var CustomerIndexEdit
61+
*/
62+
private $customerIndexEdit;
63+
64+
/**
65+
* Configuration setting.
66+
*
67+
* @var string
68+
*/
69+
private $configData;
70+
71+
/**
72+
* Injection data.
73+
*
74+
* @param TestStepFactory $stepFactory
75+
* @param FixtureFactory $fixtureFactory
76+
* @param CustomerAccountLogin $customerAccountLogin
77+
* @param CustomerIndexEdit $customerIndexEdit
78+
* @return void
79+
*/
80+
public function __inject(
81+
TestStepFactory $stepFactory,
82+
FixtureFactory $fixtureFactory,
83+
CustomerAccountLogin $customerAccountLogin,
84+
CustomerIndexEdit $customerIndexEdit
85+
) {
86+
$this->stepFactory = $stepFactory;
87+
$this->fixtureFactory = $fixtureFactory;
88+
$this->customerAccountLogin = $customerAccountLogin;
89+
$this->customerIndexEdit = $customerIndexEdit;
90+
}
91+
92+
/**
93+
* Test creation for customer login with captcha on storefront.
94+
*
95+
* @param Customer $customer
96+
* @param string $configData
97+
* @param string $captcha
98+
* @param string $incorrectPassword
99+
* @param int $attempts
100+
* @return void
101+
*/
102+
public function test(
103+
Customer $customer,
104+
$configData,
105+
$captcha,
106+
$incorrectPassword,
107+
$attempts
108+
) {
109+
$this->configData = $configData;
110+
111+
// Preconditions
112+
$this->stepFactory->create(
113+
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
114+
['configData' => $this->configData]
115+
)->run();
116+
$customer->persist();
117+
118+
$correctData = $customer->getData();
119+
$correctData['captcha'] = $captcha;
120+
$correctData['group_id'] = [
121+
'customerGroup' => $customer->getDataFieldConfig('group_id')['source']->getCustomerGroup()
122+
];
123+
124+
$newData = $customer->getData();
125+
$newData['captcha'] = $captcha;
126+
$newData['group_id'] = [
127+
'customerGroup' => $customer->getDataFieldConfig('group_id')['source']->getCustomerGroup()
128+
];
129+
$newData['password'] = $incorrectPassword;
130+
131+
$incorrectCustomer = $this->fixtureFactory->createByCode('customer', ['data' => $newData]);
132+
133+
// Steps
134+
$this->customerAccountLogin->open();
135+
136+
// Fill incorrect password $attempts times.
137+
$this->customerLogin($incorrectCustomer, $this->customerAccountLogin->getLoginBlock(), $attempts);
138+
139+
// Fill correct captcha and incorrect password $attempts times.
140+
$this->customerLogin($incorrectCustomer, $this->customerAccountLogin->getLoginBlockWithCaptcha(), $attempts);
141+
142+
// Log in customer with correct captcha and correct password.
143+
$customer = $this->fixtureFactory->createByCode('customer', ['data' => $correctData]);
144+
$this->customerLogin($customer, $this->customerAccountLogin->getLoginBlockWithCaptcha(), 1);
145+
}
146+
147+
/**
148+
* Log in customer $attempts times.
149+
*
150+
* @param FixtureInterface $customer
151+
* @param Login $loginForm
152+
* @param int $attempts
153+
* @return void
154+
*/
155+
private function customerLogin(FixtureInterface $customer, Login $loginForm, $attempts)
156+
{
157+
for ($i = 0; $i < $attempts; $i++) {
158+
$loginForm->fill($customer);
159+
$loginForm->submit();
160+
}
161+
}
162+
163+
/**
164+
* Set default configuration.
165+
*
166+
* @return void
167+
*/
168+
public function tearDown()
169+
{
170+
$this->stepFactory->create(
171+
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
172+
['configData' => $this->configData, 'rollback' => true]
173+
)->run();
174+
}
175+
}
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)