Add tests for database user backend caching
Add comment, closeCursor in user DB query Invalidate user in cache after successful creation Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
parent
592c04a9db
commit
aacfef463c
|
@ -234,7 +234,7 @@ class Database extends Backend implements IUserBackend {
|
||||||
/**
|
/**
|
||||||
* Load an user in the cache
|
* Load an user in the cache
|
||||||
* @param string $uid the username
|
* @param string $uid the username
|
||||||
* @return boolean
|
* @return boolean true if user was found, false otherwise
|
||||||
*/
|
*/
|
||||||
private function loadUser($uid) {
|
private function loadUser($uid) {
|
||||||
if (!isset($this->cache[$uid])) {
|
if (!isset($this->cache[$uid])) {
|
||||||
|
@ -254,9 +254,14 @@ class Database extends Backend implements IUserBackend {
|
||||||
|
|
||||||
$this->cache[$uid] = false;
|
$this->cache[$uid] = false;
|
||||||
|
|
||||||
|
// "uid" is primary key, so there can only be a single result
|
||||||
if ($row = $result->fetchRow()) {
|
if ($row = $result->fetchRow()) {
|
||||||
$this->cache[$uid]['uid'] = $row['uid'];
|
$this->cache[$uid]['uid'] = $row['uid'];
|
||||||
$this->cache[$uid]['displayname'] = $row['displayname'];
|
$this->cache[$uid]['displayname'] = $row['displayname'];
|
||||||
|
$result->closeCursor();
|
||||||
|
} else {
|
||||||
|
$result->closeCursor();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,4 +96,21 @@ class DatabaseTest extends Backend {
|
||||||
$this->backend->setPassword($user, 'newpass');
|
$this->backend->setPassword($user, 'newpass');
|
||||||
$this->assertSame($user, $this->backend->checkPassword($user, 'newpass'));
|
$this->assertSame($user, $this->backend->checkPassword($user, 'newpass'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCreateUserInvalidatesCache() {
|
||||||
|
$user1 = $this->getUniqueID('test_');
|
||||||
|
$this->assertFalse($this->backend->userExists($user1));
|
||||||
|
$this->backend->createUser($user1, 'pw');
|
||||||
|
$this->assertTrue($this->backend->userExists($user1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeleteUserInvalidatesCache() {
|
||||||
|
$user1 = $this->getUniqueID('test_');
|
||||||
|
$this->backend->createUser($user1, 'pw');
|
||||||
|
$this->assertTrue($this->backend->userExists($user1));
|
||||||
|
$this->backend->deleteUser($user1);
|
||||||
|
$this->assertFalse($this->backend->userExists($user1));
|
||||||
|
$this->backend->createUser($user1, 'pw2');
|
||||||
|
$this->assertTrue($this->backend->userExists($user1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue