Merge pull request #4475 from nextcloud/backport-4473-10

[stable10] Add unit tests for mounts of delete users
This commit is contained in:
Morris Jobke 2017-04-24 13:19:34 -03:00 committed by GitHub
commit d606d3eb0b
2 changed files with 30 additions and 3 deletions

View File

@ -187,6 +187,9 @@ class UserMountCache implements IUserMountCache {
private function dbRowToMountInfo(array $row) {
$user = $this->userManager->get($row['user_id']);
if (is_null($user)) {
return null;
}
return new CachedMountInfo($user, (int)$row['storage_id'], (int)$row['root_id'], $row['mount_point'], $row['mount_id']);
}
@ -203,7 +206,7 @@ class UserMountCache implements IUserMountCache {
$rows = $query->execute()->fetchAll();
$this->mountsForUsers[$user->getUID()] = array_map([$this, 'dbRowToMountInfo'], $rows);
$this->mountsForUsers[$user->getUID()] = array_filter(array_map([$this, 'dbRowToMountInfo'], $rows));
}
return $this->mountsForUsers[$user->getUID()];
}
@ -220,7 +223,7 @@ class UserMountCache implements IUserMountCache {
$rows = $query->execute()->fetchAll();
return array_map([$this, 'dbRowToMountInfo'], $rows);
return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows));
}
/**
@ -235,7 +238,7 @@ class UserMountCache implements IUserMountCache {
$rows = $query->execute()->fetchAll();
return array_map([$this, 'dbRowToMountInfo'], $rows);
return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows));
}
/**

View File

@ -46,6 +46,7 @@ class UserMountCacheTest extends TestCase {
$userBackend = new Dummy();
$userBackend->createUser('u1', '');
$userBackend->createUser('u2', '');
$userBackend->createUser('u3', '');
$this->userManager->registerBackend($userBackend);
$this->cache = new \OC\Files\Config\UserMountCache($this->connection, $this->userManager, $this->getMock('\OC\Log'));
}
@ -208,15 +209,19 @@ class UserMountCacheTest extends TestCase {
public function testGetMountsForUser() {
$user1 = $this->userManager->get('u1');
$user2 = $this->userManager->get('u2');
$user3 = $this->userManager->get('u3');
$mount1 = new MountPoint($this->getStorage(1, 2), '/foo/');
$mount2 = new MountPoint($this->getStorage(3, 4), '/bar/');
$this->cache->registerMounts($user1, [$mount1, $mount2]);
$this->cache->registerMounts($user2, [$mount2]);
$this->cache->registerMounts($user3, [$mount2]);
$this->clearCache();
$user3->delete();
$cachedMounts = $this->cache->getMountsForUser($user1);
$this->assertCount(2, $cachedMounts);
@ -229,6 +234,9 @@ class UserMountCacheTest extends TestCase {
$this->assertEquals($user1, $cachedMounts[1]->getUser());
$this->assertEquals(4, $cachedMounts[1]->getRootId());
$this->assertEquals(3, $cachedMounts[1]->getStorageId());
$cachedMounts = $this->cache->getMountsForUser($user3);
$this->assertEmpty($cachedMounts);
}
public function testGetMountsByStorageId() {
@ -397,4 +405,20 @@ class UserMountCacheTest extends TestCase {
$this->assertCount(0, $cachedMounts);
}
public function testGetMountsForFileIdDeletedUser() {
$user1 = $this->userManager->get('u1');
$storage1 = $this->getStorage(1, 2);
$rootId = $this->createCacheEntry('', 2);
$mount1 = new MountPoint($storage1, '/foo/');
$this->cache->registerMounts($user1, [$mount1]);
$user1->delete();
$this->clearCache();
$cachedMounts = $this->cache->getMountsForFileId($rootId);
$this->assertEmpty($cachedMounts);
}
}