summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/private/User/Database.php7
-rw-r--r--tests/lib/User/DatabaseTest.php19
2 files changed, 24 insertions, 2 deletions
diff --git a/lib/private/User/Database.php b/lib/private/User/Database.php
index efa6672ccee..ec463ba91dd 100644
--- a/lib/private/User/Database.php
+++ b/lib/private/User/Database.php
@@ -234,7 +234,7 @@ class Database extends Backend implements IUserBackend {
/**
* Load an user in the cache
* @param string $uid the username
- * @return boolean
+ * @return boolean true if user was found, false otherwise
*/
private function loadUser($uid) {
if (!isset($this->cache[$uid])) {
@@ -254,9 +254,14 @@ class Database extends Backend implements IUserBackend {
$this->cache[$uid] = false;
+ // "uid" is primary key, so there can only be a single result
if ($row = $result->fetchRow()) {
$this->cache[$uid]['uid'] = $row['uid'];
$this->cache[$uid]['displayname'] = $row['displayname'];
+ $result->closeCursor();
+ } else {
+ $result->closeCursor();
+ return false;
}
}
diff --git a/tests/lib/User/DatabaseTest.php b/tests/lib/User/DatabaseTest.php
index d7e4b9256cb..0e6900651cd 100644
--- a/tests/lib/User/DatabaseTest.php
+++ b/tests/lib/User/DatabaseTest.php
@@ -87,7 +87,7 @@ class DatabaseTest extends Backend {
$this->eventDispatcher->expects($this->once())->method('dispatch')
->willReturnCallback(
function ($eventName, GenericEvent $event) {
- $this->assertSame('OCP\PasswordPolicy::validate', $eventName);
+ $this->assertSame('OCP\PasswordPolicy::validate', $eventName);
$this->assertSame('newpass', $event->getSubject());
throw new HintException('password change failed', 'password change failed');
}
@@ -96,4 +96,21 @@ class DatabaseTest extends Backend {
$this->backend->setPassword($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));
+ }
}