@@ -34,26 +34,11 @@ public function testCustomerChangeValidPassword()
34
34
$ oldCustomerPassword = 'password ' ;
35
35
$ newCustomerPassword = 'anotherPassword1 ' ;
36
36
37
- $ query = <<<QUERY
38
- mutation {
39
- changePassword(
40
- currentPassword: " $ oldCustomerPassword",
41
- newPassword: " $ newCustomerPassword"
42
- ) {
43
- id
44
- email
45
- firstname
46
- lastname
47
- }
48
- }
49
- QUERY ;
37
+ $ query = $ this ->getChangePassQuery ($ oldCustomerPassword , $ newCustomerPassword );
38
+ $ headerMap = $ this ->getCustomerAuthHeaders ($ customerEmail , $ oldCustomerPassword );
50
39
51
- /** @var CustomerTokenServiceInterface $customerTokenService */
52
- $ customerTokenService = $ this ->objectManager ->create (CustomerTokenServiceInterface::class);
53
- $ customerToken = $ customerTokenService ->createCustomerAccessToken ($ customerEmail , $ oldCustomerPassword );
54
- $ headerMap = ['Authorization ' => 'Bearer ' . $ customerToken ];
55
40
$ response = $ this ->graphQlQuery ($ query , [], '' , $ headerMap );
56
- $ this ->assertEquals ($ customerEmail , $ response ['changePassword ' ]['email ' ]);
41
+ $ this ->assertEquals ($ customerEmail , $ response ['changeCustomerPassword ' ]['email ' ]);
57
42
58
43
try {
59
44
// registry contains the old password hash so needs to be reset
@@ -67,22 +52,12 @@ public function testCustomerChangeValidPassword()
67
52
68
53
public function testGuestUserCannotChangePassword ()
69
54
{
70
- $ query = <<<QUERY
71
- mutation {
72
- changePassword(
73
- currentPassword: "currentpassword",
74
- newPassword: "newpassword"
75
- ) {
76
- id
77
- email
78
- firstname
79
- lastname
80
- }
81
- }
82
- QUERY ;
55
+ $ query = $ this ->getChangePassQuery ('currentpassword ' , 'newpassword ' );
83
56
$ this ->expectException (\Exception::class);
84
- $ this ->expectExceptionMessage ('GraphQL response contains errors: Current customer ' . ' ' .
85
- 'does not have access to the resource "customer" ' );
57
+ $ this ->expectExceptionMessage (
58
+ 'GraphQL response contains errors: Current customer ' . ' ' .
59
+ 'does not have access to the resource "customer" '
60
+ );
86
61
$ this ->graphQlQuery ($ query );
87
62
}
88
63
@@ -95,11 +70,44 @@ public function testChangeWeakPassword()
95
70
$ oldCustomerPassword = 'password ' ;
96
71
$ newCustomerPassword = 'weakpass ' ;
97
72
73
+ $ query = $ this ->getChangePassQuery ($ oldCustomerPassword , $ newCustomerPassword );
74
+ $ headerMap = $ this ->getCustomerAuthHeaders ($ customerEmail , $ oldCustomerPassword );
75
+
76
+ $ this ->expectException (\Exception::class);
77
+ $ this ->expectExceptionMessageRegExp ('/Minimum of different classes of characters in password is.*/ ' );
78
+
79
+ $ this ->graphQlQuery ($ query , [], '' , $ headerMap );
80
+ }
81
+
82
+ /**
83
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
84
+ */
85
+ public function testCannotChangeWithIncorrectPassword ()
86
+ {
87
+ $ customerEmail = 'customer@example.com ' ;
88
+ $ oldCustomerPassword = 'password ' ;
89
+ $ newCustomerPassword = 'anotherPassword1 ' ;
90
+ $ incorrectPassword = 'password-incorrect ' ;
91
+
92
+ $ query = $ this ->getChangePassQuery ($ incorrectPassword , $ newCustomerPassword );
93
+
94
+ // acquire authentication with correct password
95
+ $ headerMap = $ this ->getCustomerAuthHeaders ($ customerEmail , $ oldCustomerPassword );
96
+
97
+ $ this ->expectException (\Exception::class);
98
+ $ this ->expectExceptionMessageRegExp ('/The password doesn \'t match this account. Verify the password.*/ ' );
99
+
100
+ // but try to change with incorrect 'old' password
101
+ $ this ->graphQlQuery ($ query , [], '' , $ headerMap );
102
+ }
103
+
104
+ private function getChangePassQuery ($ currentPassword , $ newPassword )
105
+ {
98
106
$ query = <<<QUERY
99
107
mutation {
100
- changePassword (
101
- currentPassword: " $ oldCustomerPassword ",
102
- newPassword: " $ newCustomerPassword "
108
+ changeCustomerPassword (
109
+ currentPassword: " $ currentPassword ",
110
+ newPassword: " $ newPassword "
103
111
) {
104
112
id
105
113
email
@@ -109,15 +117,15 @@ public function testChangeWeakPassword()
109
117
}
110
118
QUERY ;
111
119
120
+ return $ query ;
121
+ }
122
+
123
+ private function getCustomerAuthHeaders ($ customerEmail , $ oldCustomerPassword )
124
+ {
112
125
/** @var CustomerTokenServiceInterface $customerTokenService */
113
126
$ customerTokenService = $ this ->objectManager ->create (CustomerTokenServiceInterface::class);
114
127
$ customerToken = $ customerTokenService ->createCustomerAccessToken ($ customerEmail , $ oldCustomerPassword );
115
- $ headerMap = ['Authorization ' => 'Bearer ' . $ customerToken ];
116
-
117
- $ this ->expectException (\Exception::class);
118
- $ this ->expectExceptionMessageRegExp ('/Minimum of different classes of characters in password is.*/ ' );
119
-
120
- $ this ->graphQlQuery ($ query , [], '' , $ headerMap );
128
+ return ['Authorization ' => 'Bearer ' . $ customerToken ];
121
129
}
122
130
123
131
protected function setUp ()
0 commit comments