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

Commit d2bda06

Browse files
committed
Merge branch 'hotfix/13' into release-1.0.0
Forward port #13 Conflicts: CHANGELOG.md
2 parents 9660a63 + 87f0083 commit d2bda06

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,31 @@ All notable changes to this project will be documented in this file, in reverse
2626

2727
- Nothing.
2828

29+
## 0.2.1 - TBD
30+
31+
### Added
32+
33+
- Nothing.
34+
35+
### Changed
36+
37+
- Nothing
38+
39+
### Deprecated
40+
41+
- Nothing.
42+
43+
### Removed
44+
45+
- Nothing.
46+
47+
### Fixed
48+
49+
- [#13](https://github.com/zendframework/zend-expressive-authentication/pull/13)
50+
fixes an issue whereby fetching a record by an unknown username resulted in a
51+
"Trying to get property of non-object" error when using the `PdoDatabase` user
52+
repository implementation.
53+
2954
## 0.2.0 - 2017-11-27
3055

3156
### Added

src/UserRepository/PdoDatabase.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ public function authenticate(string $credential, string $password = null) : ?Use
5252

5353
$stmt = $this->pdo->prepare($sql);
5454
$stmt->bindParam(':username', $credential);
55+
$stmt->execute();
5556

56-
if (! $stmt->execute()) {
57+
$result = $stmt->fetchObject();
58+
if (! $result) {
5759
return null;
5860
}
5961

60-
$result = $stmt->fetchObject();
61-
6262
return password_verify($password, $result->{$this->config['field']['password']})
6363
? $this->generateUser($credential, $this->getRolesFromUser($credential))
6464
: null;

test/UserRepository/PdoDatabaseTest.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testAuthenticate()
3030
'table' => 'user',
3131
'field' => [
3232
'username' => 'username',
33-
'password' => 'password'
33+
'password' => 'password',
3434
]
3535
]);
3636

@@ -39,29 +39,44 @@ public function testAuthenticate()
3939
$this->assertEquals('test', $user->getUsername());
4040
}
4141

42-
public function testAuthenticateInvalidUser()
42+
public function testAuthenticateInvalidUserPassword()
4343
{
4444
$pdo = new PDO('sqlite:'. __DIR__ . '/../TestAssets/pdo.sqlite');
4545
$pdoDatabase = new PdoDatabase($pdo, [
4646
'table' => 'user',
4747
'field' => [
4848
'username' => 'username',
49-
'password' => 'password'
49+
'password' => 'password',
5050
]
5151
]);
5252

5353
$user = $pdoDatabase->authenticate('test', 'foo');
5454
$this->assertNull($user);
5555
}
5656

57+
public function testAuthenticateInvalidUsername()
58+
{
59+
$pdo = new PDO('sqlite:'. __DIR__ . '/../TestAssets/pdo.sqlite');
60+
$pdoDatabase = new PdoDatabase($pdo, [
61+
'table' => 'user',
62+
'field' => [
63+
'username' => 'username',
64+
'password' => 'password',
65+
]
66+
]);
67+
68+
$user = $pdoDatabase->authenticate('invalidusername', 'password');
69+
$this->assertNull($user);
70+
}
71+
5772
public function testAuthenticateWithRole()
5873
{
5974
$pdo = new PDO('sqlite:'. __DIR__ . '/../TestAssets/pdo_role.sqlite');
6075
$pdoDatabase = new PdoDatabase($pdo, [
6176
'table' => 'user',
6277
'field' => [
6378
'username' => 'username',
64-
'password' => 'password'
79+
'password' => 'password',
6580
],
6681
'sql_get_roles' => 'SELECT role FROM user WHERE username = :username'
6782
]);
@@ -79,7 +94,7 @@ public function testAuthenticateWithRoles()
7994
'table' => 'user',
8095
'field' => [
8196
'username' => 'username',
82-
'password' => 'password'
97+
'password' => 'password',
8398
],
8499
'sql_get_roles' => 'SELECT role FROM user_role WHERE username = :username'
85100
]);

0 commit comments

Comments
 (0)