fix encryption manager to handle more than one encryption module

This commit is contained in:
Bjoern Schiessle 2015-03-18 10:58:02 +01:00 committed by Thomas Müller
parent 5bc9ababeb
commit e2f714263f
2 changed files with 19 additions and 7 deletions

View 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);
}
}
}

View 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');