public function setUp() { $this->user = $this->initFS(); $this->rootView = new \OC\Files\View(''); $this->rootView->mkdir('/' . $this->user); $this->rootView->mkdir('/' . $this->user . '/files'); }
/** * Make sure your configuration file doesn't contain any additional providers */ protected function setUp() { parent::setUp(); $userManager = \OC::$server->getUserManager(); $userManager->clearBackends(); $backend = new \Test\Util\User\Dummy(); $userManager->registerBackend($backend); $backend->createUser(self::TEST_PREVIEW_USER1, self::TEST_PREVIEW_USER1); $this->loginAsUser(self::TEST_PREVIEW_USER1); $storage = new \OC\Files\Storage\Temporary([]); \OC\Files\Filesystem::mount($storage, [], '/' . self::TEST_PREVIEW_USER1 . '/'); $this->rootView = new \OC\Files\View(''); $this->rootView->mkdir('/' . self::TEST_PREVIEW_USER1); $this->rootView->mkdir('/' . self::TEST_PREVIEW_USER1 . '/files'); // We simulate the max dimension set in the config \OC::$server->getConfig()->setSystemValue('preview_max_x', $this->configMaxWidth); \OC::$server->getConfig()->setSystemValue('preview_max_y', $this->configMaxHeight); // Used to test upscaling $this->maxScaleFactor = 2; \OC::$server->getConfig()->setSystemValue('preview_max_scale_factor', $this->maxScaleFactor); // We need to enable the providers we're going to use in the tests $providers = ['OC\\Preview\\JPEG', 'OC\\Preview\\PNG', 'OC\\Preview\\GIF', 'OC\\Preview\\TXT', 'OC\\Preview\\Postscript']; \OC::$server->getConfig()->setSystemValue('enabledPreviewProviders', $providers); // Sample is 1680x1050 JPEG $this->prepareSample('testimage.jpg', 1680, 1050); // Sample is 2400x1707 EPS $this->prepareSample('testimage.eps', 2400, 1707); // Sample is 1200x450 PNG $this->prepareSample('testimage-wide.png', 1200, 450); // Sample is 64x64 GIF $this->prepareSample('testimage.gif', 64, 64); }
/** * @dataProvider prepareParametersData */ public function testPrepareParameters($params, $filePosition, $stripPath, $highlightParams, $expected, $createFolder = '') { if ($createFolder !== '') { $this->view->mkdir('/' . \OCP\User::getUser() . '/files/' . $createFolder); } $this->assertEquals($expected, $this->parameterHelper->prepareParameters($params, $filePosition, $stripPath, $highlightParams)); }
protected function setUp() { parent::setUp(); //clear all proxies and hooks so we can do clean testing \OC_Hook::clear('OC_Filesystem'); //set up temporary storage $this->storage = \OC\Files\Filesystem::getStorage('/'); \OC\Files\Filesystem::clearMounts(); $storage = new \OC\Files\Storage\Temporary(array()); \OC\Files\Filesystem::mount($storage, array(), '/'); $datadir = str_replace('local::', '', $storage->getId()); $config = \OC::$server->getConfig(); $this->datadir = $config->getSystemValue('cachedirectory', \OC::$SERVERROOT . '/data/cache'); $config->setSystemValue('cachedirectory', $datadir); \OC_User::clearBackends(); \OC_User::useBackend(new \Test\Util\User\Dummy()); //login \OC_User::createUser('test', 'test'); $this->user = \OC_User::getUser(); \OC_User::setUserId('test'); //set up the users dir $this->rootView = new \OC\Files\View(''); $this->rootView->mkdir('/test'); $this->instance = new \OC\Cache\File(); // forces creation of cache folder for subsequent tests $this->instance->set('hack', 'hack'); }
/** * @dataProvider prepareParametersData */ public function testPrepareParameters($params, $filePosition, $stripPath, $highlightParams, $expected, $createFolder = '', $enableAvatars = true) { if ($createFolder !== '') { $this->view->mkdir('/' . \OCP\User::getUser() . '/files/' . $createFolder); } $this->config->expects($this->any())->method('getSystemValue')->with('enable_avatars', true)->willReturn($enableAvatars); $this->assertEquals($expected, $this->parameterHelper->prepareParameters($params, $filePosition, $stripPath, $highlightParams)); }
protected function setUp() { parent::setUp(); $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); // create a new user with his own filesystem view // this gets called by each test in this test class $this->user = $this->getUniqueID(); \OC_User::setUserId($this->user); \OC\Files\Filesystem::init($this->user, '/' . $this->user . '/files'); \OC\Files\Filesystem::mount('OC\\Files\\Storage\\Temporary', array(), '/'); $this->rootView = new \OC\Files\View(''); $this->rootView->mkdir('/' . $this->user); $this->rootView->mkdir('/' . $this->user . '/files'); }
private function doTestRestore() { $filePath = self::TEST_VERSIONS_USER . '/files/sub/test.txt'; $this->rootView->file_put_contents($filePath, 'test file'); $t0 = $this->rootView->filemtime($filePath); // not exactly the same timestamp as the file $t1 = time() - 60; // second version is two weeks older $t2 = $t1 - 60 * 60 * 24 * 14; // create some versions $v1 = self::USERS_VERSIONS_ROOT . '/sub/test.txt.v' . $t1; $v2 = self::USERS_VERSIONS_ROOT . '/sub/test.txt.v' . $t2; $this->rootView->mkdir(self::USERS_VERSIONS_ROOT . '/sub'); $this->rootView->file_put_contents($v1, 'version1'); $this->rootView->file_put_contents($v2, 'version2'); $oldVersions = \OCA\Files_Versions\Storage::getVersions(self::TEST_VERSIONS_USER, '/sub/test.txt'); $this->assertCount(2, $oldVersions); $this->assertEquals('test file', $this->rootView->file_get_contents($filePath)); $info1 = $this->rootView->getFileInfo($filePath); \OCA\Files_Versions\Storage::rollback('sub/test.txt', $t2); $this->assertEquals('version2', $this->rootView->file_get_contents($filePath)); $info2 = $this->rootView->getFileInfo($filePath); $this->assertNotEquals($info2['etag'], $info1['etag'], 'Etag must change after rolling back version'); $this->assertEquals($info2['fileid'], $info1['fileid'], 'File id must not change after rolling back version'); $this->assertEquals($info2['mtime'], $t2, 'Restored file has mtime from version'); $newVersions = \OCA\Files_Versions\Storage::getVersions(self::TEST_VERSIONS_USER, '/sub/test.txt'); $this->assertTrue($this->rootView->file_exists(self::USERS_VERSIONS_ROOT . '/sub/test.txt.v' . $t0), 'A version file was created for the file before restoration'); $this->assertTrue($this->rootView->file_exists($v1), 'Untouched version file is still there'); $this->assertFalse($this->rootView->file_exists($v2), 'Restored version file gone from files_version folder'); $this->assertCount(2, $newVersions, 'Additional version created'); $this->assertTrue(isset($newVersions[$t0 . '#' . 'test.txt']), 'A version was created for the file before restoration'); $this->assertTrue(isset($newVersions[$t1 . '#' . 'test.txt']), 'Untouched version is still there'); $this->assertFalse(isset($newVersions[$t2 . '#' . 'test.txt']), 'Restored version is not in the list any more'); }
protected function setUp() { $app = new Application(); $this->container = $app->getContainer(); $this->container['AppName'] = 'core'; $this->container['AvatarManager'] = $this->getMockBuilder('OCP\\IAvatarManager')->disableOriginalConstructor()->getMock(); $this->container['Cache'] = $this->getMockBuilder('OCP\\ICache')->disableOriginalConstructor()->getMock(); $this->container['L10N'] = $this->getMockBuilder('OCP\\IL10N')->disableOriginalConstructor()->getMock(); $this->container['L10N']->method('t')->will($this->returnArgument(0)); $this->container['UserManager'] = $this->getMockBuilder('OCP\\IUserManager')->disableOriginalConstructor()->getMock(); $this->container['UserSession'] = $this->getMockBuilder('OCP\\IUserSession')->disableOriginalConstructor()->getMock(); $this->container['Request'] = $this->getMockBuilder('OCP\\IRequest')->disableOriginalConstructor()->getMock(); $this->avatarMock = $this->getMockBuilder('OCP\\IAvatar')->disableOriginalConstructor()->getMock(); $this->userMock = $this->getMockBuilder('OCP\\IUser')->disableOriginalConstructor()->getMock(); $this->avatarController = $this->container['AvatarController']; // Store current User $this->oldUser = \OC_User::getUser(); // Create a dummy user $this->user = $this->getUniqueID('user'); OC::$server->getUserManager()->createUser($this->user, $this->user); $this->loginAsUser($this->user); // Create Cache dir $view = new \OC\Files\View('/' . $this->user); $view->mkdir('cache'); // Configure userMock $this->userMock->method('getDisplayName')->willReturn($this->user); $this->userMock->method('getUID')->willReturn($this->user); $this->container['UserManager']->method('get')->willReturnMap([[$this->user, $this->userMock]]); $this->container['UserSession']->method('getUser')->willReturn($this->userMock); }
public function testPropagateCrossStorage() { $storage = new Temporary(); $this->view->mkdir('/foo'); Filesystem::mount($storage, [], $this->view->getAbsolutePath('/foo/submount')); $this->view->mkdir('/foo/submount/bar'); $this->view->file_put_contents('/foo/submount/bar/sad.txt', 'qwerty'); $oldInfo1 = $this->view->getFileInfo('/'); $oldInfo2 = $this->view->getFileInfo('/foo'); $oldInfo3 = $this->view->getFileInfo('/foo/submount'); $oldInfo4 = $this->view->getFileInfo('/foo/submount/bar'); $time = time() + 50; $this->propagator->addChange('/foo/submount/bar/sad.txt'); $this->propagator->propagateChanges($time); $newInfo1 = $this->view->getFileInfo('/'); $newInfo2 = $this->view->getFileInfo('/foo'); $newInfo3 = $this->view->getFileInfo('/foo/submount'); $newInfo4 = $this->view->getFileInfo('/foo/submount/bar'); $this->assertEquals($newInfo1->getMTime(), $time); $this->assertEquals($newInfo2->getMTime(), $time); $this->assertEquals($newInfo3->getMTime(), $time); $this->assertEquals($newInfo4->getMTime(), $time); $this->assertNotSame($oldInfo1->getEtag(), $newInfo1->getEtag()); $this->assertNotSame($oldInfo2->getEtag(), $newInfo2->getEtag()); $this->assertNotSame($oldInfo3->getEtag(), $newInfo3->getEtag()); $this->assertNotSame($oldInfo4->getEtag(), $newInfo3->getEtag()); }
/** * Copies a file or directory. * * This method must work recursively and delete the destination * if it exists * * @param string $source * @param string $destination * @throws \Sabre\DAV\Exception\ServiceUnavailable * @return void */ public function copy($source, $destination) { if (!$this->fileView) { throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup'); } try { if ($this->fileView->is_file($source)) { $this->fileView->copy($source, $destination); } else { $this->fileView->mkdir($destination); $dh = $this->fileView->opendir($source); if (is_resource($dh)) { while (($subNode = readdir($dh)) !== false) { if ($subNode == '.' || $subNode == '..') { continue; } $this->copy($source . '/' . $subNode, $destination . '/' . $subNode); } } } } catch (\OCP\Files\StorageNotAvailableException $e) { throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage()); } list($destinationDir, ) = \Sabre\DAV\URLUtil::splitPath($destination); $this->markDirty($destinationDir); }
public function testSizePropagationWhenRecipientChangesFile() { $this->loginHelper(self::TEST_FILES_SHARING_API_USER1); $recipientView = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files'); $this->loginHelper(self::TEST_FILES_SHARING_API_USER2); $ownerView = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files'); $ownerView->mkdir('/sharedfolder/subfolder'); $ownerView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'bar'); $sharedFolderInfo = $ownerView->getFileInfo('/sharedfolder', false); $this->assertInstanceOf('\\OC\\Files\\FileInfo', $sharedFolderInfo); \OCP\Share::shareItem('folder', $sharedFolderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER1, 31); $ownerRootInfo = $ownerView->getFileInfo('', false); $this->loginHelper(self::TEST_FILES_SHARING_API_USER1); $this->assertTrue($recipientView->file_exists('/sharedfolder/subfolder/foo.txt')); $recipientRootInfo = $recipientView->getFileInfo('', false); // when file changed as recipient $recipientView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'foobar'); // size of recipient's root stays the same $newRecipientRootInfo = $recipientView->getFileInfo('', false); $this->assertEquals($recipientRootInfo->getSize(), $newRecipientRootInfo->getSize()); // size of owner's root increases $this->loginHelper(self::TEST_FILES_SHARING_API_USER2); $newOwnerRootInfo = $ownerView->getFileInfo('', false); $this->assertEquals($ownerRootInfo->getSize() + 3, $newOwnerRootInfo->getSize()); }
public function testDontLowerMtime() { $time = time(); $this->view->mkdir('/foo'); $this->view->mkdir('/foo/bar'); $cache = $this->storage->getCache(); $cache->put('', ['mtime' => $time - 50]); $cache->put('foo', ['mtime' => $time - 150]); $cache->put('foo/bar', ['mtime' => $time - 250]); $this->propagator->addChange('/foo/bar/foo'); $this->propagator->propagateChanges($time - 100); $this->assertEquals(50, $time - $cache->get('')['mtime']); $this->assertEquals(100, $time - $cache->get('foo')['mtime']); $this->assertEquals(100, $time - $cache->get('foo/bar')['mtime']); }
/** * @dataProvider isExcludedPathProvider */ function testIsExcludedPath($path, $expected) { $this->view->mkdir(dirname($path)); $this->view->file_put_contents($path, "test"); $result = \Test_Helper::invokePrivate(new \OCA\Files_Encryption\Proxy(), 'isExcludedPath', array($path)); $this->assertSame($expected, $result); $this->view->deleteAll(dirname($path)); }
protected function setUp() { parent::setUp(); $userManager = \OC::$server->getUserManager(); $userManager->clearBackends(); $backend = new \OC_User_Dummy(); $userManager->registerBackend($backend); $userId = $this->getUniqueID(); $backend->createUser($userId, $userId); $this->loginAsUser($userId); $this->storage = new \OC\Files\Storage\Temporary([]); \OC\Files\Filesystem::mount($this->storage, [], '/' . $userId . '/'); $this->rootView = new \OC\Files\View(''); $this->rootView->mkdir('/' . $userId); $this->rootView->mkdir('/' . $userId . '/files'); $this->userId = $userId; }
private function createDummyKeysForBackupTest() { // create some dummy key files $encPath = '/' . self::TEST_ENCRYPTION_UTIL_USER1 . '/files_encryption'; $this->view->mkdir($encPath . '/keys/foo'); $this->view->file_put_contents($encPath . '/keys/foo/fileKey', 'key'); $this->view->file_put_contents($encPath . '/keys/foo/user1.shareKey', 'share key'); }
protected function createDummySystemWideKeys() { $this->view->mkdir('files_encryption'); $this->view->mkdir('files_encryption/public_keys'); $this->view->file_put_contents('files_encryption/systemwide_1.privateKey', 'data'); $this->view->file_put_contents('files_encryption/systemwide_2.privateKey', 'data'); $this->view->file_put_contents('files_encryption/public_keys/systemwide_1.publicKey', 'data'); $this->view->file_put_contents('files_encryption/public_keys/systemwide_2.publicKey', 'data'); }
/** * @dataProvider isExcludedPathProvider */ function testIsExcludedPath($path, $expected) { $this->view->mkdir(dirname($path)); $this->view->file_put_contents($path, "test"); $testClass = new DummyProxy(); $result = $testClass->isExcludedPathTesting($path, $this->userId); $this->assertSame($expected, $result); $this->view->deleteAll(dirname($path)); }
protected function setUp() { parent::setUp(); // FIXME: use proper tearDown with $this->loginAsUser() and $this->logout() // (would currently break the tests for some reason) $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); // create a new user with his own filesystem view // this gets called by each test in this test class $backend = new \OC_User_Dummy(); \OC_User::useBackend($backend); $backend->createUser(self::TEST_PREVIEW_USER1, self::TEST_PREVIEW_USER1); $user = \OC::$server->getUserManager()->get(self::TEST_PREVIEW_USER1); \OC::$server->getUserSession()->setUser($user); \OC\Files\Filesystem::init(self::TEST_PREVIEW_USER1, '/' . self::TEST_PREVIEW_USER1 . '/files'); \OC\Files\Filesystem::mount('OC\\Files\\Storage\\Temporary', array(), '/'); $this->rootView = new \OC\Files\View(''); $this->rootView->mkdir('/' . self::TEST_PREVIEW_USER1); $this->rootView->mkdir('/' . self::TEST_PREVIEW_USER1 . '/files'); }
public function testSinglePropagate() { $this->view->mkdir('/foo'); $this->view->mkdir('/foo/bar'); $this->view->file_put_contents('/foo/bar/sad.txt', 'qwerty'); $oldInfo1 = $this->view->getFileInfo('/'); $oldInfo2 = $this->view->getFileInfo('/foo'); $oldInfo3 = $this->view->getFileInfo('/foo/bar'); $time = time() + 50; $this->propagator->addChange('/foo/bar/sad.txt'); $this->propagator->propagateChanges($time); $newInfo1 = $this->view->getFileInfo('/'); $newInfo2 = $this->view->getFileInfo('/foo'); $newInfo3 = $this->view->getFileInfo('/foo/bar'); $this->assertEquals($newInfo1->getMTime(), $time); $this->assertEquals($newInfo2->getMTime(), $time); $this->assertEquals($newInfo3->getMTime(), $time); $this->assertNotSame($oldInfo1->getEtag(), $newInfo1->getEtag()); $this->assertNotSame($oldInfo2->getEtag(), $newInfo2->getEtag()); $this->assertNotSame($oldInfo3->getEtag(), $newInfo3->getEtag()); }
/** * create a backup of all keys from the user * * @param string $purpose define the purpose of the backup, will be part of the backup folder name * @param boolean $timestamp (optional) should a timestamp be added, default true * @param boolean $includeUserKeys (optional) include users private-/public-key, default true */ public function backupAllKeys($purpose, $timestamp = true, $includeUserKeys = true) { $this->userId; $backupDir = $this->encryptionDir . '/backup.' . $purpose; $backupDir .= $timestamp ? '.' . date("Y-m-d_H-i-s") . '/' : '/'; $this->view->mkdir($backupDir); $this->view->copy($this->keysPath, $backupDir . 'keys/'); if ($includeUserKeys) { $this->view->copy($this->privateKeyPath, $backupDir . $this->userId . '.privateKey'); $this->view->copy($this->publicKeyPath, $backupDir . $this->userId . '.publicKey'); } }
/** * @return Directory */ private function impl() { $rootView = new View(); $user = \OC::$server->getUserSession()->getUser(); Filesystem::initMountPoints($user->getUID()); if (!$rootView->file_exists('/' . $user->getUID() . '/uploads')) { $rootView->mkdir('/' . $user->getUID() . '/uploads'); } $view = new View('/' . $user->getUID() . '/uploads'); $rootInfo = $view->getFileInfo(''); $impl = new Directory($view, $rootInfo); return $impl; }
/** * create directories for the keys recursively * * @param string $path */ private function createPathForKeys($path) { if (!$this->view->file_exists($path)) { $sub_dirs = explode('/', $path); $dir = ''; foreach ($sub_dirs as $sub_dir) { $dir .= '/' . $sub_dir; if (!$this->view->is_dir($dir)) { $this->view->mkdir($dir); } } } }
/** * Make preparations to filesystem for saving a key file * * @param string $path relative to the views root */ protected function keySetPreparation($path) { // If the file resides within a subdirectory, create it if (!$this->view->file_exists($path)) { $sub_dirs = explode('/', ltrim($path, '/')); $dir = ''; foreach ($sub_dirs as $sub_dir) { $dir .= '/' . $sub_dir; if (!$this->view->is_dir($dir)) { $this->view->mkdir($dir); } } } }
/** * Make preparations to filesystem for saving a key file * * @param string $path relative to data/ */ protected function prepareParentFolder($path) { $path = Filesystem::normalizePath($path); // If the file resides within a subdirectory, create it if ($this->rootView->file_exists($path) === false) { $sub_dirs = explode('/', ltrim($path, '/')); $dir = ''; foreach ($sub_dirs as $sub_dir) { $dir .= '/' . $sub_dir; if ($this->rootView->file_exists($dir) === false) { $this->rootView->mkdir($dir); } } } }
/** * Returns the cache storage for the logged in user * * @return \OC\Files\View cache storage * @throws \OC\ForbiddenException * @throws \OC\User\NoUserException */ protected function getStorage() { if (isset($this->storage)) { return $this->storage; } if (\OC_User::isLoggedIn()) { $rootView = new View(); $user = \OC::$server->getUserSession()->getUser(); Filesystem::initMountPoints($user->getUID()); if (!$rootView->file_exists('/' . $user->getUID() . '/cache')) { $rootView->mkdir('/' . $user->getUID() . '/cache'); } $this->storage = new View('/' . $user->getUID() . '/cache'); return $this->storage; } else { \OCP\Util::writeLog('core', 'Can\'t get cache storage, user not logged in', \OCP\Util::ERROR); throw new \OC\ForbiddenException('Can\t get cache storage, user not logged in'); } }
/** * Save the certificate and re-generate the certificate bundle * * @param string $certificate the certificate data * @param string $name the filename for the certificate * @return \OCP\ICertificate * @throws \Exception If the certificate could not get added */ public function addCertificate($certificate, $name) { if (!Filesystem::isValidPath($name) or Filesystem::isFileBlacklisted($name)) { throw new \Exception('Filename is not valid'); } $dir = $this->getPathToCertificates() . 'uploads/'; if (!$this->view->file_exists($dir)) { $this->view->mkdir($dir); } try { $file = $dir . $name; $certificateObject = new Certificate($certificate, $name); $this->view->file_put_contents($file, $certificate); $this->createCertificateBundle(); return $certificateObject; } catch (\Exception $e) { throw $e; } }
/** * if session is started, check if ownCloud key pair is set up, if not create it * @param \OC\Files\View $view * * @note The ownCloud key pair is used to allow public link sharing even if encryption is enabled */ public function __construct($view) { $this->view = $view; if (!$this->view->is_dir('owncloud_private_key')) { $this->view->mkdir('owncloud_private_key'); } $appConfig = \OC::$server->getAppConfig(); $publicShareKeyId = $appConfig->getValue('files_encryption', 'publicShareKeyId'); if ($publicShareKeyId === null) { $publicShareKeyId = 'pubShare_' . substr(md5(time()), 0, 8); $appConfig->setValue('files_encryption', 'publicShareKeyId', $publicShareKeyId); } if (!$this->view->file_exists("/public-keys/" . $publicShareKeyId . ".public.key") || !$this->view->file_exists("/owncloud_private_key/" . $publicShareKeyId . ".private.key")) { $keypair = Crypt::createKeypair(); // Disable encryption proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; // Save public key if (!$view->is_dir('/public-keys')) { $view->mkdir('/public-keys'); } $this->view->file_put_contents('/public-keys/' . $publicShareKeyId . '.public.key', $keypair['publicKey']); // Encrypt private key empty passphrase $cipher = \OCA\Encryption\Helper::getCipher(); $encryptedKey = \OCA\Encryption\Crypt::symmetricEncryptFileContent($keypair['privateKey'], '', $cipher); if ($encryptedKey) { Keymanager::setPrivateSystemKey($encryptedKey, $publicShareKeyId . '.private.key'); } else { \OCP\Util::writeLog('files_encryption', 'Could not create public share keys', \OCP\Util::ERROR); } \OC_FileProxy::$enabled = $proxyStatus; } if (\OCA\Encryption\Helper::isPublicAccess()) { // Disable encryption proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; $encryptedKey = $this->view->file_get_contents('/owncloud_private_key/' . $publicShareKeyId . '.private.key'); $privateKey = Crypt::decryptPrivateKey($encryptedKey, ''); $this->setPublicSharePrivateKey($privateKey); $this->setInitialized(\OCA\Encryption\Session::INIT_SUCCESSFUL); \OC_FileProxy::$enabled = $proxyStatus; } }
/** * "user1" creates /test, /test/sub and shares with group1 * "user2" (in group1) reshares /test with group2 and reshared /test/sub with group3 * "user3" (in group 2) * "user4" (in group 3) */ protected function setUpShares() { $this->fileIds[self::TEST_FILES_SHARING_API_USER1] = []; $this->fileIds[self::TEST_FILES_SHARING_API_USER2] = []; $this->fileIds[self::TEST_FILES_SHARING_API_USER3] = []; $this->fileIds[self::TEST_FILES_SHARING_API_USER4] = []; $this->rootView = new View(''); $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1); $view1 = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files'); $view1->mkdir('/test/sub'); $folderInfo = $view1->getFileInfo('/test'); \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_GROUP, 'group1', 31); $this->fileIds[self::TEST_FILES_SHARING_API_USER1][''] = $view1->getFileInfo('')->getId(); $this->fileIds[self::TEST_FILES_SHARING_API_USER1]['test'] = $view1->getFileInfo('test')->getId(); $this->fileIds[self::TEST_FILES_SHARING_API_USER1]['test/sub'] = $view1->getFileInfo('test/sub')->getId(); $this->loginAsUser(self::TEST_FILES_SHARING_API_USER2); $view2 = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files'); $folderInfo = $view2->getFileInfo('/test'); $subFolderInfo = $view2->getFileInfo('/test/sub'); \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_GROUP, 'group2', 31); \OCP\Share::shareItem('folder', $subFolderInfo->getId(), \OCP\Share::SHARE_TYPE_GROUP, 'group3', 31); $this->fileIds[self::TEST_FILES_SHARING_API_USER2][''] = $view2->getFileInfo('')->getId(); $this->fileIds[self::TEST_FILES_SHARING_API_USER2]['test'] = $view2->getFileInfo('test')->getId(); $this->fileIds[self::TEST_FILES_SHARING_API_USER2]['test/sub'] = $view2->getFileInfo('test/sub')->getId(); $this->loginAsUser(self::TEST_FILES_SHARING_API_USER3); $view3 = new View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files'); $this->fileIds[self::TEST_FILES_SHARING_API_USER3][''] = $view3->getFileInfo('')->getId(); $this->fileIds[self::TEST_FILES_SHARING_API_USER3]['test'] = $view3->getFileInfo('test')->getId(); $this->fileIds[self::TEST_FILES_SHARING_API_USER3]['test/sub'] = $view3->getFileInfo('test/sub')->getId(); $this->loginAsUser(self::TEST_FILES_SHARING_API_USER4); $view4 = new View('/' . self::TEST_FILES_SHARING_API_USER4 . '/files'); $this->fileIds[self::TEST_FILES_SHARING_API_USER4][''] = $view4->getFileInfo('')->getId(); $this->fileIds[self::TEST_FILES_SHARING_API_USER4]['sub'] = $view4->getFileInfo('sub')->getId(); foreach ($this->fileIds as $user => $ids) { $this->loginAsUser($user); foreach ($ids as $id) { $path = $this->rootView->getPath($id); $this->fileEtags[$id] = $this->rootView->getFileInfo($path)->getEtag(); } } }
/** * test rename operation */ function doTestCopyHook($filename) { // check if keys exists $this->assertTrue($this->rootView->file_exists( '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/' . $filename . '.' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey')); $this->assertTrue($this->rootView->file_exists( '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $filename . '.key')); // make subfolder and sub-subfolder $this->rootView->mkdir('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/' . $this->folder); $this->rootView->mkdir('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/' . $this->folder . '/' . $this->folder); $this->assertTrue($this->rootView->is_dir('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/' . $this->folder . '/' . $this->folder)); // copy the file to the sub-subfolder \OC\Files\Filesystem::copy($filename, '/' . $this->folder . '/' . $this->folder . '/' . $filename); $this->assertTrue($this->rootView->file_exists('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/' . $filename)); $this->assertTrue($this->rootView->file_exists('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/' . $this->folder . '/' . $this->folder . '/' . $filename)); // keys should be copied too $this->assertTrue($this->rootView->file_exists( '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/' . $filename . '.' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey')); $this->assertTrue($this->rootView->file_exists( '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $filename . '.key')); $this->assertTrue($this->rootView->file_exists( '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/' . $this->folder . '/' . $this->folder . '/' . $filename . '.' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey')); $this->assertTrue($this->rootView->file_exists( '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $this->folder . '/' . $this->folder . '/' . $filename . '.key')); // cleanup $this->rootView->unlink('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/' . $this->folder); $this->rootView->unlink('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/' . $filename); }
/** * Delete should fail is the source folder cant be deleted */ public function testSingleStorageDeleteFolderFail() { /** * @var \OC\Files\Storage\Temporary | \PHPUnit_Framework_MockObject_MockObject $storage */ $storage = $this->getMockBuilder('\\OC\\Files\\Storage\\Temporary')->setConstructorArgs([[]])->setMethods(['rename', 'unlink', 'rmdir'])->getMock(); $storage->expects($this->any())->method('rmdir')->will($this->returnValue(false)); $cache = $storage->getCache(); Filesystem::mount($storage, [], '/' . $this->user . '/files'); $this->userView->mkdir('folder'); $this->userView->file_put_contents('folder/test.txt', 'foo'); $this->assertTrue($storage->file_exists('folder/test.txt')); $this->assertFalse($this->userView->rmdir('folder')); $this->assertTrue($storage->file_exists('folder')); $this->assertTrue($storage->file_exists('folder/test.txt')); $this->assertTrue($cache->inCache('folder')); $this->assertTrue($cache->inCache('folder/test.txt')); // file should not be in the trashbin $results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files/'); $this->assertEquals(0, count($results)); }