[Pkg-owncloud-commits] [owncloud] 36/215: update share keys if file gets copied

David Prévot taffit at moszumanska.debian.org
Tue May 5 01:01:18 UTC 2015


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

taffit pushed a commit to branch stable8
in repository owncloud.

commit 2646bccb83d06f575722e3fb8c5bd87ed42775c9
Author: Bjoern Schiessle <schiessle at owncloud.com>
Date:   Thu Apr 23 17:06:55 2015 +0200

    update share keys if file gets copied
---
 lib/private/files/storage/wrapper/encryption.php |  6 +-
 tests/lib/files/storage/wrapper/encryption.php   | 83 +++++++++++++++++++-----
 2 files changed, 70 insertions(+), 19 deletions(-)

diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php
index 089da94..0f6096a 100644
--- a/lib/private/files/storage/wrapper/encryption.php
+++ b/lib/private/files/storage/wrapper/encryption.php
@@ -256,9 +256,9 @@ class Encryption extends Wrapper {
 		$result = $this->storage->copy($path1, $path2);
 		if ($result) {
 			$target = $this->getFullPath($path2);
-			$encryptionModule = $this->getEncryptionModule($path2);
-			if ($encryptionModule) {
-				$this->keyStorage->copyKeys($source, $target);
+			$this->keyStorage->copyKeys($source, $target);
+			if (dirname($source) !== dirname($target) && $this->util->isFile($target)) {
+				$this->update->update($target);
 			}
 		}
 
diff --git a/tests/lib/files/storage/wrapper/encryption.php b/tests/lib/files/storage/wrapper/encryption.php
index 12309c5..f22f02f 100644
--- a/tests/lib/files/storage/wrapper/encryption.php
+++ b/tests/lib/files/storage/wrapper/encryption.php
@@ -27,6 +27,18 @@ class Encryption extends \Test\Files\Storage\Storage {
 	 */
 	private $util;
 
+
+	/**
+	 * @var \OC\Encryption\Manager | \PHPUnit_Framework_MockObject_MockObject
+	 */
+	private $encryptionManager;
+
+	/**
+	 * @var \OCP\Encryption\IEncryptionModule | \PHPUnit_Framework_MockObject_MockObject
+	 */
+	private $encryptionModule;
+
+
 	/**
 	 * @var \OC\Encryption\Update | \PHPUnit_Framework_MockObject_MockObject
 	 */
@@ -37,17 +49,17 @@ class Encryption extends \Test\Files\Storage\Storage {
 		parent::setUp();
 
 		$mockModule = $this->buildMockModule();
-		$encryptionManager = $this->getMockBuilder('\OC\Encryption\Manager')
+		$this->encryptionManager = $this->getMockBuilder('\OC\Encryption\Manager')
 			->disableOriginalConstructor()
 			->setMethods(['getDefaultEncryptionModule', 'getEncryptionModule', 'isEnabled'])
 			->getMock();
-		$encryptionManager->expects($this->any())
+		$this->encryptionManager->expects($this->any())
 			->method('getDefaultEncryptionModule')
 			->willReturn($mockModule);
-		$encryptionManager->expects($this->any())
+		$this->encryptionManager->expects($this->any())
 			->method('getEncryptionModule')
 			->willReturn($mockModule);
-		$encryptionManager->expects($this->any())
+		$this->encryptionManager->expects($this->any())
 			->method('isEnabled')
 			->willReturn(true);
 
@@ -89,7 +101,7 @@ class Encryption extends \Test\Files\Storage\Storage {
 			'mountPoint' => '/',
 			'mount' => $mount
 		],
-			$encryptionManager, $this->util, $logger, $file, null, $this->keyStore, $this->update
+			$this->encryptionManager, $this->util, $logger, $file, null, $this->keyStore, $this->update
 		);
 	}
 
@@ -97,21 +109,21 @@ class Encryption extends \Test\Files\Storage\Storage {
 	 * @return \PHPUnit_Framework_MockObject_MockObject
 	 */
 	protected function buildMockModule() {
-		$encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
+		$this->encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
 			->disableOriginalConstructor()
 			->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'getUnencryptedBlockSize'])
 			->getMock();
 
-		$encryptionModule->expects($this->any())->method('getId')->willReturn('UNIT_TEST_MODULE');
-		$encryptionModule->expects($this->any())->method('getDisplayName')->willReturn('Unit test module');
-		$encryptionModule->expects($this->any())->method('begin')->willReturn([]);
-		$encryptionModule->expects($this->any())->method('end')->willReturn('');
-		$encryptionModule->expects($this->any())->method('encrypt')->willReturnArgument(0);
-		$encryptionModule->expects($this->any())->method('decrypt')->willReturnArgument(0);
-		$encryptionModule->expects($this->any())->method('update')->willReturn(true);
-		$encryptionModule->expects($this->any())->method('shouldEncrypt')->willReturn(true);
-		$encryptionModule->expects($this->any())->method('getUnencryptedBlockSize')->willReturn(8192);
-		return $encryptionModule;
+		$this->encryptionModule->expects($this->any())->method('getId')->willReturn('UNIT_TEST_MODULE');
+		$this->encryptionModule->expects($this->any())->method('getDisplayName')->willReturn('Unit test module');
+		$this->encryptionModule->expects($this->any())->method('begin')->willReturn([]);
+		$this->encryptionModule->expects($this->any())->method('end')->willReturn('');
+		$this->encryptionModule->expects($this->any())->method('encrypt')->willReturnArgument(0);
+		$this->encryptionModule->expects($this->any())->method('decrypt')->willReturnArgument(0);
+		$this->encryptionModule->expects($this->any())->method('update')->willReturn(true);
+		$this->encryptionModule->expects($this->any())->method('shouldEncrypt')->willReturn(true);
+		$this->encryptionModule->expects($this->any())->method('getUnencryptedBlockSize')->willReturn(8192);
+		return $this->encryptionModule;
 	}
 
 	/**
@@ -151,4 +163,43 @@ class Encryption extends \Test\Files\Storage\Storage {
 			array('source', '/subFolder/target', true),
 		);
 	}
+
+	/**
+	 * @dataProvider dataTestCopy
+	 *
+	 * @param string $source
+	 * @param string $target
+	 * @param boolean $shouldUpdate
+	 */
+	public function testCopy($source, $target, $shouldUpdate) {
+		$this->keyStore
+			->expects($this->once())
+			->method('copyKeys');
+		$this->util->expects($this->any())
+			->method('isFile')->willReturn(true);
+		if ($shouldUpdate) {
+			$this->update->expects($this->once())
+				->method('update');
+		} else {
+			$this->update->expects($this->never())
+				->method('update');
+		}
+
+		$this->instance->mkdir($source);
+		$this->instance->mkdir(dirname($target));
+		$this->instance->copy($source, $target);
+	}
+
+	/**
+	 * data provider for testRename()
+	 *
+	 * @return array
+	 */
+	public function dataTestCopy() {
+		return array(
+			array('source', 'target', false),
+			array('source', '/subFolder/target', true),
+		);
+	}
+
 }

-- 
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