Skip to content

Commit b80000a

Browse files
Merge branch 'MTO-143' into 'PR-5'
Mto 143 See merge request !219
2 parents e83a7bf + 7f8eb6e commit b80000a

File tree

5 files changed

+245
-9
lines changed

5 files changed

+245
-9
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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="0">
9+
<fields>
10+
<captcha>
11+
<selector>[name='captcha[user_edit]']</selector>
12+
</captcha>
13+
</fields>
14+
</mapping>

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,50 @@
165165
</field>
166166
</dataset>
167167

168+
<dataset name="captcha_storefront_user_edit_failures_number">
169+
<field name="customer/captcha/enable" xsi:type="array">
170+
<item name="scope_id" xsi:type="number">0</item>
171+
<item name="label" xsi:type="string">Yes</item>
172+
<item name="value" xsi:type="number">1</item>
173+
</field>
174+
<field name="customer/captcha/forms" xsi:type="array">
175+
<item name="scope_id" xsi:type="number">0</item>
176+
<item name="label" xsi:type="string">Change password</item>
177+
<item name="value" xsi:type="string">user_edit</item>
178+
</field>
179+
<field name="customer/captcha/mode" xsi:type="array">
180+
<item name="scope_id" xsi:type="number">0</item>
181+
<item name="label" xsi:type="string">After number of attempts to login</item>
182+
<item name="value" xsi:type="string">after_fail</item>
183+
</field>
184+
<field name="customer/captcha/failed_attempts_login" xsi:type="array">
185+
<item name="scope" xsi:type="string">customer</item>
186+
<item name="scope_id" xsi:type="number">1</item>
187+
<item name="label" xsi:type="string"/>
188+
<item name="value" xsi:type="string">3</item>
189+
</field>
190+
<field name="customer/captcha/length" xsi:type="array">
191+
<item name="scope" xsi:type="string">customer</item>
192+
<item name="scope_id" xsi:type="number">1</item>
193+
<item name="label" xsi:type="string"/>
194+
<item name="value" xsi:type="number">3</item>
195+
</field>
196+
<field name="customer/captcha/symbols" xsi:type="array">
197+
<item name="scope" xsi:type="string">customer</item>
198+
<item name="scope_id" xsi:type="number">1</item>
199+
<item name="label" xsi:type="string"/>
200+
<item name="value" xsi:type="number">1</item>
201+
</field>
202+
</dataset>
203+
<dataset name="captcha_storefront_user_edit_failures_number_rollback">
204+
<field name="customer/captcha/enable" xsi:type="array">
205+
<item name="scope" xsi:type="string">default</item>
206+
<item name="scope_id" xsi:type="number">1</item>
207+
<item name="label" xsi:type="string">No</item>
208+
<item name="value" xsi:type="number">0</item>
209+
</field>
210+
</dataset>
211+
168212
<dataset name="captcha_backend_login">
169213
<field name="admin/captcha/enable" xsi:type="array">
170214
<item name="scope_id" xsi:type="number">0</item>
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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\Mtf\TestCase\Injectable;
10+
use Magento\Mtf\TestStep\TestStepFactory;
11+
use Magento\Customer\Test\Fixture\Customer;
12+
use Magento\Mtf\Fixture\FixtureFactory;
13+
use Magento\Customer\Test\Page\CustomerAccountEdit;
14+
15+
/**
16+
* Check captcha and lockout customer on the account edit page.
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. Log in to Store Front.
25+
* 2. Open customer account edit page.
26+
* 2. Update email with incorrect password 3 or more times.
27+
* 3. Update email with incorrect password and captcha(111) 3 or more times.
28+
* 5. Perform asserts.
29+
*
30+
* @group Captcha
31+
* @ZephyrId MAGETWO-49049
32+
*/
33+
class CaptchaEditCustomerTest 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+
* Customer Edit page.
51+
*
52+
* @var CustomerAccountEdit
53+
*/
54+
private $customerAccountEdit;
55+
56+
/**
57+
* Configuration setting.
58+
*
59+
* @var string
60+
*/
61+
private $configData;
62+
63+
/**
64+
* Injection data.
65+
*
66+
* @param TestStepFactory $stepFactory
67+
* @param FixtureFactory $fixtureFactory
68+
* @param CustomerAccountEdit $customerAccountEdit
69+
* @return void
70+
*/
71+
public function __inject(
72+
TestStepFactory $stepFactory,
73+
FixtureFactory $fixtureFactory,
74+
CustomerAccountEdit $customerAccountEdit
75+
) {
76+
$this->stepFactory = $stepFactory;
77+
$this->fixtureFactory = $fixtureFactory;
78+
$this->customerAccountEdit = $customerAccountEdit;
79+
}
80+
81+
/**
82+
* Test for checking captcha on the customer account edit page and customer is locked.
83+
*
84+
* @param Customer $customer
85+
* @param Customer $initCustomer
86+
* @param string $configData
87+
* @param string $captcha
88+
* @param int $attempts
89+
* @return void
90+
*/
91+
public function test(
92+
Customer $customer,
93+
Customer $initCustomer,
94+
$configData,
95+
$captcha,
96+
$attempts
97+
) {
98+
$this->configData = $configData;
99+
100+
// Preconditions
101+
$customer->persist();
102+
$this->stepFactory->create(
103+
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
104+
['configData' => $this->configData]
105+
)->run();
106+
$this->stepFactory->create(
107+
\Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep::class,
108+
['customer' => $customer]
109+
)->run();
110+
111+
// Steps
112+
$this->customerAccountEdit->getAccountMenuBlock()->openMenuItem('Account Information');
113+
114+
// Update email with incorrect password $attempts times.
115+
$this->customerEdit($initCustomer, $attempts);
116+
117+
// Update email with incorrect password and captcha $attempts + 1 times.
118+
$data = $initCustomer->getData();
119+
$data['captcha'] = $captcha;
120+
$data['group_id'] = [];
121+
122+
$initCustomer = $this->fixtureFactory->createByCode('customer', ['data' => $data]);
123+
$this->customerEdit($initCustomer, $attempts + 1);
124+
}
125+
126+
/**
127+
* Update email with incorrect password $attempts times.
128+
*
129+
* @param Customer $customer
130+
* @param int $attempts
131+
* @return void
132+
*/
133+
private function customerEdit(Customer $customer, $attempts)
134+
{
135+
$accountInfoForm = $this->customerAccountEdit->getAccountInfoForm();
136+
for ($i = 0; $i < $attempts; $i++) {
137+
$accountInfoForm->setChangeEmail(true);
138+
$accountInfoForm->fill($customer);
139+
$accountInfoForm->submit();
140+
}
141+
}
142+
143+
/**
144+
* Set default configuration.
145+
*
146+
* @return void
147+
*/
148+
public function tearDown()
149+
{
150+
$this->stepFactory->create(
151+
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
152+
['configData' => $this->configData, 'rollback' => true]
153+
)->run();
154+
}
155+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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\CaptchaEditCustomerTest" summary="Captcha and Lockout on account edit page" ticketId="MAGETWO-49049">
10+
<variation name="CaptchaEditCustomerTestVariation1">
11+
<data name="customer/dataset" xsi:type="string">default</data>
12+
<data name="initCustomer/data/email" xsi:type="string">JaneDoe_%isolation%@example.com</data>
13+
<data name="initCustomer/data/current_password" xsi:type="string">incorrect password</data>
14+
<data name="attempts" xsi:type="number">3</data>
15+
<data name="captcha" xsi:type="string">111</data>
16+
<data name="configData" xsi:type="string">captcha_storefront_user_edit_failures_number, customer_max_login_failures_number</data>
17+
<constraint name="Magento\Security\Test\Constraint\AssertCustomerIsLocked" />
18+
<constraint name="Magento\Customer\Test\Constraint\AssertCustomerIsLockedOnBackend" />
19+
</variation>
20+
</testCase>
21+
</config>

dev/tests/functional/tests/app/Magento/Customer/Test/Block/Form/CustomerForm.xml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@
66
*/
77
-->
88
<mapping strict="0">
9-
<fields>
9+
<fields>
10+
<customer composite="1">
1011
<firstname />
1112
<lastname />
12-
<change_email>
13-
<input>checkbox</input>
14-
</change_email>
15-
<change_password>
16-
<input>checkbox</input>
17-
</change_password>
1813
<email />
1914
<current_password />
2015
<password />
21-
<confirmation />
22-
</fields>
16+
</customer>
17+
<change_password>
18+
<input>checkbox</input>
19+
</change_password>
20+
<change_email>
21+
<input>checkbox</input>
22+
</change_email>
23+
<confirmation />
24+
</fields>
2325
</mapping>

0 commit comments

Comments
 (0)