[Pkg-owncloud-commits] [owncloud] 119/457: remove part file extension before we read a filekey to reuse a existing key if possible, otherwise stuff like versioning will break

David Prévot taffit at moszumanska.debian.org
Sun Jun 28 20:05:43 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 fef75e5417206fcc36d979022f0f9921a743a3ae
Author: Bjoern Schiessle <schiessle at owncloud.com>
Date:   Fri May 22 12:12:31 2015 +0200

    remove part file extension before we read a filekey to reuse a existing key if possible, otherwise stuff like versioning will break
---
 lib/private/encryption/keys/storage.php |  3 ++-
 tests/lib/encryption/keys/storage.php   |  4 +++-
 tests/lib/encryption/utiltest.php       | 20 ++++++++++++++++++++
 3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/lib/private/encryption/keys/storage.php b/lib/private/encryption/keys/storage.php
index 6aa00c5..f90548f 100644
--- a/lib/private/encryption/keys/storage.php
+++ b/lib/private/encryption/keys/storage.php
@@ -70,7 +70,8 @@ class Storage implements IStorage {
 	 * @inheritdoc
 	 */
 	public function getFileKey($path, $keyId, $encryptionModuleId) {
-		$keyDir = $this->getFileKeyDir($encryptionModuleId, $path);
+		$realFile = $this->util->stripPartialFileExtension($path);
+		$keyDir = $this->getFileKeyDir($encryptionModuleId, $realFile);
 		return $this->getKey($keyDir . $keyId);
 	}
 
diff --git a/tests/lib/encryption/keys/storage.php b/tests/lib/encryption/keys/storage.php
index e67103f..fa623ac 100644
--- a/tests/lib/encryption/keys/storage.php
+++ b/tests/lib/encryption/keys/storage.php
@@ -76,7 +76,9 @@ class StorageTest extends TestCase {
 		$this->util->expects($this->any())
 			->method('getUidAndFilename')
 			->willReturn(array('user1', '/files/foo.txt'));
-		$this->util->expects($this->any())
+		// we need to strip away the part file extension in order to reuse a
+		// existing key if it exists, otherwise versions will break
+		$this->util->expects($this->once())
 			->method('stripPartialFileExtension')
 			->willReturnArgument(0);
 		$this->util->expects($this->any())
diff --git a/tests/lib/encryption/utiltest.php b/tests/lib/encryption/utiltest.php
index 0154fa3..d3a4e21 100644
--- a/tests/lib/encryption/utiltest.php
+++ b/tests/lib/encryption/utiltest.php
@@ -174,4 +174,24 @@ class UtilTest extends TestCase {
 		);
 	}
 
+	/**
+	 * @dataProvider dataTestStripPartialFileExtension
+	 *
+	 * @param string $path
+	 * @param string $expected
+	 */
+	public function testStripPartialFileExtension($path, $expected) {
+		$this->assertSame($expected,
+			$this->util->stripPartialFileExtension($path));
+	}
+
+	public function dataTestStripPartialFileExtension() {
+		return array(
+			array('/foo/test.txt', '/foo/test.txt'),
+			array('/foo/test.txt.part', '/foo/test.txt'),
+			array('/foo/test.txt.ocTransferId7567846853.part', '/foo/test.txt'),
+			array('/foo/test.txt.ocTransferId7567.part', '/foo/test.txt'),
+		);
+	}
+
 }

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