[Pkg-owncloud-commits] [owncloud] 46/78: fix filesystem and encryption tests

David Prévot taffit at moszumanska.debian.org
Sun May 31 01:59:07 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 919241cdda030f173ea1431f6b4745ceaf45eb63
Author: Jörn Friedrich Dreyer <jfd at butonic.de>
Date:   Thu Apr 2 11:28:10 2015 +0200

    fix filesystem and encryption tests
---
 apps/files_encryption/lib/util.php    | 11 +++++++++--
 apps/files_encryption/tests/hooks.php | 24 +++++++++++++++---------
 tests/lib/files/filesystem.php        |  9 ++-------
 3 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index a239749..cec316f 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -23,6 +23,7 @@
  */
 
 namespace OCA\Encryption;
+use OC\User\NoUserException;
 
 /**
  * Class for utilities relating to encrypted file storage system
@@ -903,8 +904,14 @@ class Util {
 		) {
 			return true;
 		}
-		$util = new Util($this->view, $user);
-		return $util->ready();
+		try {
+			$util = new Util($this->view, $user);
+			return $util->ready();
+		} catch (NoUserException $e) {
+			\OCP\Util::writeLog('Encryption library',
+				'No User object for '.$user, \OCP\Util::DEBUG);
+			return false;
+		}
 	}
 
 	/**
diff --git a/apps/files_encryption/tests/hooks.php b/apps/files_encryption/tests/hooks.php
index 1ff3ac6..e125e66 100644
--- a/apps/files_encryption/tests/hooks.php
+++ b/apps/files_encryption/tests/hooks.php
@@ -37,6 +37,7 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase {
 
 	const TEST_ENCRYPTION_HOOKS_USER1 = "test-encryption-hooks-user1.dot";
 	const TEST_ENCRYPTION_HOOKS_USER2 = "test-encryption-hooks-user2.dot";
+	const TEST_ENCRYPTION_HOOKS_USER3 = "test-encryption-hooks-user3.dot";
 
 	/** @var \OC\Files\View */
 	public $user1View;     // view on /data/user1/files
@@ -120,6 +121,7 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase {
 		// cleanup test user
 		\OC_User::deleteUser(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
 		\OC_User::deleteUser(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
+		\OC_User::deleteUser(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER3);
 
 		\OC_Hook::clear();
 		\OC_FileProxy::clearProxies();
@@ -444,31 +446,35 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase {
 		$view = new \OC\Files\View();
 
 		// set user password for the first time
-		\OCA\Encryption\Hooks::postCreateUser(array('uid' => 'newUser', 'password' => 'newUserPassword'));
+		\OC_User::createUser(self::TEST_ENCRYPTION_HOOKS_USER3, 'newUserPassword');
+		\OCA\Encryption\Hooks::postCreateUser(array(
+			'uid' => self::TEST_ENCRYPTION_HOOKS_USER3,
+			'password' => 'newUserPassword')
+		);
 
-		$this->assertTrue($view->file_exists('public-keys/newUser.public.key'));
-		$this->assertTrue($view->file_exists('newUser/files_encryption/newUser.private.key'));
+		$this->assertTrue($view->file_exists('public-keys/'.self::TEST_ENCRYPTION_HOOKS_USER3.'.public.key'));
+		$this->assertTrue($view->file_exists(self::TEST_ENCRYPTION_HOOKS_USER3.'/files_encryption/'.self::TEST_ENCRYPTION_HOOKS_USER3.'.private.key'));
 
 		// check if we are able to decrypt the private key
-		$encryptedKey = \OCA\Encryption\Keymanager::getPrivateKey($view, 'newUser');
+		$encryptedKey = \OCA\Encryption\Keymanager::getPrivateKey($view, self::TEST_ENCRYPTION_HOOKS_USER3);
 		$privateKey = \OCA\Encryption\Crypt::decryptPrivateKey($encryptedKey, 'newUserPassword');
 		$this->assertTrue(is_string($privateKey));
 
 		// change the password before the user logged-in for the first time,
 		// we can replace the encryption keys
-		\OCA\Encryption\Hooks::setPassphrase(array('uid' => 'newUser', 'password' => 'passwordChanged'));
+		\OCA\Encryption\Hooks::setPassphrase(array('uid' => self::TEST_ENCRYPTION_HOOKS_USER3, 'password' => 'passwordChanged'));
 
-		$encryptedKey = \OCA\Encryption\Keymanager::getPrivateKey($view, 'newUser');
+		$encryptedKey = \OCA\Encryption\Keymanager::getPrivateKey($view, self::TEST_ENCRYPTION_HOOKS_USER3);
 		$privateKey = \OCA\Encryption\Crypt::decryptPrivateKey($encryptedKey, 'passwordChanged');
 		$this->assertTrue(is_string($privateKey));
 
 		// now create a files folder to simulate a already used account
-		$view->mkdir('/newUser/files');
+		$view->mkdir('/'.self::TEST_ENCRYPTION_HOOKS_USER3.'/files');
 
 		// change the password after the user logged in, now the password should not change
-		\OCA\Encryption\Hooks::setPassphrase(array('uid' => 'newUser', 'password' => 'passwordChanged2'));
+		\OCA\Encryption\Hooks::setPassphrase(array('uid' => self::TEST_ENCRYPTION_HOOKS_USER3, 'password' => 'passwordChanged2'));
 
-		$encryptedKey = \OCA\Encryption\Keymanager::getPrivateKey($view, 'newUser');
+		$encryptedKey = \OCA\Encryption\Keymanager::getPrivateKey($view, self::TEST_ENCRYPTION_HOOKS_USER3);
 		$privateKey = \OCA\Encryption\Crypt::decryptPrivateKey($encryptedKey, 'passwordChanged2');
 		$this->assertFalse($privateKey);
 
diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php
index 0a5ae40..7ae84ad 100644
--- a/tests/lib/files/filesystem.php
+++ b/tests/lib/files/filesystem.php
@@ -191,19 +191,14 @@ class Filesystem extends \Test\TestCase {
 	}
 
 	/**
-	 * Tests that a local storage mount is used when passed user
-	 * does not exist.
+	 * Tests that an exception is thrown when passed user does not exist.
+	 * @expectedException \OC\User\NoUserException
 	 */
 	public function testLocalMountWhenUserDoesNotExist() {
 		$datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data");
 		$userId = uniqid('user_');
 
 		\OC\Files\Filesystem::initMountPoints($userId);
-
-		$homeMount = \OC\Files\Filesystem::getStorage('/' . $userId . '/');
-
-		$this->assertTrue($homeMount->instanceOfStorage('\OC\Files\Storage\Local'));
-		$this->assertEquals('local::' . $datadir . '/' . $userId . '/', $homeMount->getId());
 	}
 
 	/**

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