[Pkg-owncloud-commits] [owncloud] 339/457: Add a test for the fallback to the part file keys

David Prévot taffit at moszumanska.debian.org
Sun Jun 28 20:06:36 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 05c2fc72d81857dfea7dbf661b632075a19a48dd
Author: Joas Schilling <nickvergessen at owncloud.com>
Date:   Mon Jun 8 16:35:37 2015 +0200

    Add a test for the fallback to the part file keys
---
 tests/lib/encryption/keys/storage.php | 59 +++++++++++++++++++++++++++--------
 1 file changed, 46 insertions(+), 13 deletions(-)

diff --git a/tests/lib/encryption/keys/storage.php b/tests/lib/encryption/keys/storage.php
index 8af3821..2f3aa35 100644
--- a/tests/lib/encryption/keys/storage.php
+++ b/tests/lib/encryption/keys/storage.php
@@ -72,29 +72,62 @@ class StorageTest extends TestCase {
 		);
 	}
 
-	public function testGetFileKey() {
+	public function dataTestGetFileKey() {
+		return [
+			['/files/foo.txt', '/files/foo.txt', true, 'key'],
+			['/files/foo.txt.ocTransferId2111130212.part', '/files/foo.txt', true, 'key'],
+			['/files/foo.txt.ocTransferId2111130212.part', '/files/foo.txt', false, 'key2'],
+		];
+	}
+
+	/**
+	 * @dataProvider dataTestGetFileKey
+	 *
+	 * @param string $path
+	 * @param string $strippedPartialName
+	 * @param bool $originalKeyExists
+	 * @param string $expectedKeyContent
+	 */
+	public function testGetFileKey2($path, $strippedPartialName, $originalKeyExists, $expectedKeyContent) {
 		$this->util->expects($this->any())
 			->method('getUidAndFilename')
-			->willReturn(array('user1', '/files/foo.txt'));
+			->willReturnMap([
+				['user1/files/foo.txt', ['user1', '/files/foo.txt']],
+				['user1/files/foo.txt.ocTransferId2111130212.part', ['user1', '/files/foo.txt.ocTransferId2111130212.part']],
+			]);
 		// 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);
+			->willReturn('user1' . $strippedPartialName);
 		$this->util->expects($this->any())
 			->method('isSystemWideMountPoint')
 			->willReturn(false);
-		$this->view->expects($this->once())
-			->method('file_get_contents')
-			->with($this->equalTo('/user1/files_encryption/keys/files/foo.txt/encModule/fileKey'))
-			->willReturn('key');
-		$this->view->expects($this->once())
-			->method('file_exists')
-			->with($this->equalTo('/user1/files_encryption/keys/files/foo.txt/encModule/fileKey'))
-			->willReturn(true);
 
-		$this->assertSame('key',
-			$this->storage->getFileKey('user1/files/foo.txt', 'fileKey', 'encModule')
+		$this->view->expects($this->at(0))
+			->method('file_exists')
+			->with($this->equalTo('/user1/files_encryption/keys' . $strippedPartialName . '/encModule/fileKey'))
+			->willReturn($originalKeyExists);
+
+		if (!$originalKeyExists) {
+			$this->view->expects($this->at(1))
+				->method('file_exists')
+				->with($this->equalTo('/user1/files_encryption/keys' . $path . '/encModule/fileKey'))
+				->willReturn(true);
+
+			$this->view->expects($this->once())
+				->method('file_get_contents')
+				->with($this->equalTo('/user1/files_encryption/keys' . $path . '/encModule/fileKey'))
+				->willReturn('key2');
+		} else {
+			$this->view->expects($this->once())
+				->method('file_get_contents')
+				->with($this->equalTo('/user1/files_encryption/keys' . $strippedPartialName . '/encModule/fileKey'))
+				->willReturn('key');
+		}
+
+		$this->assertSame($expectedKeyContent,
+			$this->storage->getFileKey('user1' . $path, 'fileKey', 'encModule')
 		);
 	}
 

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