diff options
author | Clark Tomlinson <fallen013@gmail.com> | 2015-04-16 09:34:47 -0400 |
---|---|---|
committer | Clark Tomlinson <fallen013@gmail.com> | 2015-04-16 09:34:47 -0400 |
commit | 1174ad0681bb82252a26b5ee44d5b2990171932b (patch) | |
tree | 77f5d7d2e65e9d5eeedb3f36f0576cb5196ba09e /tests | |
parent | c7e5e30b86733a22ac0d411e00537b10e0220ddd (diff) | |
parent | 959665003b408ed837066307350fb76b83beaa52 (diff) | |
download | nextcloud-server-1174ad0681bb82252a26b5ee44d5b2990171932b.tar.gz nextcloud-server-1174ad0681bb82252a26b5ee44d5b2990171932b.zip |
Merge pull request #15445 from owncloud/enc2_migration
add migration script from old encryption to new one
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/encryption/managertest.php | 95 | ||||
-rw-r--r-- | tests/lib/encryption/utiltest.php | 35 | ||||
-rw-r--r-- | tests/lib/files/storage/wrapper/encryption.php | 5 | ||||
-rw-r--r-- | tests/lib/files/stream/encryption.php | 5 |
4 files changed, 78 insertions, 62 deletions
diff --git a/tests/lib/encryption/managertest.php b/tests/lib/encryption/managertest.php index 4fcbc3b9983..f123f438311 100644 --- a/tests/lib/encryption/managertest.php +++ b/tests/lib/encryption/managertest.php @@ -7,36 +7,45 @@ use Test\TestCase; class ManagerTest extends TestCase { + /** @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); + + } + public function testManagerIsDisabled() { - $config = $this->getMock('\OCP\IConfig'); - $m = new Manager($config); - $this->assertFalse($m->isEnabled()); + $this->assertFalse($this->manager->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()); + $this->config->expects($this->any())->method('getAppValue')->willReturn(true); + $this->assertFalse($this->manager->isEnabled()); } public function testManagerIsDisabledIfDisabledButModules() { - $config = $this->getMock('\OCP\IConfig'); - $config->expects($this->any())->method('getAppValue')->willReturn(false); + $this->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()); + $this->manager->registerEncryptionModule($em); + $this->assertFalse($this->manager->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()); + $this->config->expects($this->any())->method('getSystemValue')->willReturn(true); + $this->config->expects($this->any())->method('getAppValue')->willReturn('yes'); + $this->assertTrue($this->manager->isEnabled()); } /** @@ -44,30 +53,26 @@ class ManagerTest extends TestCase { * @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'); + $this->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); + $this->manager->registerEncryptionModule($em); + $this->assertSame(1, count($this->manager->getEncryptionModules())); + $this->manager->registerEncryptionModule($em); } public function testModuleUnRegistration() { - $config = $this->getMock('\OCP\IConfig'); - $config->expects($this->any())->method('getAppValue')->willReturn(true); + $this->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->manager->registerEncryptionModule($em); $this->assertSame(1, - count($m->getEncryptionModules()) + count($this->manager->getEncryptionModules()) ); - $m->unregisterEncryptionModule($em); - $this->assertEmpty($m->getEncryptionModules()); + $this->manager->unregisterEncryptionModule($em); + $this->assertEmpty($this->manager->getEncryptionModules()); } /** @@ -75,40 +80,34 @@ class ManagerTest extends TestCase { * @expectedExceptionMessage Module with id: unknown does not exists. */ public function testGetEncryptionModuleUnknown() { - $config = $this->getMock('\OCP\IConfig'); - $config->expects($this->any())->method('getAppValue')->willReturn(true); + $this->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'); + $this->manager->registerEncryptionModule($em); + $this->assertSame(1, count($this->manager->getEncryptionModules())); + $this->manager->getEncryptionModule('unknown'); } public function testGetEncryptionModule() { - $config = $this->getMock('\OCP\IConfig'); - $config->expects($this->any())->method('getAppValue')->willReturn(true); + $this->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->manager->registerEncryptionModule($em); + $this->assertSame(1, count($this->manager->getEncryptionModules())); + $en0 = $this->manager->getEncryptionModule(0); $this->assertEquals(0, $en0->getId()); } public function testGetDefaultEncryptionModule() { - $config = $this->getMock('\OCP\IConfig'); - $config->expects($this->any())->method('getAppValue')->willReturn(true); + $this->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->manager->registerEncryptionModule($em); + $this->assertSame(1, count($this->manager->getEncryptionModules())); + $en0 = $this->manager->getEncryptionModule(0); $this->assertEquals(0, $en0->getId()); } diff --git a/tests/lib/encryption/utiltest.php b/tests/lib/encryption/utiltest.php index 03aefe61151..dc6205e16fd 100644 --- a/tests/lib/encryption/utiltest.php +++ b/tests/lib/encryption/utiltest.php @@ -21,8 +21,14 @@ class UtilTest extends TestCase { protected $userManager; /** @var \PHPUnit_Framework_MockObject_MockObject */ + protected $groupManager; + + /** @var \PHPUnit_Framework_MockObject_MockObject */ private $config; + /** @var \OC\Encryption\Util */ + private $util; + public function setUp() { parent::setUp(); $this->view = $this->getMockBuilder('OC\Files\View') @@ -33,18 +39,28 @@ class UtilTest extends TestCase { ->disableOriginalConstructor() ->getMock(); + $this->groupManager = $this->getMockBuilder('OC\Group\Manager') + ->disableOriginalConstructor() + ->getMock(); + $this->config = $this->getMockBuilder('OCP\IConfig') ->disableOriginalConstructor() ->getMock(); + $this->util = new Util( + $this->view, + $this->userManager, + $this->groupManager, + $this->config + ); + } /** * @dataProvider providesHeadersForEncryptionModule */ public function testGetEncryptionModuleId($expected, $header) { - $u = new Util($this->view, $this->userManager, $this->config); - $id = $u->getEncryptionModuleId($header); + $id = $this->util->getEncryptionModuleId($header); $this->assertEquals($expected, $id); } @@ -61,8 +77,7 @@ class UtilTest extends TestCase { */ public function testReadHeader($header, $expected, $moduleId) { $expected['oc_encryption_module'] = $moduleId; - $u = new Util($this->view, $this->userManager, $this->config); - $result = $u->readHeader($header); + $result = $this->util->readHeader($header); $this->assertSameSize($expected, $result); foreach ($expected as $key => $value) { $this->assertArrayHasKey($key, $result); @@ -78,8 +93,7 @@ class UtilTest extends TestCase { $em = $this->getMock('\OCP\Encryption\IEncryptionModule'); $em->expects($this->any())->method('getId')->willReturn($moduleId); - $u = new Util($this->view, $this->userManager, $this->config); - $result = $u->createHeader($header, $em); + $result = $this->util->createHeader($header, $em); $this->assertEquals($expected, $result); } @@ -102,23 +116,20 @@ class UtilTest extends TestCase { $em = $this->getMock('\OCP\Encryption\IEncryptionModule'); $em->expects($this->any())->method('getId')->willReturn('moduleId'); - $u = new Util($this->view, $this->userManager, $this->config); - $u->createHeader($header, $em); + $this->util->createHeader($header, $em); } /** * @dataProvider providePathsForTestIsExcluded */ - public function testIsEcluded($path, $expected) { + public function testIsExcluded($path, $expected) { $this->userManager ->expects($this->any()) ->method('userExists') ->will($this->returnCallback(array($this, 'isExcludedCallback'))); - $u = new Util($this->view, $this->userManager, $this->config); - $this->assertSame($expected, - $u->isExcluded($path) + $this->util->isExcluded($path) ); } diff --git a/tests/lib/files/storage/wrapper/encryption.php b/tests/lib/files/storage/wrapper/encryption.php index ec3770260aa..3256f772df7 100644 --- a/tests/lib/files/storage/wrapper/encryption.php +++ b/tests/lib/files/storage/wrapper/encryption.php @@ -34,8 +34,11 @@ class Encryption extends \Test\Files\Storage\Storage { $config = $this->getMockBuilder('\OCP\IConfig') ->disableOriginalConstructor() ->getMock(); + $groupManager = $this->getMockBuilder('\OC\Group\Manager') + ->disableOriginalConstructor() + ->getMock(); - $util = $this->getMock('\OC\Encryption\Util', ['getUidAndFilename'], [new View(), new \OC\User\Manager(), $config]); + $util = $this->getMock('\OC\Encryption\Util', ['getUidAndFilename'], [new View(), new \OC\User\Manager(), $groupManager, $config]); $util->expects($this->any()) ->method('getUidAndFilename') ->willReturnCallback(function ($path) { diff --git a/tests/lib/files/stream/encryption.php b/tests/lib/files/stream/encryption.php index 6964d203f18..f52fd0e16cc 100644 --- a/tests/lib/files/stream/encryption.php +++ b/tests/lib/files/stream/encryption.php @@ -27,12 +27,15 @@ class Encryption extends \Test\TestCase { $config = $this->getMockBuilder('\OCP\IConfig') ->disableOriginalConstructor() ->getMock(); + $groupManager = $this->getMockBuilder('\OC\Group\Manager') + ->disableOriginalConstructor() + ->getMock(); $file = $this->getMockBuilder('\OC\Encryption\File') ->disableOriginalConstructor() ->setMethods(['getAccessList']) ->getMock(); $file->expects($this->any())->method('getAccessList')->willReturn([]); - $util = $this->getMock('\OC\Encryption\Util', ['getUidAndFilename'], [new View(), new \OC\User\Manager(), $config]); + $util = $this->getMock('\OC\Encryption\Util', ['getUidAndFilename'], [new View(), new \OC\User\Manager(), $groupManager, $config]); $util->expects($this->any()) ->method('getUidAndFilename') ->willReturn(['user1', $internalPath]); |