Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2015-05-28 17:53:55 +0300
committerVincent Petry <pvince81@owncloud.com>2015-05-28 17:53:55 +0300
commitb04d51005370cb8fb94d171082a389ff02b104e9 (patch)
treee6a0fb4415faa6fe2ca23019cc7d92dadf80a271
parent55a122a9fecabc928162cab1346c22e3e7c86f70 (diff)
parentb4741cfa9617006e95ebb85731773d0e2360c202 (diff)
Merge pull request #16608 from owncloud/fix_14588
[stable7] make sure to get the right list of users with access to the file when deleting a shared file
-rwxr-xr-xapps/files_encryption/tests/trashbin.php72
-rw-r--r--apps/files_trashbin/lib/trashbin.php6
2 files changed, 77 insertions, 1 deletions
diff --git a/apps/files_encryption/tests/trashbin.php b/apps/files_encryption/tests/trashbin.php
index 1fd8ff4c940..0b6498eab6c 100755
--- a/apps/files_encryption/tests/trashbin.php
+++ b/apps/files_encryption/tests/trashbin.php
@@ -38,6 +38,7 @@ use OCA\Encryption;
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;
@@ -60,6 +61,7 @@ class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase {
\OC_Hook::clear('OC_Filesystem');
\OC_Hook::clear('OC_User');
+ \OC_Hook::clear('OCP\\Share');
// trashbin hooks
\OCA\Files_Trashbin\Trashbin::registerHooks();
@@ -67,11 +69,24 @@ class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase {
// 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);
}
@@ -96,6 +111,9 @@ class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase {
// 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');
}
@@ -367,4 +385,58 @@ class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase {
. '.' . 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));
+ }
}
diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php
index 8aea6d1a5e3..11b4a4cc033 100644
--- a/apps/files_trashbin/lib/trashbin.php
+++ b/apps/files_trashbin/lib/trashbin.php
@@ -97,6 +97,7 @@ class Trashbin {
* 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();
@@ -109,6 +110,9 @@ class Trashbin {
}
self::setUpTrash($user);
+ if ($owner !== $user) {
+ self::setUpTrash($owner);
+ }
$view = new \OC\Files\View('/' . $user);
$path_parts = pathinfo($file_path);
@@ -279,7 +283,7 @@ class Trashbin {
$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);