Skip to content

Commit 18ab161

Browse files
authored
ENGCOM-4861: #628 Check if email or password are empty (generateCustomerToken) #636
2 parents 53e8c50 + 7e8ada3 commit 18ab161

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

app/code/Magento/CustomerGraphQl/Model/Resolver/GenerateCustomerToken.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ public function resolve(
4444
array $value = null,
4545
array $args = null
4646
) {
47-
if (!isset($args['email'])) {
47+
if (!isset($args['email']) || empty($args['email'])) {
4848
throw new GraphQlInputException(__('Specify the "email" value.'));
4949
}
5050

51-
if (!isset($args['password'])) {
51+
if (!isset($args['password']) || empty($args['password'])) {
5252
throw new GraphQlInputException(__('Specify the "password" value.'));
5353
}
5454

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GenerateCustomerTokenTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,54 @@ public function testGenerateCustomerTokenWithInvalidCredentials()
6868
'was incorrect or your account is disabled temporarily. Please wait and try again later.');
6969
$this->graphQlMutation($mutation);
7070
}
71+
72+
/**
73+
* Verify customer with empty email
74+
*/
75+
public function testGenerateCustomerTokenWithEmptyEmail()
76+
{
77+
$email = '';
78+
$password = 'bad-password';
79+
80+
$mutation
81+
= <<<MUTATION
82+
mutation {
83+
generateCustomerToken(
84+
email: "{$email}"
85+
password: "{$password}"
86+
) {
87+
token
88+
}
89+
}
90+
MUTATION;
91+
92+
$this->expectException(\Exception::class);
93+
$this->expectExceptionMessage('GraphQL response contains errors: Specify the "email" value.');
94+
$this->graphQlMutation($mutation);
95+
}
96+
97+
/**
98+
* Verify customer with empty password
99+
*/
100+
public function testGenerateCustomerTokenWithEmptyPassword()
101+
{
102+
$email = 'customer@example.com';
103+
$password = '';
104+
105+
$mutation
106+
= <<<MUTATION
107+
mutation {
108+
generateCustomerToken(
109+
email: "{$email}"
110+
password: "{$password}"
111+
) {
112+
token
113+
}
114+
}
115+
MUTATION;
116+
117+
$this->expectException(\Exception::class);
118+
$this->expectExceptionMessage('GraphQL response contains errors: Specify the "password" value.');
119+
$this->graphQlMutation($mutation);
120+
}
71121
}

0 commit comments

Comments
 (0)