protected function tearDown() { // disable trashbin to be able to properly clean up \OC::$server->getAppManager()->disableApp('files_trashbin'); $this->rootView->deleteAll('/' . self::TEST_TRASHBIN_USER1 . '/files'); $this->rootView->deleteAll('/' . self::TEST_TRASHBIN_USER2 . '/files'); $this->rootView->deleteAll($this->trashRoot1); $this->rootView->deleteAll($this->trashRoot2); // clear trash table $connection = \OC::$server->getDatabaseConnection(); $connection->executeUpdate('DELETE FROM `*PREFIX*files_trash`'); parent::tearDown(); }
/** * @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)); }
/** * @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)); }
function testKeySetPreperation() { $basePath = '/' . self::TEST_USER . '/files'; $path = '/folder1/subfolder/subsubfolder/file.txt'; $this->assertFalse($this->view->is_dir($basePath . '/testKeySetPreperation')); TestProtectedKeymanagerMethods::testKeySetPreperation($this->view, $basePath . $path); // check if directory structure was created $this->assertTrue($this->view->is_dir($basePath . $path)); // cleanup $this->view->deleteAll($basePath . '/folder1'); }
function testDescryptAllWithBrokenFiles() { $file1 = "/decryptAll1" . $this->getUniqueID() . ".txt"; $file2 = "/decryptAll2" . $this->getUniqueID() . ".txt"; $util = new \OCA\Files_Encryption\Util($this->view, $this->userId); $this->view->file_put_contents($this->userId . '/files/' . $file1, $this->dataShort); $this->view->file_put_contents($this->userId . '/files/' . $file2, $this->dataShort); $fileInfoEncrypted1 = $this->view->getFileInfo($this->userId . '/files/' . $file1); $fileInfoEncrypted2 = $this->view->getFileInfo($this->userId . '/files/' . $file2); $this->assertTrue($fileInfoEncrypted1 instanceof \OC\Files\FileInfo); $this->assertTrue($fileInfoEncrypted2 instanceof \OC\Files\FileInfo); $this->assertEquals($fileInfoEncrypted1['encrypted'], 1); $this->assertEquals($fileInfoEncrypted2['encrypted'], 1); // rename keyfile for file1 so that the decryption for file1 fails // Expected behaviour: decryptAll() returns false, file2 gets decrypted anyway $this->view->rename($this->userId . '/files_encryption/keys/' . $file1 . '/fileKey', $this->userId . '/files_encryption/keys/' . $file1 . '/fileKey.moved'); // need to reset key cache that we don't use the cached key $this->resetKeyCache(); // decrypt all encrypted files $result = $util->decryptAll(); $this->assertFalse($result); $fileInfoUnencrypted1 = $this->view->getFileInfo($this->userId . '/files/' . $file1); $fileInfoUnencrypted2 = $this->view->getFileInfo($this->userId . '/files/' . $file2); $this->assertTrue($fileInfoUnencrypted1 instanceof \OC\Files\FileInfo); $this->assertTrue($fileInfoUnencrypted2 instanceof \OC\Files\FileInfo); // file1 should be still encrypted; file2 should be decrypted $this->assertEquals(1, $fileInfoUnencrypted1['encrypted']); $this->assertEquals(0, $fileInfoUnencrypted2['encrypted']); // keyfiles and share keys should still exist $this->assertTrue($this->view->is_dir($this->userId . '/files_encryption/keys/')); $this->assertTrue($this->view->file_exists($this->userId . '/files_encryption/keys/' . $file1 . '/fileKey.moved')); $this->assertTrue($this->view->file_exists($this->userId . '/files_encryption/keys/' . $file1 . '/' . $this->userId . '.shareKey')); // rename the keyfile for file1 back $this->view->rename($this->userId . '/files_encryption/keys/' . $file1 . '/fileKey.moved', $this->userId . '/files_encryption/keys/' . $file1 . '/fileKey'); // try again to decrypt all encrypted files $result = $util->decryptAll(); $this->assertTrue($result); $fileInfoUnencrypted1 = $this->view->getFileInfo($this->userId . '/files/' . $file1); $fileInfoUnencrypted2 = $this->view->getFileInfo($this->userId . '/files/' . $file2); $this->assertTrue($fileInfoUnencrypted1 instanceof \OC\Files\FileInfo); $this->assertTrue($fileInfoUnencrypted2 instanceof \OC\Files\FileInfo); // now both files should be decrypted $this->assertEquals(0, $fileInfoUnencrypted1['encrypted']); $this->assertEquals(0, $fileInfoUnencrypted2['encrypted']); // keyfiles and share keys should be deleted $this->assertFalse($this->view->is_dir($this->userId . '/files_encryption/keys/')); //cleanup $backupPath = $this->getBackupPath('decryptAll'); $this->view->unlink($this->userId . '/files/' . $file1); $this->view->unlink($this->userId . '/files/' . $file2); $this->view->deleteAll($backupPath); }
protected function setUp() { parent::setUp(); // set user id \OC_User::setUserId(self::TEST_ENCRYPTION_TRASHBIN_USER1); $this->userId = self::TEST_ENCRYPTION_TRASHBIN_USER1; $this->pass = self::TEST_ENCRYPTION_TRASHBIN_USER1; // init filesystem view $this->view = new \OC\Files\View('/'); // init short data $this->dataShort = 'hats'; $this->folder1 = '/folder1'; $this->subfolder = '/subfolder1'; $this->subsubfolder = '/subsubfolder1'; // remember files_trashbin state $this->stateFilesTrashbin = OC_App::isEnabled('files_trashbin'); $this->view->deleteAll('/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin'); $this->view->deleteAll('/' . self::TEST_ENCRYPTION_TRASHBIN_USER2 . '/files_trashbin'); // we want to tests with app files_trashbin enabled \OC_App::enable('files_trashbin'); }
/** * test if we find all versions and if the versions array contain * the correct 'path' and 'name' */ public function testGetVersions() { $t1 = time(); // second version is two weeks older, this way we make sure that no // version will be expired $t2 = $t1 - 60 * 60 * 24 * 14; // create some versions $v1 = self::USERS_VERSIONS_ROOT . '/subfolder/test.txt.v' . $t1; $v2 = self::USERS_VERSIONS_ROOT . '/subfolder/test.txt.v' . $t2; $this->rootView->mkdir(self::USERS_VERSIONS_ROOT . '/subfolder/'); $this->rootView->file_put_contents($v1, 'version1'); $this->rootView->file_put_contents($v2, 'version2'); // execute copy hook of versions app $versions = \OCA\Files_Versions\Storage::getVersions(self::TEST_VERSIONS_USER, '/subfolder/test.txt'); $this->assertCount(2, $versions); foreach ($versions as $version) { $this->assertSame('/subfolder/test.txt', $version['path']); $this->assertSame('test.txt', $version['name']); } //cleanup $this->rootView->deleteAll(self::USERS_VERSIONS_ROOT . '/subfolder'); }
public function testMigrateToNewFolderStructure() { // go back to the state before migration $this->view->rename('/files_encryption/public_keys', '/public-keys'); $this->view->rename('/public-keys/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.publicKey', '/public-keys/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.public.key'); $this->view->rename('/public-keys/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.publicKey', '/public-keys/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.public.key'); $this->view->rename('/public-keys/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.publicKey', '/public-keys/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.public.key'); $this->view->deleteAll(self::TEST_ENCRYPTION_MIGRATION_USER1 . '/files_encryption/keys'); $this->view->deleteAll(self::TEST_ENCRYPTION_MIGRATION_USER2 . '/files_encryption/keys'); $this->view->deleteAll(self::TEST_ENCRYPTION_MIGRATION_USER3 . '/files_encryption/keys'); $this->view->rename(self::TEST_ENCRYPTION_MIGRATION_USER1 . '/files_encryption/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.privateKey', self::TEST_ENCRYPTION_MIGRATION_USER1 . '/files_encryption/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.private.key'); $this->view->rename(self::TEST_ENCRYPTION_MIGRATION_USER2 . '/files_encryption/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.privateKey', self::TEST_ENCRYPTION_MIGRATION_USER2 . '/files_encryption/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.private.key'); $this->view->rename(self::TEST_ENCRYPTION_MIGRATION_USER3 . '/files_encryption/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.privateKey', self::TEST_ENCRYPTION_MIGRATION_USER3 . '/files_encryption/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.private.key'); $this->createDummyShareKeys(self::TEST_ENCRYPTION_MIGRATION_USER1); $this->createDummyShareKeys(self::TEST_ENCRYPTION_MIGRATION_USER2); $this->createDummyShareKeys(self::TEST_ENCRYPTION_MIGRATION_USER3); $this->createDummyFileKeys(self::TEST_ENCRYPTION_MIGRATION_USER1); $this->createDummyFileKeys(self::TEST_ENCRYPTION_MIGRATION_USER2); $this->createDummyFileKeys(self::TEST_ENCRYPTION_MIGRATION_USER3); $this->createDummyFilesInTrash(self::TEST_ENCRYPTION_MIGRATION_USER2); // no user for system wide mount points $this->createDummyFileKeys(''); $this->createDummyShareKeys(''); $this->createDummySystemWideKeys(); $m = new \OCA\Files_Encryption\Migration(); $m->reorganizeFolderStructure(); // TODO Verify that all files at the right place $this->assertTrue($this->view->file_exists('/files_encryption/public_keys/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.publicKey')); $this->assertTrue($this->view->file_exists('/files_encryption/public_keys/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.publicKey')); $this->assertTrue($this->view->file_exists('/files_encryption/public_keys/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.publicKey')); $this->verifyNewKeyPath(self::TEST_ENCRYPTION_MIGRATION_USER1); $this->verifyNewKeyPath(self::TEST_ENCRYPTION_MIGRATION_USER2); $this->verifyNewKeyPath(self::TEST_ENCRYPTION_MIGRATION_USER3); // system wide keys $this->verifyNewKeyPath(''); // trash $this->verifyFilesInTrash(self::TEST_ENCRYPTION_MIGRATION_USER2); }
/** * delete backup * * @param string $backup complete name of the backup * @return boolean */ public function deleteBackup($backup) { $backupDir = $this->encryptionDir . '/backup.' . $backup . '/'; return $this->view->deleteAll($backupDir); }
public function tearDown() { $this->rootView->deleteAll($this->trashRoot1); $this->rootView->deleteAll($this->trashRoot2); }
/** * delete all files from the trash */ public static function deleteAll() { $user = \OCP\User::getUser(); $view = new \OC\Files\View('/' . $user); $view->deleteAll('files_trashbin'); $query = \OC_DB::prepare('DELETE FROM `*PREFIX*files_trash` WHERE `user`=?'); $query->execute(array($user)); $view->mkdir('files_trashbin'); $view->mkdir('files_trashbin/files'); return true; }
/** * delete old keys * * @param string $user */ private function deleteOldKeys($user) { $this->view->deleteAll($user . '/files_encryption/keyfiles'); $this->view->deleteAll($user . '/files_encryption/share-keys'); }
protected function tearDown() { $this->rootView->deleteAll($this->trashRoot1); $this->rootView->deleteAll($this->trashRoot2); parent::tearDown(); }
/** * @inheritdoc */ public function deleteAllFileKeys($path) { $keyDir = $this->getFileKeyDir('', $path); return !$this->view->file_exists($keyDir) || $this->view->deleteAll($keyDir); }
/** * @param \OC\Files\View $view * @param $file * @param $filename * @param $timestamp * @return int */ private static function deleteEncryptionKeys(\OC\Files\View $view, $file, $filename, $timestamp) { $size = 0; if (\OCP\App::isEnabled('files_encryption')) { $user = \OCP\User::getUser(); $keyfiles = \OC\Files\Filesystem::normalizePath('files_trashbin/keys/' . $filename); if ($timestamp) { $keyfiles .= '.d' . $timestamp; } if ($view->is_dir($keyfiles)) { $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $keyfiles)); $view->deleteAll($keyfiles); } } return $size; }