summaryrefslogtreecommitdiffstats
path: root/tests/lib/encryption
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2015-04-02 16:42:28 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2015-04-07 13:30:31 +0200
commit3d7404fe68474e72a520cb804d7c493e00215752 (patch)
treee53ab6622fb1298ff1072e2ef6371d1821d5d53d /tests/lib/encryption
parentfe74a0cb4f319ac9dccfce8c296365c3535ef84e (diff)
downloadnextcloud-server-3d7404fe68474e72a520cb804d7c493e00215752.tar.gz
nextcloud-server-3d7404fe68474e72a520cb804d7c493e00215752.zip
add unit tests to the keystorage
Diffstat (limited to 'tests/lib/encryption')
-rw-r--r--tests/lib/encryption/keys/storage.php85
1 files changed, 45 insertions, 40 deletions
diff --git a/tests/lib/encryption/keys/storage.php b/tests/lib/encryption/keys/storage.php
index be32f0e44a1..8ab46987f8c 100644
--- a/tests/lib/encryption/keys/storage.php
+++ b/tests/lib/encryption/keys/storage.php
@@ -28,6 +28,9 @@ use Test\TestCase;
class StorageTest extends TestCase {
+ /** @var Storage */
+ protected $storage;
+
/** @var \PHPUnit_Framework_MockObject_MockObject */
protected $util;
@@ -45,6 +48,8 @@ class StorageTest extends TestCase {
->disableOriginalConstructor()
->getMock();
+ $this->storage = new Storage('encModule', $this->view, $this->util);
+
}
public function testSetFileKey() {
@@ -63,10 +68,8 @@ class StorageTest extends TestCase {
$this->equalTo('key'))
->willReturn(strlen('key'));
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->setFileKey('user1/files/foo.txt', 'fileKey', 'key')
+ $this->storage->setFileKey('user1/files/foo.txt', 'fileKey', 'key')
);
}
@@ -89,10 +92,8 @@ class StorageTest extends TestCase {
->with($this->equalTo('/user1/files_encryption/keys/files/foo.txt/encModule/fileKey'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertSame('key',
- $storage->getFileKey('user1/files/foo.txt', 'fileKey')
+ $this->storage->getFileKey('user1/files/foo.txt', 'fileKey')
);
}
@@ -112,10 +113,8 @@ class StorageTest extends TestCase {
$this->equalTo('key'))
->willReturn(strlen('key'));
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->setFileKey('user1/files/foo.txt', 'fileKey', 'key')
+ $this->storage->setFileKey('user1/files/foo.txt', 'fileKey', 'key')
);
}
@@ -138,10 +137,8 @@ class StorageTest extends TestCase {
->with($this->equalTo('/files_encryption/keys/files/foo.txt/encModule/fileKey'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertSame('key',
- $storage->getFileKey('user1/files/foo.txt', 'fileKey')
+ $this->storage->getFileKey('user1/files/foo.txt', 'fileKey')
);
}
@@ -152,10 +149,8 @@ class StorageTest extends TestCase {
$this->equalTo('key'))
->willReturn(strlen('key'));
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->setSystemUserKey('shareKey_56884', 'key')
+ $this->storage->setSystemUserKey('shareKey_56884', 'key')
);
}
@@ -166,10 +161,8 @@ class StorageTest extends TestCase {
$this->equalTo('key'))
->willReturn(strlen('key'));
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->setUserKey('user1', 'publicKey', 'key')
+ $this->storage->setUserKey('user1', 'publicKey', 'key')
);
}
@@ -183,10 +176,8 @@ class StorageTest extends TestCase {
->with($this->equalTo('/files_encryption/encModule/shareKey_56884'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertSame('key',
- $storage->getSystemUserKey('shareKey_56884')
+ $this->storage->getSystemUserKey('shareKey_56884')
);
}
@@ -200,10 +191,8 @@ class StorageTest extends TestCase {
->with($this->equalTo('/user1/files_encryption/encModule/user1.publicKey'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertSame('key',
- $storage->getUserKey('user1', 'publicKey')
+ $this->storage->getUserKey('user1', 'publicKey')
);
}
@@ -213,10 +202,8 @@ class StorageTest extends TestCase {
->with($this->equalTo('/user1/files_encryption/encModule/user1.publicKey'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->deleteUserKey('user1', 'publicKey')
+ $this->storage->deleteUserKey('user1', 'publicKey')
);
}
@@ -226,10 +213,8 @@ class StorageTest extends TestCase {
->with($this->equalTo('/files_encryption/encModule/shareKey_56884'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->deleteSystemUserKey('shareKey_56884')
+ $this->storage->deleteSystemUserKey('shareKey_56884')
);
}
@@ -248,10 +233,8 @@ class StorageTest extends TestCase {
->with($this->equalTo('/files_encryption/keys/files/foo.txt/encModule/fileKey'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->deleteFileKey('user1/files/foo.txt', 'fileKey')
+ $this->storage->deleteFileKey('user1/files/foo.txt', 'fileKey')
);
}
@@ -270,10 +253,8 @@ class StorageTest extends TestCase {
->with($this->equalTo('/user1/files_encryption/keys/files/foo.txt/encModule/fileKey'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->deleteFileKey('user1/files/foo.txt', 'fileKey')
+ $this->storage->deleteFileKey('user1/files/foo.txt', 'fileKey')
);
}
@@ -300,8 +281,7 @@ class StorageTest extends TestCase {
->method('isSystemWideMountPoint')
->willReturn($systemWideMount);
- $storage = new Storage('encModule', $this->view, $this->util);
- $storage->renameKeys($source, $target);
+ $this->storage->renameKeys($source, $target);
}
/**
@@ -327,8 +307,7 @@ class StorageTest extends TestCase {
->method('isSystemWideMountPoint')
->willReturn($systemWideMount);
- $storage = new Storage('encModule', $this->view, $this->util);
- $storage->copyKeys($source, $target);
+ $this->storage->copyKeys($source, $target);
}
public function getUidAndFilenameCallback() {
@@ -353,4 +332,30 @@ class StorageTest extends TestCase {
);
}
+ public function testKeySetPreparation() {
+ $this->view->expects($this->any())
+ ->method('file_exists')
+ ->willReturn(false);
+ $this->view->expects($this->any())
+ ->method('is_dir')
+ ->willReturn(false);
+ $this->view->expects($this->any())
+ ->method('mkdir')
+ ->will($this->returnCallback(array($this, 'mkdirCallback')));
+
+ $this->mkdirStack = array(
+ '/user1/files_encryption/keys/foo',
+ '/user1/files_encryption/keys',
+ '/user1/files_encryption',
+ '/user1');
+
+ \Test_Helper::invokePrivate($this->storage, 'keySetPreparation', array('/user1/files_encryption/keys/foo'));
+ }
+
+ public function mkdirCallback() {
+ $args = func_get_args();
+ $expected = array_pop($this->mkdirStack);
+ $this->assertSame($expected, $args[0]);
+ }
+
}