fix encryption manager to handle more than one encryption module
This commit is contained in:
parent
5bc9ababeb
commit
e2f714263f
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in New Issue