Skip to content

Commit

Permalink
better status code: on invalid credentials return 422 instead of 400 …
Browse files Browse the repository at this point in the history
…now.

added tests
  • Loading branch information
Mohammad-Alavi committed Sep 29, 2021
1 parent 2897616 commit 09ef067
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

class LoginFailedException extends Exception
{
protected $code = Response::HTTP_BAD_REQUEST;
protected $code = Response::HTTP_UNPROCESSABLE_ENTITY;
protected $message = 'An Exception happened during the Login Process.';
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function run(array $data, string $languageHeader = null): float|object|in

// If the internal request to the oauth token endpoint was not successful we throw an exception
if (!$response->isSuccessful()) {
throw new LoginFailedException($content['message'], $response->getStatusCode());
throw new LoginFailedException($content['message']);
}

return $content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public function testClientWebAdminProxyLogin(): void
'email' => '[email protected]',
'password' => 'testingpass',
];
$user = $this->getTestingUser($data);
$this->actingAs($user, 'web');
$this->getTestingUser($data);

$response = $this->makeCall($data);

Expand All @@ -40,8 +39,7 @@ public function testClientWebAdminProxyUnconfirmedLogin(): void
'password' => 'testingpass',
'email_verified_at' => null,
];
$user = $this->getTestingUser($data);
$this->actingAs($user, 'web');
$this->getTestingUser($data);

$response = $this->makeCall($data);

Expand All @@ -59,8 +57,7 @@ public function testLoginWithNameAttribute(): void
'password' => 'testingpass',
'name' => 'username',
];
$user = $this->getTestingUser($data);
$this->actingAs($user, 'web');
$this->getTestingUser($data);
$this->setLoginAttributes([
'email' => [],
'name' => [],
Expand Down Expand Up @@ -117,4 +114,16 @@ public function testGivenMultipleLoginAttributeIsSetThenAtLeastOneShouldBeRequir
'name' => 'The name field is required when none of email are present.',
]);
}

public function testGivenWrongCredential_Throw422(): void
{
$data = [
'email' => '[email protected]',
'password' => 'some-unbelievable-password',
];

$response = $this->makeCall($data);

$response->assertStatus(422);
}
}

0 comments on commit 09ef067

Please sign in to comment.