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

Commit 6f25663

Browse files
committed
Merge branch 'hotfix/13'
Close #13 Fixes #12
2 parents ce7620e + 87f0083 commit 6f25663

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
@@ -2,6 +2,31 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5+
## 0.2.1 - TBD
6+
7+
### Added
8+
9+
- Nothing.
10+
11+
### Changed
12+
13+
- Nothing
14+
15+
### Deprecated
16+
17+
- Nothing.
18+
19+
### Removed
20+
21+
- Nothing.
22+
23+
### Fixed
24+
25+
- [#13](https://github.com/zendframework/zend-expressive-authentication/pull/13)
26+
fixes an issue whereby fetching a record by an unknown username resulted in a
27+
"Trying to get property of non-object" error when using the `PdoDatabase` user
28+
repository implementation.
29+
530
## 0.2.0 - 2017-11-27
631

732
### Added

src/UserRepository/PdoDatabase.php

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

5050
$stmt = $this->pdo->prepare($sql);
5151
$stmt->bindParam(':username', $credential);
52+
$stmt->execute();
5253

53-
if (! $stmt->execute()) {
54+
$result = $stmt->fetchObject();
55+
if (! $result) {
5456
return null;
5557
}
5658

57-
$result = $stmt->fetchObject();
58-
5959
return password_verify($password, $result->{$this->config['field']['password']})
6060
? $this->generateUser($credential, $this->getRolesFromUser($credential))
6161
: null;

test/UserRepository/PdoDatabaseTest.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testAuthenticate()
2727
'table' => 'user',
2828
'field' => [
2929
'username' => 'username',
30-
'password' => 'password'
30+
'password' => 'password',
3131
]
3232
]);
3333

@@ -36,29 +36,44 @@ public function testAuthenticate()
3636
$this->assertEquals('test', $user->getUsername());
3737
}
3838

39-
public function testAuthenticateInvalidUser()
39+
public function testAuthenticateInvalidUserPassword()
4040
{
4141
$pdo = new PDO('sqlite:'. __DIR__ . '/../TestAssets/pdo.sqlite');
4242
$pdoDatabase = new PdoDatabase($pdo, [
4343
'table' => 'user',
4444
'field' => [
4545
'username' => 'username',
46-
'password' => 'password'
46+
'password' => 'password',
4747
]
4848
]);
4949

5050
$user = $pdoDatabase->authenticate('test', 'foo');
5151
$this->assertNull($user);
5252
}
5353

54+
public function testAuthenticateInvalidUsername()
55+
{
56+
$pdo = new PDO('sqlite:'. __DIR__ . '/../TestAssets/pdo.sqlite');
57+
$pdoDatabase = new PdoDatabase($pdo, [
58+
'table' => 'user',
59+
'field' => [
60+
'username' => 'username',
61+
'password' => 'password',
62+
]
63+
]);
64+
65+
$user = $pdoDatabase->authenticate('invalidusername', 'password');
66+
$this->assertNull($user);
67+
}
68+
5469
public function testAuthenticateWithRole()
5570
{
5671
$pdo = new PDO('sqlite:'. __DIR__ . '/../TestAssets/pdo_role.sqlite');
5772
$pdoDatabase = new PdoDatabase($pdo, [
5873
'table' => 'user',
5974
'field' => [
6075
'username' => 'username',
61-
'password' => 'password'
76+
'password' => 'password',
6277
],
6378
'sql_get_roles' => 'SELECT role FROM user WHERE username = :username'
6479
]);
@@ -76,7 +91,7 @@ public function testAuthenticateWithRoles()
7691
'table' => 'user',
7792
'field' => [
7893
'username' => 'username',
79-
'password' => 'password'
94+
'password' => 'password',
8095
],
8196
'sql_get_roles' => 'SELECT role FROM user_role WHERE username = :username'
8297
]);

0 commit comments

Comments
 (0)