summaryrefslogtreecommitdiffstats
path: root/apps/encryption/tests
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2015-10-13 17:54:06 +0200
committerBjörn Schießle <bjoern@schiessle.org>2015-10-27 14:24:20 +0100
commit5fad45b2309426c5b91af1d87beaa9950eadc5ba (patch)
tree0c45e969b3a5b457c47169ff540df82f46ae14b3 /apps/encryption/tests
parentd7d5a3bab51d952e05965e84b784d7eff0efc9c9 (diff)
downloadnextcloud-server-5fad45b2309426c5b91af1d87beaa9950eadc5ba.tar.gz
nextcloud-server-5fad45b2309426c5b91af1d87beaa9950eadc5ba.zip
make encryption configurable for home storage
Diffstat (limited to 'apps/encryption/tests')
-rw-r--r--apps/encryption/tests/controller/SettingsControllerTest.php16
-rw-r--r--apps/encryption/tests/lib/UtilTest.php52
-rw-r--r--apps/encryption/tests/lib/crypto/encryptionTest.php36
3 files changed, 94 insertions, 10 deletions
diff --git a/apps/encryption/tests/controller/SettingsControllerTest.php b/apps/encryption/tests/controller/SettingsControllerTest.php
index 724a01522af..3b30e61a45b 100644
--- a/apps/encryption/tests/controller/SettingsControllerTest.php
+++ b/apps/encryption/tests/controller/SettingsControllerTest.php
@@ -56,6 +56,9 @@ class SettingsControllerTest extends TestCase {
/** @var \PHPUnit_Framework_MockObject_MockObject */
private $ocSessionMock;
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
+ private $utilMock;
+
protected function setUp() {
parent::setUp();
@@ -106,6 +109,10 @@ class SettingsControllerTest extends TestCase {
$this->sessionMock = $this->getMockBuilder('OCA\Encryption\Session')
->disableOriginalConstructor()->getMock();
+ $this->utilMock = $this->getMockBuilder('OCA\Encryption\Util')
+ ->disableOriginalConstructor()
+ ->getMock();
+
$this->controller = new SettingsController(
'encryption',
$this->requestMock,
@@ -115,7 +122,8 @@ class SettingsControllerTest extends TestCase {
$this->keyManagerMock,
$this->cryptMock,
$this->sessionMock,
- $this->ocSessionMock
+ $this->ocSessionMock,
+ $this->utilMock
);
}
@@ -234,4 +242,10 @@ class SettingsControllerTest extends TestCase {
$data['message']);
}
+ function testSetEncryptHomeStorage() {
+ $value = true;
+ $this->utilMock->expects($this->once())->method('setEncryptHomeStorage')->with($value);
+ $this->controller->setEncryptHomeStorage($value);
+ }
+
}
diff --git a/apps/encryption/tests/lib/UtilTest.php b/apps/encryption/tests/lib/UtilTest.php
index 723cc9fb910..d55b6b50b3e 100644
--- a/apps/encryption/tests/lib/UtilTest.php
+++ b/apps/encryption/tests/lib/UtilTest.php
@@ -39,6 +39,9 @@ class UtilTest extends TestCase {
/** @var \PHPUnit_Framework_MockObject_MockObject */
private $userManagerMock;
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
+ private $mountMock;
+
/** @var Util */
private $instance;
@@ -65,6 +68,7 @@ class UtilTest extends TestCase {
protected function setUp() {
parent::setUp();
+ $this->mountMock = $this->getMock('\OCP\Files\Mount\IMountPoint');
$this->filesMock = $this->getMock('OC\Files\View');
$this->userManagerMock = $this->getMock('\OCP\IUserManager');
@@ -151,4 +155,52 @@ class UtilTest extends TestCase {
];
}
+ /**
+ * @dataProvider dataTestShouldEncryptHomeStorage
+ * @param $returnValue return value from getAppValue()
+ * @param $expected
+ */
+ public function testShouldEncryptHomeStorage($returnValue, $expected) {
+ $this->configMock->expects($this->once())->method('getAppValue')
+ ->with('encryption', 'encryptHomeStorage', '1')
+ ->willReturn($returnValue);
+
+ $this->assertSame($expected,
+ $this->instance->shouldEncryptHomeStorage());
+ }
+
+ public function dataTestShouldEncryptHomeStorage() {
+ return [
+ ['1', true],
+ ['0', false]
+ ];
+ }
+
+ /**
+ * @dataProvider dataTestSetEncryptHomeStorage
+ * @param $value
+ * @param $expected
+ */
+ public function testSetEncryptHomeStorage($value, $expected) {
+ $this->configMock->expects($this->once())->method('setAppValue')
+ ->with('encryption', 'encryptHomeStorage', $expected);
+ $this->instance->setEncryptHomeStorage($value);
+ }
+
+ public function dataTestSetEncryptHomeStorage() {
+ return [
+ [true, '1'],
+ [false, '0']
+ ];
+ }
+
+ public function testGetStorage() {
+ $path = '/foo/bar.txt';
+ $this->filesMock->expects($this->once())->method('getMount')->with($path)
+ ->willReturn($this->mountMock);
+ $this->mountMock->expects($this->once())->method('getStorage')->willReturn(true);
+
+ $this->assertTrue($this->instance->getStorage($path));
+ }
+
}
diff --git a/apps/encryption/tests/lib/crypto/encryptionTest.php b/apps/encryption/tests/lib/crypto/encryptionTest.php
index f76bdfb6d61..138c1bc9446 100644
--- a/apps/encryption/tests/lib/crypto/encryptionTest.php
+++ b/apps/encryption/tests/lib/crypto/encryptionTest.php
@@ -55,9 +55,14 @@ class EncryptionTest extends TestCase {
/** @var \PHPUnit_Framework_MockObject_MockObject */
private $l10nMock;
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
+ private $storageMock;
+
public function setUp() {
parent::setUp();
+ $this->storageMock = $this->getMockBuilder('OCP\Files\Storage')
+ ->disableOriginalConstructor()->getMock();
$this->cryptMock = $this->getMockBuilder('OCA\Encryption\Crypto\Crypt')
->disableOriginalConstructor()
->getMock();
@@ -312,7 +317,17 @@ class EncryptionTest extends TestCase {
*
* @dataProvider dataTestShouldEncrypt
*/
- public function testShouldEncrypt($path, $expected) {
+ public function testShouldEncrypt($path, $shouldEncryptHomeStorage, $isHomeStorage, $expected) {
+ $this->utilMock->expects($this->once())->method('shouldEncryptHomeStorage')
+ ->willReturn($shouldEncryptHomeStorage);
+
+ if ($shouldEncryptHomeStorage === false) {
+ $this->storageMock->expects($this->once())->method('instanceOfStorage')
+ ->with('\OCP\Files\IHomeStorage')->willReturn($isHomeStorage);
+ $this->utilMock->expects($this->once())->method('getStorage')->with($path)
+ ->willReturn($this->storageMock);
+ }
+
$this->assertSame($expected,
$this->instance->shouldEncrypt($path)
);
@@ -320,14 +335,17 @@ class EncryptionTest extends TestCase {
public function dataTestShouldEncrypt() {
return array(
- array('/user1/files/foo.txt', true),
- array('/user1/files_versions/foo.txt', true),
- array('/user1/files_trashbin/foo.txt', true),
- array('/user1/some_folder/foo.txt', false),
- array('/user1/foo.txt', false),
- array('/user1/files', false),
- array('/user1/files_trashbin', false),
- array('/user1/files_versions', false),
+ array('/user1/files/foo.txt', true, true, true),
+ array('/user1/files_versions/foo.txt', true, true, true),
+ array('/user1/files_trashbin/foo.txt', true, true, true),
+ array('/user1/some_folder/foo.txt', true, true, false),
+ array('/user1/foo.txt', true, true, false),
+ array('/user1/files', true, true, false),
+ array('/user1/files_trashbin', true, true, false),
+ array('/user1/files_versions', true, true, false),
+ // test if shouldEncryptHomeStorage is set to false
+ array('/user1/files/foo.txt', false, true, false),
+ array('/user1/files_versions/foo.txt', false, false, true),
);
}