Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ private function getCredentials(Request $request)
try {
$credentials['username'] = $this->propertyAccessor->getValue($data, $this->options['username_path']);

if (!\is_string($credentials['username'])) {
throw new BadRequestHttpException(sprintf('The key "%s" must be a string.', $this->options['username_path']));
if (!\is_string($credentials['username']) || $credentials['username'] === "") {
throw new BadRequestHttpException(sprintf('The key "%s" must be a non empty string.', $this->options['username_path']));
}

if (\strlen($credentials['username']) > Security::MAX_USERNAME_LENGTH) {
Expand All @@ -184,8 +184,8 @@ private function getCredentials(Request $request)
try {
$credentials['password'] = $this->propertyAccessor->getValue($data, $this->options['password_path']);

if (!\is_string($credentials['password'])) {
throw new BadRequestHttpException(sprintf('The key "%s" must be a string.', $this->options['password_path']));
if (!\is_string($credentials['password']) || $credentials['password'] === "") {
throw new BadRequestHttpException(sprintf('The key "%s" must be a non empty string.', $this->options['password_path']));
}
} catch (AccessException $e) {
throw new BadRequestHttpException(sprintf('The key "%s" must be provided.', $this->options['password_path']), $e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,16 @@ public function provideInvalidAuthenticateData()
yield [$request, 'The key "password" must be provided'];

$request = new Request([], [], [], [], [], ['HTTP_CONTENT_TYPE' => 'application/json'], '{"username": 1, "password": "foo"}');
yield [$request, 'The key "username" must be a string.'];
yield [$request, 'The key "username" must be a non empty string.'];

$request = new Request([], [], [], [], [], ['HTTP_CONTENT_TYPE' => 'application/json'], '{"username": "dunglas", "password": 1}');
yield [$request, 'The key "password" must be a string.'];
yield [$request, 'The key "password" must be a non empty string.'];

$request = new Request([], [], [], [], [], ['HTTP_CONTENT_TYPE' => 'application/json'], '{"username": "", "password": ""}');
yield [$request, 'The key "username" must be a non empty string.'];

$request = new Request([], [], [], [], [], ['HTTP_CONTENT_TYPE' => 'application/json'], '{"username": "rimas", "password": ""}');
yield [$request, 'The key "password" must be a non empty string.'];

$username = str_repeat('x', Security::MAX_USERNAME_LENGTH + 1);
$request = new Request([], [], [], [], [], ['HTTP_CONTENT_TYPE' => 'application/json'], sprintf('{"username": "%s", "password": 1}', $username));
Expand Down