class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase {
const TEST_ENCRYPTION_TRASHBIN_USER1 = "test-trashbin-user1";
+ const TEST_ENCRYPTION_TRASHBIN_USER2 = "test-trashbin-user2";
public $userId;
public $pass;
\OC_Hook::clear('OC_Filesystem');
\OC_Hook::clear('OC_User');
+ \OC_Hook::clear('OCP\\Share');
// trashbin hooks
\OCA\Files_Trashbin\Trashbin::registerHooks();
// Filesystem related hooks
\OCA\Encryption\Helper::registerFilesystemHooks();
+
+ // register share hooks
+ \OC::registerShareHooks();
+ \OCA\Files_Sharing\Helper::registerHooks();
+
+ // Sharing related hooks
+ \OCA\Encryption\Helper::registerShareHooks();
+
+ // Filesystem related hooks
+ \OCA\Encryption\Helper::registerFilesystemHooks();
+
// clear and register hooks
\OC_FileProxy::clearProxies();
+ \OC_FileProxy::register(new OCA\Files\Share\Proxy());
\OC_FileProxy::register(new OCA\Encryption\Proxy());
// create test user
+ self::loginHelper(self::TEST_ENCRYPTION_TRASHBIN_USER2, true);
self::loginHelper(self::TEST_ENCRYPTION_TRASHBIN_USER1, true);
}
// 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');
}
. '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey.' . $trashFileSuffix));
}
+
+ function testDeleteSharedFile() {
+
+ // generate filename
+ $filename = 'tmp-' . $this->getUniqueID() . '.txt';
+
+ // save file with content
+ $cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files/' . $filename, $this->dataShort);
+ // test that data was successfully written
+ $this->assertTrue(is_int($cryptedFile));
+
+ // get the file info from previous created file
+ $fileInfo = $this->view->getFileInfo(
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files/' . $filename);
+
+ // check if we have a valid file info
+ $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo);
+
+ // share the file
+ $this->assertTrue(
+ \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_TRASHBIN_USER2, OCP\PERMISSION_ALL)
+ );
+
+ self::loginHelper(self::TEST_ENCRYPTION_TRASHBIN_USER2);
+
+ $this->assertTrue(\OC\Files\Filesystem::file_exists($filename));
+
+ \OCA\Files_Trashbin\Trashbin::move2trash($filename);
+
+ $query = \OC_DB::prepare('SELECT `timestamp` FROM `*PREFIX*files_trash`'
+ . ' WHERE `id`=?');
+ $result = $query->execute(array($filename))->fetchRow();
+
+ $this->assertNotEmpty($result);
+
+ $timestamp = $result['timestamp'];
+
+ // check if key for both users exists
+ $this->assertTrue($this->view->file_exists(
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keyfiles/' . $filename
+ . '.key.d'. $timestamp));
+ // check if key for admin exists
+ $this->assertTrue($this->view->file_exists(
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER2 . '/files_trashbin/keyfiles/' . $filename
+ . '.key.d' . $timestamp));
+
+ // check if share key for both users exists
+ $this->assertTrue($this->view->file_exists(
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/share-keys/'
+ . $filename . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey.d' . $timestamp));
+ $this->assertTrue($this->view->file_exists(
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER2 . '/files_trashbin/share-keys/'
+ . $filename . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER2 . '.shareKey.d' . $timestamp));
+ }
}
* move file to the trash bin
*
* @param string $file_path path to the deleted file/directory relative to the files root directory
+ * @return bool
*/
public static function move2trash($file_path) {
$user = \OCP\User::getUser();
}
self::setUpTrash($user);
+ if ($owner !== $user) {
+ self::setUpTrash($owner);
+ }
$view = new \OC\Files\View('/' . $user);
$path_parts = pathinfo($file_path);
$rootView->rename($sharekeys, $user . '/files_trashbin/share-keys/' . $filename . '.d' . $timestamp);
} else {
// handle share-keys
- $matches = \OCA\Encryption\Helper::findShareKeys($ownerPath, $sharekeys, $rootView);
+ $matches = \OCA\Encryption\Helper::findShareKeys($file_path, $sharekeys, $rootView);
foreach ($matches as $src) {
// get source file parts
$pathinfo = pathinfo($src);