[Pkg-owncloud-commits] [owncloud] 69/78: make sure to get the right list of users with access to the file, including the owner

David Prévot taffit at moszumanska.debian.org
Sun May 31 01:59:11 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit b4741cfa9617006e95ebb85731773d0e2360c202
Author: Bjoern Schiessle <schiessle at owncloud.com>
Date:   Thu May 28 16:11:42 2015 +0200

    make sure to get the right list of users with access to the file, including the owner
---
 apps/files_encryption/tests/trashbin.php | 72 ++++++++++++++++++++++++++++++++
 apps/files_trashbin/lib/trashbin.php     |  6 ++-
 2 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/apps/files_encryption/tests/trashbin.php b/apps/files_encryption/tests/trashbin.php
index 1fd8ff4..0b6498e 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 8aea6d1..11b4a4c 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);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list