]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix encryption manager to handle more than one encryption module
authorBjoern Schiessle <schiessle@owncloud.com>
Wed, 18 Mar 2015 09:58:02 +0000 (10:58 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Tue, 7 Apr 2015 11:30:27 +0000 (13:30 +0200)
lib/private/encryption/manager.php
tests/lib/encryption/managertest.php

index 5164025239c59cd560aa0e8122cafa9ada4a03f6..fa50d32218dff648c6720f4ea6461faed0e06870 100644 (file)
@@ -106,12 +106,24 @@ class Manager implements \OCP\Encryption\IManager {
         * @return IEncryptionModule
         * @throws Exceptions\ModuleDoesNotExistsException
         */
-       public function getEncryptionModule($moduleId) {
-               if (isset($this->encryptionModules[$moduleId])) {
-                       return $this->encryptionModules[$moduleId];
-               } else {
-                       $message = "Module with id: $moduleId does not exists.";
-                       throw new Exceptions\ModuleDoesNotExistsException($message);
+       public function getEncryptionModule($moduleId = '') {
+               if (!empty($moduleId)) {
+                       if (isset($this->encryptionModules[$moduleId])) {
+                               return $this->encryptionModules[$moduleId];
+                       } else {
+                               $message = "Module with id: $moduleId does not exists.";
+                               throw new Exceptions\ModuleDoesNotExistsException($message);
+                       }
+               } else { // get default module and return this
+                                // For now we simply return the first module until we have a way
+                    // to enable multiple modules and define a default module
+                       $module = reset($this->encryptionModules);
+                       if ($module) {
+                               return $module;
+                       } else {
+                               $message = 'No encryption module registered';
+                               throw new Exceptions\ModuleDoesNotExistsException($message);
+                       }
                }
        }
 
index 5a0efa37b369d3ed7f090bc339df93ce7f3007d3..e5a1898515a9009769f1e9f3d9e746f0d648305f 100644 (file)
@@ -114,7 +114,7 @@ class ManagerTest extends TestCase {
 
        /**
         * @expectedException \OC\Encryption\Exceptions\ModuleAlreadyExistsException
-        * @expectedExceptionMessage At the moment it is not allowed to register more than one encryption module
+        * @expectedExceptionMessage Id "0" already used by encryption module "TestDummyModule0"
         */
        public function testModuleRegistration() {
                $config = $this->getMock('\OCP\IConfig');