]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix filesystem and encryption tests
authorJörn Friedrich Dreyer <jfd@butonic.de>
Thu, 2 Apr 2015 09:28:10 +0000 (11:28 +0200)
committerMorris Jobke <hey@morrisjobke.de>
Wed, 22 Apr 2015 09:34:17 +0000 (11:34 +0200)
apps/files_encryption/lib/util.php
apps/files_encryption/tests/hooks.php
tests/lib/files/filesystem.php

index a2397495dd5251ab30361b12233b27eb55856f07..cec316f39db303fee430101f76a2a106d6888ca6 100644 (file)
@@ -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;
+               }
        }
 
        /**
index 1ff3ac6619bc60eef70195e4eb309351b8150558..e125e66177013e4b36501d00875e5cab26f02a42 100644 (file)
@@ -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);
 
index 0a5ae40d994f1dd0634c574ed2449cddef1dc164..7ae84adb7d1ad409b23417b0ed0500c477853200 100644 (file)
@@ -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());
        }
 
        /**