2015-01-14 22:39:23 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Test\Encryption;
|
|
|
|
|
|
|
|
use OC\Encryption\Manager;
|
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
class ManagerTest extends TestCase {
|
|
|
|
|
2015-04-07 19:05:54 +03:00
|
|
|
/** @var Manager */
|
|
|
|
private $manager;
|
|
|
|
|
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $config;
|
|
|
|
|
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $logger;
|
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
$this->config = $this->getMock('\OCP\IConfig');
|
|
|
|
$this->logger = $this->getMock('\OCP\ILogger');
|
|
|
|
$this->manager = new Manager($this->config, $this->logger);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-14 22:39:23 +03:00
|
|
|
public function testManagerIsDisabled() {
|
2015-04-07 19:05:54 +03:00
|
|
|
$this->assertFalse($this->manager->isEnabled());
|
2015-01-14 22:39:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testManagerIsDisabledIfEnabledButNoModules() {
|
2015-04-07 19:05:54 +03:00
|
|
|
$this->config->expects($this->any())->method('getAppValue')->willReturn(true);
|
|
|
|
$this->assertFalse($this->manager->isEnabled());
|
2015-01-14 22:39:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testManagerIsDisabledIfDisabledButModules() {
|
2015-04-07 19:05:54 +03:00
|
|
|
$this->config->expects($this->any())->method('getAppValue')->willReturn(false);
|
2015-01-14 22:39:23 +03:00
|
|
|
$em = $this->getMock('\OCP\Encryption\IEncryptionModule');
|
2015-04-14 17:48:39 +03:00
|
|
|
$em->expects($this->any())->method('getId')->willReturn('id');
|
2015-01-14 22:39:23 +03:00
|
|
|
$em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
|
2015-04-14 17:48:39 +03:00
|
|
|
$this->manager->registerEncryptionModule('id', 'TestDummyModule0', function() use ($em) {return $em;});
|
2015-04-07 19:05:54 +03:00
|
|
|
$this->assertFalse($this->manager->isEnabled());
|
2015-01-14 22:39:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testManagerIsEnabled() {
|
2015-04-07 19:05:54 +03:00
|
|
|
$this->config->expects($this->any())->method('getSystemValue')->willReturn(true);
|
|
|
|
$this->config->expects($this->any())->method('getAppValue')->willReturn('yes');
|
|
|
|
$this->assertTrue($this->manager->isEnabled());
|
2015-01-14 22:39:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \OC\Encryption\Exceptions\ModuleAlreadyExistsException
|
2015-04-14 17:48:39 +03:00
|
|
|
* @expectedExceptionMessage Id "id" already used by encryption module "TestDummyModule0"
|
2015-01-14 22:39:23 +03:00
|
|
|
*/
|
|
|
|
public function testModuleRegistration() {
|
2015-04-07 19:05:54 +03:00
|
|
|
$this->config->expects($this->any())->method('getAppValue')->willReturn('yes');
|
2015-01-14 22:39:23 +03:00
|
|
|
$em = $this->getMock('\OCP\Encryption\IEncryptionModule');
|
2015-04-14 17:48:39 +03:00
|
|
|
$em->expects($this->any())->method('getId')->willReturn('id');
|
2015-01-14 22:39:23 +03:00
|
|
|
$em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
|
2015-04-14 17:48:39 +03:00
|
|
|
|
|
|
|
$this->manager->registerEncryptionModule('id', 'TestDummyModule0', function () use ($em) { return $em;});
|
2015-04-07 19:05:54 +03:00
|
|
|
$this->assertSame(1, count($this->manager->getEncryptionModules()));
|
2015-04-14 17:48:39 +03:00
|
|
|
$this->manager->registerEncryptionModule('id', 'TestDummyModule0', function () use ($em) { return $em;});
|
2015-01-14 22:39:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testModuleUnRegistration() {
|
2015-04-07 19:05:54 +03:00
|
|
|
$this->config->expects($this->any())->method('getAppValue')->willReturn(true);
|
2015-01-14 22:39:23 +03:00
|
|
|
$em = $this->getMock('\OCP\Encryption\IEncryptionModule');
|
2015-04-14 17:48:39 +03:00
|
|
|
$em->expects($this->any())->method('getId')->willReturn('id');
|
2015-01-14 22:39:23 +03:00
|
|
|
$em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
|
2015-04-14 17:48:39 +03:00
|
|
|
$this->manager->registerEncryptionModule('id', 'TestDummyModule0', function () use ($em) { return $em;});
|
2015-01-14 22:39:23 +03:00
|
|
|
$this->assertSame(1,
|
2015-04-07 19:05:54 +03:00
|
|
|
count($this->manager->getEncryptionModules())
|
2015-01-14 22:39:23 +03:00
|
|
|
);
|
2015-04-14 17:48:39 +03:00
|
|
|
|
|
|
|
$this->manager->unregisterEncryptionModule('id');
|
2015-04-07 19:05:54 +03:00
|
|
|
$this->assertEmpty($this->manager->getEncryptionModules());
|
2015-04-14 17:48:39 +03:00
|
|
|
|
2015-01-14 22:39:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \OC\Encryption\Exceptions\ModuleDoesNotExistsException
|
|
|
|
* @expectedExceptionMessage Module with id: unknown does not exists.
|
|
|
|
*/
|
|
|
|
public function testGetEncryptionModuleUnknown() {
|
2015-04-07 19:05:54 +03:00
|
|
|
$this->config->expects($this->any())->method('getAppValue')->willReturn(true);
|
2015-01-14 22:39:23 +03:00
|
|
|
$em = $this->getMock('\OCP\Encryption\IEncryptionModule');
|
2015-04-14 17:48:39 +03:00
|
|
|
$em->expects($this->any())->method('getId')->willReturn('id');
|
2015-01-14 22:39:23 +03:00
|
|
|
$em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
|
2015-04-14 17:48:39 +03:00
|
|
|
$this->manager->registerEncryptionModule('id', 'TestDummyModule0', function () use ($em) { return $em;});
|
2015-04-07 19:05:54 +03:00
|
|
|
$this->assertSame(1, count($this->manager->getEncryptionModules()));
|
|
|
|
$this->manager->getEncryptionModule('unknown');
|
2015-01-14 22:39:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetEncryptionModule() {
|
2015-04-07 19:05:54 +03:00
|
|
|
$this->config->expects($this->any())->method('getAppValue')->willReturn(true);
|
2015-01-14 22:39:23 +03:00
|
|
|
$em = $this->getMock('\OCP\Encryption\IEncryptionModule');
|
2015-04-14 17:48:39 +03:00
|
|
|
$em->expects($this->any())->method('getId')->willReturn('id');
|
2015-01-14 22:39:23 +03:00
|
|
|
$em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
|
2015-04-14 17:48:39 +03:00
|
|
|
$this->manager->registerEncryptionModule('id', 'TestDummyModule0', function () use ($em) { return $em;});
|
2015-04-07 19:05:54 +03:00
|
|
|
$this->assertSame(1, count($this->manager->getEncryptionModules()));
|
2015-04-14 17:48:39 +03:00
|
|
|
$en0 = $this->manager->getEncryptionModule('id');
|
|
|
|
$this->assertEquals('id', $en0->getId());
|
2015-01-14 22:39:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetDefaultEncryptionModule() {
|
2015-04-07 19:05:54 +03:00
|
|
|
$this->config->expects($this->any())->method('getAppValue')->willReturn(true);
|
2015-01-14 22:39:23 +03:00
|
|
|
$em = $this->getMock('\OCP\Encryption\IEncryptionModule');
|
2015-04-14 17:48:39 +03:00
|
|
|
$em->expects($this->any())->method('getId')->willReturn('id');
|
2015-01-14 22:39:23 +03:00
|
|
|
$em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
|
2015-04-14 17:48:39 +03:00
|
|
|
$this->manager->registerEncryptionModule('id', 'TestDummyModule0', function () use ($em) { return $em;});
|
2015-04-07 19:05:54 +03:00
|
|
|
$this->assertSame(1, count($this->manager->getEncryptionModules()));
|
2015-04-14 17:48:39 +03:00
|
|
|
$en0 = $this->manager->getEncryptionModule('id');
|
|
|
|
$this->assertEquals('id', $en0->getId());
|
2015-01-14 22:39:23 +03:00
|
|
|
}
|
2015-02-24 21:05:19 +03:00
|
|
|
|
2015-03-27 12:07:59 +03:00
|
|
|
// /**
|
|
|
|
// * @expectedException \OC\Encryption\Exceptions\ModuleAlreadyExistsException
|
|
|
|
// * @expectedExceptionMessage Id "0" already used by encryption module "TestDummyModule0"
|
|
|
|
// */
|
|
|
|
// public function testModuleRegistration() {
|
|
|
|
// $config = $this->getMock('\OCP\IConfig');
|
|
|
|
// $config->expects($this->any())->method('getSystemValue')->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->assertTrue($m->isEnabled());
|
|
|
|
// $m->registerEncryptionModule($em);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// public function testModuleUnRegistration() {
|
|
|
|
// $config = $this->getMock('\OCP\IConfig');
|
|
|
|
// $config->expects($this->any())->method('getSystemValue')->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->assertTrue($m->isEnabled());
|
|
|
|
// $m->unregisterEncryptionModule($em);
|
|
|
|
// $this->assertFalse($m->isEnabled());
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// /**
|
|
|
|
// * @expectedException \OC\Encryption\Exceptions\ModuleDoesNotExistsException
|
|
|
|
// * @expectedExceptionMessage Module with id: unknown does not exists.
|
|
|
|
// */
|
|
|
|
// public function testGetEncryptionModuleUnknown() {
|
|
|
|
// $config = $this->getMock('\OCP\IConfig');
|
|
|
|
// $config->expects($this->any())->method('getSystemValue')->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->assertTrue($m->isEnabled());
|
|
|
|
// $m->getEncryptionModule('unknown');
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// public function testGetEncryptionModule() {
|
|
|
|
// $config = $this->getMock('\OCP\IConfig');
|
|
|
|
// $config->expects($this->any())->method('getSystemValue')->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->assertTrue($m->isEnabled());
|
|
|
|
// $en0 = $m->getEncryptionModule(0);
|
|
|
|
// $this->assertEquals(0, $en0->getId());
|
|
|
|
// }
|
2015-01-14 22:39:23 +03:00
|
|
|
}
|