summaryrefslogtreecommitdiffstats
path: root/tests/lib/encryption/keys/storage.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/encryption/keys/storage.php')
-rw-r--r--tests/lib/encryption/keys/storage.php59
1 files changed, 53 insertions, 6 deletions
diff --git a/tests/lib/encryption/keys/storage.php b/tests/lib/encryption/keys/storage.php
index 2f3aa3527b9..b5b91f886a3 100644
--- a/tests/lib/encryption/keys/storage.php
+++ b/tests/lib/encryption/keys/storage.php
@@ -37,6 +37,9 @@ class StorageTest extends TestCase {
/** @var \PHPUnit_Framework_MockObject_MockObject */
protected $view;
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
+ protected $config;
+
public function setUp() {
parent::setUp();
@@ -48,6 +51,10 @@ class StorageTest extends TestCase {
->disableOriginalConstructor()
->getMock();
+ $this->config = $this->getMockBuilder('OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock();
+
$this->storage = new Storage($this->view, $this->util);
}
@@ -88,7 +95,7 @@ class StorageTest extends TestCase {
* @param bool $originalKeyExists
* @param string $expectedKeyContent
*/
- public function testGetFileKey2($path, $strippedPartialName, $originalKeyExists, $expectedKeyContent) {
+ public function testGetFileKey($path, $strippedPartialName, $originalKeyExists, $expectedKeyContent) {
$this->util->expects($this->any())
->method('getUidAndFilename')
->willReturnMap([
@@ -414,9 +421,12 @@ class StorageTest extends TestCase {
*
* @param string $path
* @param boolean $systemWideMountPoint
+ * @param string $storageRoot
* @param string $expected
*/
- public function testGetPathToKeys($path, $systemWideMountPoint, $expected) {
+ public function testGetPathToKeys($path, $systemWideMountPoint, $storageRoot, $expected) {
+
+ $this->invokePrivate($this->storage, 'root_dir', [$storageRoot]);
$this->util->expects($this->any())
->method('getUidAndFilename')
@@ -431,10 +441,12 @@ class StorageTest extends TestCase {
}
public function dataTestGetPathToKeys() {
- return array(
- array('/user1/files/source.txt', false, '/user1/files_encryption/keys/files/source.txt/'),
- array('/user1/files/source.txt', true, '/files_encryption/keys/files/source.txt/')
- );
+ return [
+ ['/user1/files/source.txt', false, '', '/user1/files_encryption/keys/files/source.txt/'],
+ ['/user1/files/source.txt', true, '', '/files_encryption/keys/files/source.txt/'],
+ ['/user1/files/source.txt', false, 'storageRoot', '/storageRoot/user1/files_encryption/keys/files/source.txt/'],
+ ['/user1/files/source.txt', true, 'storageRoot', '/storageRoot/files_encryption/keys/files/source.txt/'],
+ ];
}
public function testKeySetPreparation() {
@@ -463,4 +475,39 @@ class StorageTest extends TestCase {
$this->assertSame($expected, $args[0]);
}
+ /**
+ * @dataProvider dataTestGetFileKeyDir
+ *
+ * @param bool $isSystemWideMountPoint
+ * @param string $storageRoot
+ * @param string $expected
+ */
+ public function testGetFileKeyDir($isSystemWideMountPoint, $storageRoot, $expected) {
+
+ $path = '/user1/files/foo/bar.txt';
+ $owner = 'user1';
+ $relativePath = '/foo/bar.txt';
+
+ $this->invokePrivate($this->storage, 'root_dir', [$storageRoot]);
+
+ $this->util->expects($this->once())->method('isSystemWideMountPoint')
+ ->willReturn($isSystemWideMountPoint);
+ $this->util->expects($this->once())->method('getUidAndFilename')
+ ->with($path)->willReturn([$owner, $relativePath]);
+
+ $this->assertSame($expected,
+ $this->invokePrivate($this->storage, 'getFileKeyDir', ['OC_DEFAULT_MODULE', $path])
+ );
+
+ }
+
+ public function dataTestGetFileKeyDir() {
+ return [
+ [false, '', '/user1/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'],
+ [true, '', '/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'],
+ [false, 'newStorageRoot', '/newStorageRoot/user1/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'],
+ [true, 'newStorageRoot', '/newStorageRoot/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'],
+ ];
+ }
+
}