Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'jonsa-bugfix/handle_null_password'
Browse files Browse the repository at this point in the history
  • Loading branch information
ezimuel committed Sep 28, 2018
2 parents 358795c + 7d47fef commit 6545ec1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#37](https://github.com/zendframework/zend-expressive-authentication/pull/37) handles null values when verifying password in `PdoDatabase`

## 1.0.0 - 2018-08-27

Expand Down
2 changes: 1 addition & 1 deletion src/UserRepository/PdoDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function authenticate(string $credential, string $password = null) : ?Use
return null;
}

if (password_verify($password, $result->{$this->config['field']['password']})) {
if (password_verify($password ?? '', $result->{$this->config['field']['password']} ?? '')) {
return ($this->userFactory)(
$credential,
$this->getUserRoles($credential),
Expand Down
32 changes: 32 additions & 0 deletions test/UserRepository/PdoDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace ZendTest\Expressive\Authentication\UserRepository;

use PDO;
use PDOStatement;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Zend\Expressive\Authentication\DefaultUser;
Expand Down Expand Up @@ -222,4 +223,35 @@ public function testAuthenticateWithNoIdentityParam()
$this->expectException(InvalidConfigException::class);
$user = $pdoDatabase->authenticate('test', 'password');
}

public function getVoidPasswords()
{
return [
[ null ],
[ '' ]
];
}

/**
* @dataProvider getVoidPasswords
*/
public function testHandlesNullOrEmptyPassword($password)
{
$stmt = $this->prophesize(PDOStatement::class);
$stmt->bindParam(Argument::any(), Argument::any())->willReturn();
$stmt->execute(Argument::any())->willReturn();
$stmt->fetchObject()->willReturn((object)['password' => $password]);

$pdo = $this->prophesize(PDO::class);
$pdo->prepare(Argument::any())->willReturn($stmt->reveal());

$pdoDatabase = new PdoDatabase(
$pdo->reveal(),
$this->getConfig(),
$this->userFactory
);

$user = $pdoDatabase->authenticate('null', $password);
$this->assertNull($user);
}
}

0 comments on commit 6545ec1

Please sign in to comment.