2015-11-26 19:47:53 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2015 Robin Appelman <icewind@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Test\Files\Config;
|
|
|
|
|
2016-01-22 18:02:21 +03:00
|
|
|
use OC\DB\QueryBuilder\Literal;
|
2015-11-26 19:47:53 +03:00
|
|
|
use OC\Files\Mount\MountPoint;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OC\Files\Storage\Storage;
|
2015-12-01 15:29:20 +03:00
|
|
|
use OC\Log;
|
2015-11-26 19:47:53 +03:00
|
|
|
use OC\User\Manager;
|
2019-11-20 16:22:00 +03:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2015-12-01 15:29:20 +03:00
|
|
|
use OCP\Files\Config\ICachedMountInfo;
|
2021-02-02 17:45:34 +03:00
|
|
|
use OCP\ICacheFactory;
|
2016-10-28 10:07:40 +03:00
|
|
|
use OCP\IConfig;
|
2015-11-26 19:47:53 +03:00
|
|
|
use OCP\IDBConnection;
|
|
|
|
use OCP\IUserManager;
|
2019-02-24 10:54:43 +03:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
2015-11-26 19:47:53 +03:00
|
|
|
use Test\TestCase;
|
|
|
|
use Test\Util\User\Dummy;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DB
|
|
|
|
*/
|
2016-05-20 16:38:20 +03:00
|
|
|
class UserMountCacheTest extends TestCase {
|
2015-11-26 19:47:53 +03:00
|
|
|
/**
|
|
|
|
* @var IDBConnection
|
|
|
|
*/
|
|
|
|
private $connection;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var IUserManager
|
|
|
|
*/
|
|
|
|
private $userManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \OC\Files\Config\UserMountCache
|
|
|
|
*/
|
|
|
|
private $cache;
|
|
|
|
|
2016-01-22 18:02:21 +03:00
|
|
|
private $fileIds = [];
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function setUp(): void {
|
2016-01-22 18:02:21 +03:00
|
|
|
$this->fileIds = [];
|
2015-11-26 19:47:53 +03:00
|
|
|
$this->connection = \OC::$server->getDatabaseConnection();
|
2021-02-02 17:45:34 +03:00
|
|
|
$this->userManager = new Manager($this->createMock(IConfig::class), $this->createMock(EventDispatcherInterface::class), $this->createMock(ICacheFactory::class), $this->createMock(IEventDispatcher::class));
|
2015-11-26 19:47:53 +03:00
|
|
|
$userBackend = new Dummy();
|
|
|
|
$userBackend->createUser('u1', '');
|
|
|
|
$userBackend->createUser('u2', '');
|
2017-04-24 17:43:25 +03:00
|
|
|
$userBackend->createUser('u3', '');
|
2015-11-26 19:47:53 +03:00
|
|
|
$this->userManager->registerBackend($userBackend);
|
2016-09-12 22:04:06 +03:00
|
|
|
$this->cache = new \OC\Files\Config\UserMountCache($this->connection, $this->userManager, $this->createMock(Log::class));
|
2015-11-26 19:47:53 +03:00
|
|
|
}
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function tearDown(): void {
|
2015-11-26 19:47:53 +03:00
|
|
|
$builder = $this->connection->getQueryBuilder();
|
|
|
|
|
|
|
|
$builder->delete('mounts')->execute();
|
2016-01-22 18:02:21 +03:00
|
|
|
|
|
|
|
$builder = $this->connection->getQueryBuilder();
|
|
|
|
|
|
|
|
foreach ($this->fileIds as $fileId) {
|
|
|
|
$builder->delete('filecache')
|
|
|
|
->where($builder->expr()->eq('fileid', new Literal($fileId)))
|
|
|
|
->execute();
|
|
|
|
}
|
2015-11-26 19:47:53 +03:00
|
|
|
}
|
|
|
|
|
2016-09-18 19:36:53 +03:00
|
|
|
private function getStorage($storageId) {
|
|
|
|
$rootId = $this->createCacheEntry('', $storageId);
|
|
|
|
|
2015-11-26 19:47:53 +03:00
|
|
|
$storageCache = $this->getMockBuilder('\OC\Files\Cache\Storage')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$storageCache->expects($this->any())
|
|
|
|
->method('getNumericId')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($storageId);
|
2015-11-26 19:47:53 +03:00
|
|
|
|
|
|
|
$cache = $this->getMockBuilder('\OC\Files\Cache\Cache')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$cache->expects($this->any())
|
|
|
|
->method('getId')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($rootId);
|
2015-11-26 19:47:53 +03:00
|
|
|
|
|
|
|
$storage = $this->getMockBuilder('\OC\Files\Storage\Storage')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$storage->expects($this->any())
|
|
|
|
->method('getStorageCache')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($storageCache);
|
2015-11-26 19:47:53 +03:00
|
|
|
$storage->expects($this->any())
|
|
|
|
->method('getCache')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($cache);
|
2015-11-26 19:47:53 +03:00
|
|
|
|
2016-09-18 19:36:53 +03:00
|
|
|
return [$storage, $rootId];
|
2015-11-26 19:47:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private function clearCache() {
|
|
|
|
$this->invokePrivate($this->cache, 'mountsForUsers', [[]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNewMounts() {
|
|
|
|
$user = $this->userManager->get('u1');
|
|
|
|
|
2016-09-18 19:36:53 +03:00
|
|
|
list($storage) = $this->getStorage(10);
|
2015-11-26 19:47:53 +03:00
|
|
|
$mount = new MountPoint($storage, '/asd/');
|
|
|
|
|
|
|
|
$this->cache->registerMounts($user, [$mount]);
|
|
|
|
|
|
|
|
$this->clearCache();
|
|
|
|
|
|
|
|
$cachedMounts = $this->cache->getMountsForUser($user);
|
|
|
|
|
|
|
|
$this->assertCount(1, $cachedMounts);
|
|
|
|
$cachedMount = $cachedMounts[0];
|
|
|
|
$this->assertEquals('/asd/', $cachedMount->getMountPoint());
|
|
|
|
$this->assertEquals($user, $cachedMount->getUser());
|
|
|
|
$this->assertEquals($storage->getCache()->getId(''), $cachedMount->getRootId());
|
|
|
|
$this->assertEquals($storage->getStorageCache()->getNumericId(), $cachedMount->getStorageId());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSameMounts() {
|
|
|
|
$user = $this->userManager->get('u1');
|
|
|
|
|
2016-09-18 19:36:53 +03:00
|
|
|
list($storage) = $this->getStorage(10);
|
2015-11-26 19:47:53 +03:00
|
|
|
$mount = new MountPoint($storage, '/asd/');
|
|
|
|
|
|
|
|
$this->cache->registerMounts($user, [$mount]);
|
|
|
|
|
|
|
|
$this->clearCache();
|
|
|
|
|
|
|
|
$this->cache->registerMounts($user, [$mount]);
|
|
|
|
|
|
|
|
$this->clearCache();
|
|
|
|
|
|
|
|
$cachedMounts = $this->cache->getMountsForUser($user);
|
|
|
|
|
|
|
|
$this->assertCount(1, $cachedMounts);
|
|
|
|
$cachedMount = $cachedMounts[0];
|
|
|
|
$this->assertEquals('/asd/', $cachedMount->getMountPoint());
|
|
|
|
$this->assertEquals($user, $cachedMount->getUser());
|
|
|
|
$this->assertEquals($storage->getCache()->getId(''), $cachedMount->getRootId());
|
|
|
|
$this->assertEquals($storage->getStorageCache()->getNumericId(), $cachedMount->getStorageId());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRemoveMounts() {
|
|
|
|
$user = $this->userManager->get('u1');
|
|
|
|
|
2016-09-18 19:36:53 +03:00
|
|
|
list($storage) = $this->getStorage(10);
|
2015-11-26 19:47:53 +03:00
|
|
|
$mount = new MountPoint($storage, '/asd/');
|
|
|
|
|
|
|
|
$this->cache->registerMounts($user, [$mount]);
|
|
|
|
|
|
|
|
$this->clearCache();
|
|
|
|
|
|
|
|
$this->cache->registerMounts($user, []);
|
|
|
|
|
|
|
|
$this->clearCache();
|
|
|
|
|
|
|
|
$cachedMounts = $this->cache->getMountsForUser($user);
|
|
|
|
|
|
|
|
$this->assertCount(0, $cachedMounts);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testChangeMounts() {
|
|
|
|
$user = $this->userManager->get('u1');
|
|
|
|
|
2016-09-18 19:36:53 +03:00
|
|
|
list($storage) = $this->getStorage(10);
|
2016-07-13 17:29:51 +03:00
|
|
|
$mount = new MountPoint($storage, '/bar/');
|
2015-11-26 19:47:53 +03:00
|
|
|
|
|
|
|
$this->cache->registerMounts($user, [$mount]);
|
|
|
|
|
|
|
|
$this->clearCache();
|
|
|
|
|
2016-07-13 17:29:51 +03:00
|
|
|
$mount = new MountPoint($storage, '/foo/');
|
|
|
|
|
2015-11-26 19:47:53 +03:00
|
|
|
$this->cache->registerMounts($user, [$mount]);
|
|
|
|
|
|
|
|
$this->clearCache();
|
|
|
|
|
|
|
|
$cachedMounts = $this->cache->getMountsForUser($user);
|
|
|
|
|
|
|
|
$this->assertCount(1, $cachedMounts);
|
|
|
|
$cachedMount = $cachedMounts[0];
|
|
|
|
$this->assertEquals('/foo/', $cachedMount->getMountPoint());
|
|
|
|
}
|
|
|
|
|
2016-07-13 17:29:51 +03:00
|
|
|
public function testChangeMountId() {
|
|
|
|
$user = $this->userManager->get('u1');
|
|
|
|
|
2016-09-18 19:36:53 +03:00
|
|
|
list($storage) = $this->getStorage(10);
|
2016-07-13 17:29:51 +03:00
|
|
|
$mount = new MountPoint($storage, '/foo/', null, null, null, null);
|
|
|
|
|
|
|
|
$this->cache->registerMounts($user, [$mount]);
|
|
|
|
|
|
|
|
$this->clearCache();
|
|
|
|
|
|
|
|
$mount = new MountPoint($storage, '/foo/', null, null, null, 1);
|
|
|
|
|
|
|
|
$this->cache->registerMounts($user, [$mount]);
|
|
|
|
|
|
|
|
$this->clearCache();
|
|
|
|
|
|
|
|
$cachedMounts = $this->cache->getMountsForUser($user);
|
|
|
|
|
|
|
|
$this->assertCount(1, $cachedMounts);
|
|
|
|
$cachedMount = $cachedMounts[0];
|
|
|
|
$this->assertEquals(1, $cachedMount->getMountId());
|
|
|
|
}
|
|
|
|
|
2015-11-26 19:47:53 +03:00
|
|
|
public function testGetMountsForUser() {
|
|
|
|
$user1 = $this->userManager->get('u1');
|
|
|
|
$user2 = $this->userManager->get('u2');
|
2017-04-24 17:43:25 +03:00
|
|
|
$user3 = $this->userManager->get('u3');
|
2015-11-26 19:47:53 +03:00
|
|
|
|
2016-09-18 19:36:53 +03:00
|
|
|
list($storage1, $id1) = $this->getStorage(1);
|
|
|
|
list($storage2, $id2) = $this->getStorage(2);
|
|
|
|
$mount1 = new MountPoint($storage1, '/foo/');
|
|
|
|
$mount2 = new MountPoint($storage2, '/bar/');
|
2015-11-26 19:47:53 +03:00
|
|
|
|
|
|
|
$this->cache->registerMounts($user1, [$mount1, $mount2]);
|
|
|
|
$this->cache->registerMounts($user2, [$mount2]);
|
2017-04-24 17:43:25 +03:00
|
|
|
$this->cache->registerMounts($user3, [$mount2]);
|
2015-11-26 19:47:53 +03:00
|
|
|
|
|
|
|
$this->clearCache();
|
|
|
|
|
2017-04-24 17:43:25 +03:00
|
|
|
$user3->delete();
|
|
|
|
|
2015-11-26 19:47:53 +03:00
|
|
|
$cachedMounts = $this->cache->getMountsForUser($user1);
|
|
|
|
|
|
|
|
$this->assertCount(2, $cachedMounts);
|
|
|
|
$this->assertEquals('/foo/', $cachedMounts[0]->getMountPoint());
|
|
|
|
$this->assertEquals($user1, $cachedMounts[0]->getUser());
|
2016-09-18 19:36:53 +03:00
|
|
|
$this->assertEquals($id1, $cachedMounts[0]->getRootId());
|
2015-11-26 19:47:53 +03:00
|
|
|
$this->assertEquals(1, $cachedMounts[0]->getStorageId());
|
|
|
|
|
|
|
|
$this->assertEquals('/bar/', $cachedMounts[1]->getMountPoint());
|
|
|
|
$this->assertEquals($user1, $cachedMounts[1]->getUser());
|
2016-09-18 19:36:53 +03:00
|
|
|
$this->assertEquals($id2, $cachedMounts[1]->getRootId());
|
|
|
|
$this->assertEquals(2, $cachedMounts[1]->getStorageId());
|
2017-04-24 17:43:25 +03:00
|
|
|
|
|
|
|
$cachedMounts = $this->cache->getMountsForUser($user3);
|
|
|
|
$this->assertEmpty($cachedMounts);
|
2015-11-26 19:47:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetMountsByStorageId() {
|
|
|
|
$user1 = $this->userManager->get('u1');
|
|
|
|
$user2 = $this->userManager->get('u2');
|
|
|
|
|
2016-09-18 19:36:53 +03:00
|
|
|
list($storage1, $id1) = $this->getStorage(1);
|
|
|
|
list($storage2, $id2) = $this->getStorage(2);
|
|
|
|
$mount1 = new MountPoint($storage1, '/foo/');
|
|
|
|
$mount2 = new MountPoint($storage2, '/bar/');
|
2015-11-26 19:47:53 +03:00
|
|
|
|
|
|
|
$this->cache->registerMounts($user1, [$mount1, $mount2]);
|
|
|
|
$this->cache->registerMounts($user2, [$mount2]);
|
|
|
|
|
|
|
|
$this->clearCache();
|
|
|
|
|
2016-09-18 19:36:53 +03:00
|
|
|
$cachedMounts = $this->cache->getMountsForStorageId(2);
|
2016-01-22 18:02:21 +03:00
|
|
|
$this->sortMounts($cachedMounts);
|
2015-11-26 19:47:53 +03:00
|
|
|
|
|
|
|
$this->assertCount(2, $cachedMounts);
|
|
|
|
|
|
|
|
$this->assertEquals('/bar/', $cachedMounts[0]->getMountPoint());
|
|
|
|
$this->assertEquals($user1, $cachedMounts[0]->getUser());
|
2016-09-18 19:36:53 +03:00
|
|
|
$this->assertEquals($id2, $cachedMounts[0]->getRootId());
|
|
|
|
$this->assertEquals(2, $cachedMounts[0]->getStorageId());
|
2015-11-26 19:47:53 +03:00
|
|
|
|
|
|
|
$this->assertEquals('/bar/', $cachedMounts[1]->getMountPoint());
|
|
|
|
$this->assertEquals($user2, $cachedMounts[1]->getUser());
|
2016-09-18 19:36:53 +03:00
|
|
|
$this->assertEquals($id2, $cachedMounts[1]->getRootId());
|
|
|
|
$this->assertEquals(2, $cachedMounts[1]->getStorageId());
|
2015-11-26 19:47:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetMountsByRootId() {
|
|
|
|
$user1 = $this->userManager->get('u1');
|
|
|
|
$user2 = $this->userManager->get('u2');
|
|
|
|
|
2016-09-18 19:36:53 +03:00
|
|
|
list($storage1, $id1) = $this->getStorage(1);
|
|
|
|
list($storage2, $id2) = $this->getStorage(2);
|
|
|
|
$mount1 = new MountPoint($storage1, '/foo/');
|
|
|
|
$mount2 = new MountPoint($storage2, '/bar/');
|
2015-11-26 19:47:53 +03:00
|
|
|
|
|
|
|
$this->cache->registerMounts($user1, [$mount1, $mount2]);
|
|
|
|
$this->cache->registerMounts($user2, [$mount2]);
|
|
|
|
|
|
|
|
$this->clearCache();
|
|
|
|
|
2016-09-18 19:36:53 +03:00
|
|
|
$cachedMounts = $this->cache->getMountsForRootId($id2);
|
2016-01-22 18:02:21 +03:00
|
|
|
$this->sortMounts($cachedMounts);
|
2015-11-26 19:47:53 +03:00
|
|
|
|
|
|
|
$this->assertCount(2, $cachedMounts);
|
|
|
|
|
|
|
|
$this->assertEquals('/bar/', $cachedMounts[0]->getMountPoint());
|
|
|
|
$this->assertEquals($user1, $cachedMounts[0]->getUser());
|
2016-09-18 19:36:53 +03:00
|
|
|
$this->assertEquals($id2, $cachedMounts[0]->getRootId());
|
|
|
|
$this->assertEquals(2, $cachedMounts[0]->getStorageId());
|
2015-11-26 19:47:53 +03:00
|
|
|
|
|
|
|
$this->assertEquals('/bar/', $cachedMounts[1]->getMountPoint());
|
|
|
|
$this->assertEquals($user2, $cachedMounts[1]->getUser());
|
2016-09-18 19:36:53 +03:00
|
|
|
$this->assertEquals($id2, $cachedMounts[1]->getRootId());
|
|
|
|
$this->assertEquals(2, $cachedMounts[1]->getStorageId());
|
2015-11-26 19:47:53 +03:00
|
|
|
}
|
2016-01-22 18:02:21 +03:00
|
|
|
|
|
|
|
private function sortMounts(&$mounts) {
|
|
|
|
usort($mounts, function (ICachedMountInfo $a, ICachedMountInfo $b) {
|
|
|
|
return strcmp($a->getUser()->getUID(), $b->getUser()->getUID());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-06-12 16:24:55 +03:00
|
|
|
private function createCacheEntry($internalPath, $storageId, $size = 0) {
|
2016-09-18 19:36:53 +03:00
|
|
|
$internalPath = trim($internalPath, '/');
|
|
|
|
$inserted = $this->connection->insertIfNotExist('*PREFIX*filecache', [
|
2016-01-22 18:02:21 +03:00
|
|
|
'storage' => $storageId,
|
|
|
|
'path' => $internalPath,
|
|
|
|
'path_hash' => md5($internalPath),
|
|
|
|
'parent' => -1,
|
|
|
|
'name' => basename($internalPath),
|
|
|
|
'mimetype' => 0,
|
|
|
|
'mimepart' => 0,
|
2017-06-12 16:24:55 +03:00
|
|
|
'size' => $size,
|
2016-01-22 18:02:21 +03:00
|
|
|
'storage_mtime' => 0,
|
2016-01-26 16:51:06 +03:00
|
|
|
'encrypted' => 0,
|
2016-01-22 18:02:21 +03:00
|
|
|
'unencrypted_size' => 0,
|
|
|
|
'etag' => '',
|
|
|
|
'permissions' => 31
|
2016-01-26 16:51:06 +03:00
|
|
|
], ['storage', 'path_hash']);
|
2016-09-18 19:36:53 +03:00
|
|
|
if ($inserted) {
|
|
|
|
$id = (int)$this->connection->lastInsertId('*PREFIX*filecache');
|
|
|
|
$this->fileIds[] = $id;
|
|
|
|
} else {
|
2017-07-21 15:45:49 +03:00
|
|
|
$sql = 'SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` =?';
|
2016-09-18 19:36:53 +03:00
|
|
|
$query = $this->connection->prepare($sql);
|
|
|
|
$query->execute([$storageId, md5($internalPath)]);
|
2021-01-03 17:28:31 +03:00
|
|
|
return (int)$query->fetchOne();
|
2016-09-18 19:36:53 +03:00
|
|
|
}
|
2016-01-22 18:02:21 +03:00
|
|
|
return $id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetMountsForFileIdRootId() {
|
|
|
|
$user1 = $this->userManager->get('u1');
|
|
|
|
|
2016-09-18 19:36:53 +03:00
|
|
|
list($storage1, $rootId) = $this->getStorage(2);
|
|
|
|
$mount1 = new MountPoint($storage1, '/foo/');
|
2016-01-22 18:02:21 +03:00
|
|
|
|
|
|
|
$this->cache->registerMounts($user1, [$mount1]);
|
|
|
|
|
|
|
|
$this->clearCache();
|
|
|
|
|
|
|
|
$cachedMounts = $this->cache->getMountsForFileId($rootId);
|
|
|
|
|
|
|
|
$this->assertCount(1, $cachedMounts);
|
|
|
|
|
|
|
|
$this->assertEquals('/foo/', $cachedMounts[0]->getMountPoint());
|
|
|
|
$this->assertEquals($user1, $cachedMounts[0]->getUser());
|
|
|
|
$this->assertEquals($rootId, $cachedMounts[0]->getRootId());
|
|
|
|
$this->assertEquals(2, $cachedMounts[0]->getStorageId());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetMountsForFileIdSubFolder() {
|
|
|
|
$user1 = $this->userManager->get('u1');
|
|
|
|
|
|
|
|
$fileId = $this->createCacheEntry('/foo/bar', 2);
|
|
|
|
|
2016-09-18 19:36:53 +03:00
|
|
|
list($storage1, $rootId) = $this->getStorage(2);
|
|
|
|
$mount1 = new MountPoint($storage1, '/foo/');
|
2016-01-22 18:02:21 +03:00
|
|
|
|
|
|
|
$this->cache->registerMounts($user1, [$mount1]);
|
|
|
|
|
|
|
|
$this->clearCache();
|
|
|
|
|
|
|
|
$cachedMounts = $this->cache->getMountsForFileId($fileId);
|
|
|
|
|
|
|
|
$this->assertCount(1, $cachedMounts);
|
|
|
|
|
|
|
|
$this->assertEquals('/foo/', $cachedMounts[0]->getMountPoint());
|
|
|
|
$this->assertEquals($user1, $cachedMounts[0]->getUser());
|
|
|
|
$this->assertEquals($rootId, $cachedMounts[0]->getRootId());
|
|
|
|
$this->assertEquals(2, $cachedMounts[0]->getStorageId());
|
2017-08-22 16:44:52 +03:00
|
|
|
$this->assertEquals('foo/bar', $cachedMounts[0]->getInternalPath());
|
|
|
|
$this->assertEquals('/foo/foo/bar', $cachedMounts[0]->getPath());
|
2016-01-22 18:02:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetMountsForFileIdSubFolderMount() {
|
|
|
|
$user1 = $this->userManager->get('u1');
|
|
|
|
|
2016-09-18 19:36:53 +03:00
|
|
|
list($storage1, $rootId) = $this->getStorage(2);
|
2016-01-22 18:02:21 +03:00
|
|
|
$folderId = $this->createCacheEntry('/foo', 2);
|
|
|
|
$fileId = $this->createCacheEntry('/foo/bar', 2);
|
|
|
|
|
2016-09-18 19:36:53 +03:00
|
|
|
|
|
|
|
$mount1 = $this->getMockBuilder('\OC\Files\Mount\MountPoint')
|
|
|
|
->setConstructorArgs([$storage1, '/'])
|
|
|
|
->setMethods(['getStorageRootId'])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$mount1->expects($this->any())
|
|
|
|
->method('getStorageRootId')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($folderId);
|
2016-01-22 18:02:21 +03:00
|
|
|
|
|
|
|
$this->cache->registerMounts($user1, [$mount1]);
|
|
|
|
|
|
|
|
$this->clearCache();
|
|
|
|
|
|
|
|
$cachedMounts = $this->cache->getMountsForFileId($fileId);
|
|
|
|
|
|
|
|
$this->assertCount(1, $cachedMounts);
|
|
|
|
|
2016-09-18 19:36:53 +03:00
|
|
|
$this->assertEquals('/', $cachedMounts[0]->getMountPoint());
|
2016-01-22 18:02:21 +03:00
|
|
|
$this->assertEquals($user1, $cachedMounts[0]->getUser());
|
|
|
|
$this->assertEquals($folderId, $cachedMounts[0]->getRootId());
|
|
|
|
$this->assertEquals(2, $cachedMounts[0]->getStorageId());
|
2016-09-18 19:36:53 +03:00
|
|
|
$this->assertEquals('foo', $cachedMounts[0]->getRootInternalPath());
|
2017-08-22 16:44:52 +03:00
|
|
|
$this->assertEquals('bar', $cachedMounts[0]->getInternalPath());
|
|
|
|
$this->assertEquals('/bar', $cachedMounts[0]->getPath());
|
2016-01-22 18:02:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetMountsForFileIdSubFolderMountOutside() {
|
|
|
|
$user1 = $this->userManager->get('u1');
|
|
|
|
|
2016-09-18 19:36:53 +03:00
|
|
|
list($storage1, $rootId) = $this->getStorage(2);
|
2016-01-22 18:02:21 +03:00
|
|
|
$folderId = $this->createCacheEntry('/foo', 2);
|
|
|
|
$fileId = $this->createCacheEntry('/bar/asd', 2);
|
|
|
|
|
2016-09-18 19:36:53 +03:00
|
|
|
$mount1 = $this->getMockBuilder('\OC\Files\Mount\MountPoint')
|
|
|
|
->setConstructorArgs([$storage1, '/foo/'])
|
|
|
|
->setMethods(['getStorageRootId'])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$mount1->expects($this->any())
|
|
|
|
->method('getStorageRootId')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($folderId);
|
2016-09-18 19:36:53 +03:00
|
|
|
|
|
|
|
$this->cache->registerMounts($user1, [$mount1]);
|
2016-01-22 18:02:21 +03:00
|
|
|
|
|
|
|
$this->cache->registerMounts($user1, [$mount1]);
|
|
|
|
|
|
|
|
$this->clearCache();
|
|
|
|
|
|
|
|
$cachedMounts = $this->cache->getMountsForFileId($fileId);
|
|
|
|
|
|
|
|
$this->assertCount(0, $cachedMounts);
|
|
|
|
}
|
2017-04-24 17:43:25 +03:00
|
|
|
|
|
|
|
|
|
|
|
public function testGetMountsForFileIdDeletedUser() {
|
|
|
|
$user1 = $this->userManager->get('u1');
|
|
|
|
|
|
|
|
list($storage1, $rootId) = $this->getStorage(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);
|
|
|
|
}
|
2017-06-12 16:24:55 +03:00
|
|
|
|
|
|
|
public function testGetUsedSpaceForUsers() {
|
|
|
|
$user1 = $this->userManager->get('u1');
|
|
|
|
$user2 = $this->userManager->get('u2');
|
|
|
|
|
|
|
|
/** @var Storage $storage1 */
|
|
|
|
list($storage1, $rootId) = $this->getStorage(2);
|
|
|
|
$folderId = $this->createCacheEntry('files', 2, 100);
|
|
|
|
$fileId = $this->createCacheEntry('files/foo', 2, 7);
|
|
|
|
$storage1->getCache()->put($folderId, ['size' => 100]);
|
|
|
|
$storage1->getCache()->update($fileId, ['size' => 70]);
|
|
|
|
|
|
|
|
$mount1 = $this->getMockBuilder(MountPoint::class)
|
|
|
|
->setConstructorArgs([$storage1, '/u1/'])
|
|
|
|
->setMethods(['getStorageRootId', 'getNumericStorageId'])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$mount1->expects($this->any())
|
|
|
|
->method('getStorageRootId')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($rootId);
|
2017-06-12 16:24:55 +03:00
|
|
|
|
|
|
|
$mount1->expects($this->any())
|
|
|
|
->method('getNumericStorageId')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(2);
|
2017-06-12 16:24:55 +03:00
|
|
|
|
|
|
|
$this->cache->registerMounts($user1, [$mount1]);
|
|
|
|
|
|
|
|
$result = $this->cache->getUsedSpaceForUsers([$user1, $user2]);
|
|
|
|
$this->assertEquals(['u1' => 100], $result);
|
|
|
|
}
|
2015-11-26 19:47:53 +03:00
|
|
|
}
|