summaryrefslogtreecommitdiffstats
path: root/tests/lib/encryption/managertest.php
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2015-01-14 20:39:23 +0100
committerBjoern Schiessle <schiessle@owncloud.com>2015-03-26 20:56:51 +0100
commitff9c85ce60aac1098c741b7ea630d9fc545e3d96 (patch)
treeb51ab4917630680beb0499fae4a1d7c0ae100e34 /tests/lib/encryption/managertest.php
parenta9b4f0d8429dbeb612e80b168b6146890bb7843e (diff)
downloadnextcloud-server-ff9c85ce60aac1098c741b7ea630d9fc545e3d96.tar.gz
nextcloud-server-ff9c85ce60aac1098c741b7ea630d9fc545e3d96.zip
implement basic encryption functionallity in core to enable multiple encryption modules
Diffstat (limited to 'tests/lib/encryption/managertest.php')
-rw-r--r--tests/lib/encryption/managertest.php114
1 files changed, 114 insertions, 0 deletions
diff --git a/tests/lib/encryption/managertest.php b/tests/lib/encryption/managertest.php
new file mode 100644
index 00000000000..ab297bae0cb
--- /dev/null
+++ b/tests/lib/encryption/managertest.php
@@ -0,0 +1,114 @@
+<?php
+
+namespace Test\Encryption;
+
+use OC\Encryption\Manager;
+use Test\TestCase;
+
+class ManagerTest extends TestCase {
+
+ public function testManagerIsDisabled() {
+ $config = $this->getMock('\OCP\IConfig');
+ $m = new Manager($config);
+ $this->assertFalse($m->isEnabled());
+ }
+
+ public function testManagerIsDisabledIfEnabledButNoModules() {
+ $config = $this->getMock('\OCP\IConfig');
+ $config->expects($this->any())->method('getAppValue')->willReturn(true);
+ $m = new Manager($config);
+ $this->assertFalse($m->isEnabled());
+ }
+
+ public function testManagerIsDisabledIfDisabledButModules() {
+ $config = $this->getMock('\OCP\IConfig');
+ $config->expects($this->any())->method('getAppValue')->willReturn(false);
+ $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->assertFalse($m->isEnabled());
+ }
+
+ public function testManagerIsEnabled() {
+ $config = $this->getMock('\OCP\IConfig');
+ $config->expects($this->any())->method('getSystemValue')->willReturn(true);
+ $config->expects($this->any())->method('getAppValue')->willReturn('yes');
+ $m = new Manager($config);
+ $this->assertTrue($m->isEnabled());
+ }
+
+ /**
+ * @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('getAppValue')->willReturn('yes');
+ $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()));
+ $m->registerEncryptionModule($em);
+ }
+
+ public function testModuleUnRegistration() {
+ $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())
+ );
+ $m->unregisterEncryptionModule($em);
+ $this->assertEmpty($m->getEncryptionModules());
+ }
+
+ /**
+ * @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('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()));
+ $m->getEncryptionModule('unknown');
+ }
+
+ public function testGetEncryptionModule() {
+ $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());
+ }
+
+ 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());
+ }
+}