示例#1
0
	public function testSetDefaultEncryptionModule() {
		global $defaultId;
		$defaultId = null;

		$this->config->expects($this->any())
			->method('getAppValue')
			->with('core', 'default_encryption_module')
			->willReturnCallback(function() { global $defaultId; return $defaultId; });

		$this->addNewEncryptionModule($this->manager, 0);
		$this->assertCount(1, $this->manager->getEncryptionModules());
		$this->addNewEncryptionModule($this->manager, 1);
		$this->assertCount(2, $this->manager->getEncryptionModules());

		// Default module is the first we set
		$defaultId = 'ID0';
		$this->assertEquals('ID0', $this->manager->getDefaultEncryptionModuleId());

		// Set to an existing module
		$this->config->expects($this->once())
			->method('setAppValue')
			->with('core', 'default_encryption_module', 'ID1');
		$this->assertTrue($this->manager->setDefaultEncryptionModule('ID1'));
		$defaultId = 'ID1';
		$this->assertEquals('ID1', $this->manager->getDefaultEncryptionModuleId());

		// Set to an unexisting module
		$this->assertFalse($this->manager->setDefaultEncryptionModule('ID2'));
		$this->assertEquals('ID1', $this->manager->getDefaultEncryptionModuleId());
	}
示例#2
0
 /**
  * prepare encryption modules to perform the decrypt all function
  *
  * @param $user
  * @return bool
  */
 protected function prepareEncryptionModules($user)
 {
     // prepare all encryption modules for decrypt all
     $encryptionModules = $this->encryptionManager->getEncryptionModules();
     foreach ($encryptionModules as $moduleDesc) {
         /** @var IEncryptionModule $module */
         $module = call_user_func($moduleDesc['callback']);
         if ($module->prepareDecryptAll($this->input, $this->output, $user) === false) {
             $this->output->writeln('Module "' . $moduleDesc['displayName'] . '" does not support the functionality to decrypt all files again or the initialization of the module failed!');
             return false;
         }
     }
     return true;
 }
示例#3
0
 public function testGetDefaultEncryptionModule()
 {
     $config = $this->getMock('\\OCP\\IConfig');
     $config->expects($this->any())->method('getAppValue')->willReturn(true);
     $em = $this->getMock('\\OCP\\Encryption\\IEncryptionModule');
     $em->expects($this->any())->method('getId')->willReturn(0);
     $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
     $m = new Manager($config);
     $m->registerEncryptionModule($em);
     $this->assertSame(1, count($m->getEncryptionModules()));
     $en0 = $m->getEncryptionModule(0);
     $this->assertEquals(0, $en0->getId());
 }