Skip to content

Commit

Permalink
Merge pull request #930 from joaoinacio/EZP-23156_userlogin_empty_pas…
Browse files Browse the repository at this point in the history
…sword

Fix EZP-23156: do not throw InvalidArgument exception on empty password
  • Loading branch information
andrerom committed Oct 20, 2014
2 parents f2f0b3f + 08b93b7 commit a472370
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
46 changes: 46 additions & 0 deletions eZ/Publish/API/Repository/Tests/UserServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,29 @@ public function testLoadUserByCredentialsThrowsNotFoundExceptionForUnknownPasswo
/* END: Use Case */
}

/**
* Test for the loadUserByCredentials() method.
*
* @return void
* @see \eZ\Publish\API\Repository\UserService::loadUserByCredentials()
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadUserByCredentials
*/
public function testLoadUserByCredentialsThrowsNotFoundExceptionForUnknownPasswordEmtpy()
{
$repository = $this->getRepository();

$userService = $repository->getUserService();

/* BEGIN: Use Case */
$this->createUserVersion1();

// This call will fail with a "NotFoundException", because the given
// login/password combination does not exist.
$userService->loadUserByCredentials( 'user', '' );
/* END: Use Case */
}

/**
* Test for the loadUserByCredentials() method.
*
Expand All @@ -1183,6 +1206,29 @@ public function testLoadUserByCredentialsThrowsNotFoundExceptionForUnknownLogin(
/* END: Use Case */
}

/**
* Test for the loadUserByCredentials() method.
*
* @return void
* @see \eZ\Publish\API\Repository\UserService::loadUserByCredentials()
* @expectedException \eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue
* @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadUserByCredentials
*/
public function testLoadUserByCredentialsThrowsInvalidArgumentValueForEmptyLogin()
{
$repository = $this->getRepository();

$userService = $repository->getUserService();

/* BEGIN: Use Case */
$this->createUserVersion1();

// This call will fail with a "InvalidArgumentValue", because the given
// login is empty.
$userService->loadUserByCredentials( '', 'secret' );
/* END: Use Case */
}

/**
* Test for the loadUserByLogin() method.
*
Expand Down
1 change: 1 addition & 0 deletions eZ/Publish/API/Repository/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public function loadAnonymousUser();
*
* @return \eZ\Publish\API\Repository\Values\User\User
*
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentValue if credentials are invalid
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a user with the given credentials was not found
*/
public function loadUserByCredentials( $login, $password );
Expand Down
1 change: 1 addition & 0 deletions eZ/Publish/Core/REST/Client/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ public function loadAnonymousUser()
*
* @return \eZ\Publish\API\Repository\Values\User\User
*
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentValue if credentials are invalid
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a user with the given credentials was not found
*/
public function loadUserByCredentials( $login, $password )
Expand Down
3 changes: 2 additions & 1 deletion eZ/Publish/Core/Repository/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,14 +576,15 @@ public function loadAnonymousUser()
*
* @return \eZ\Publish\API\Repository\Values\User\User
*
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentValue if credentials are invalid
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a user with the given credentials was not found
*/
public function loadUserByCredentials( $login, $password )
{
if ( !is_string( $login ) || empty( $login ) )
throw new InvalidArgumentValue( "login", $login );

if ( !is_string( $password ) || empty( $password ) )
if ( !is_string( $password ) )
throw new InvalidArgumentValue( "password", $password );

// Randomize login time to protect against timing attacks
Expand Down
1 change: 1 addition & 0 deletions eZ/Publish/Core/SignalSlot/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ public function loadAnonymousUser()
*
* @return \eZ\Publish\API\Repository\Values\User\User
*
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentValue if credentials are invalid
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a user with the given credentials was not found
*/
public function loadUserByCredentials( $login, $password )
Expand Down

0 comments on commit a472370

Please sign in to comment.