Skip to content

Commit

Permalink
Extend authorization tests with new error message (#80)
Browse files Browse the repository at this point in the history
Tarantool is going to replace an error thrown in case of entering an
invalid password and entering the login of a non-existent user during
authorization. The patch updates authorization tests correspondingly.

Co-authored-by: Eugene Leonovich <gen.work+gh@gmail.com>

Co-authored-by: Eugene Leonovich <gen.work+gh@gmail.com>
  • Loading branch information
drewdzzz and rybakit authored Oct 20, 2022
1 parent a62aad8 commit 6f7bcbe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tests/Integration/ClientMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function testAuthenticationRetryFails() : void
]);

$this->expectException(RequestFailed::class);
$this->expectExceptionMessage("User 'ghost' is not found");
$this->expectExceptionMessageMatches("/(User 'ghost' is not found|User not found or supplied credentials are invalid)/");

$client->ping();
}
Expand Down
9 changes: 4 additions & 5 deletions tests/Integration/Requests/AuthenticateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function provideValidCredentials() : iterable
/**
* @dataProvider provideInvalidCredentials
*/
public function testAuthenticateWithInvalidCredentials(string $errorMessage, int $errorCode, $username, $password) : void
public function testAuthenticateWithInvalidCredentials(string $errorMessagePattern, $username, $password) : void
{
$client = ClientBuilder::createFromEnv()->setOptions([
'username' => $username,
Expand All @@ -61,16 +61,15 @@ public function testAuthenticateWithInvalidCredentials(string $errorMessage, int
$client->ping();
self::fail(sprintf('Client must throw an exception on authenticating "%s" with the password "%s"', $username, $password));
} catch (RequestFailed $e) {
self::assertSame($errorMessage, $e->getMessage());
self::assertSame($errorCode, $e->getCode());
self::assertMatchesRegularExpression($errorMessagePattern, $e->getMessage());
}
}

public function provideInvalidCredentials() : iterable
{
return [
["User 'non_existing_user' is not found", 45, 'non_existing_user', 'password'],
["Incorrect password supplied for user 'guest'", 47, 'guest', 'password'],
["/(User 'non_existing_user' is not found|User not found or supplied credentials are invalid)/", 'non_existing_user', 'password'],
["/(Incorrect password supplied for user 'guest'|User not found or supplied credentials are invalid)/", 'guest', 'password'],
];
}

Expand Down

0 comments on commit 6f7bcbe

Please sign in to comment.