aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Files/Stream/EncryptionTest.php
diff options
context:
space:
mode:
authorBjoern Schiessle <bjoern@schiessle.org>2017-05-31 15:26:10 +0200
committerBjoern Schiessle <bjoern@schiessle.org>2017-07-06 11:47:12 +0200
commitb43f6d295e8e3d69b032da55f8a2ef85e66f860e (patch)
treeab353c4e8a552317c876311c4a2bdaa3627c55c8 /tests/lib/Files/Stream/EncryptionTest.php
parentf186a5cfb1e118dbcf8ee5d072f1e9793017abe1 (diff)
downloadnextcloud-server-b43f6d295e8e3d69b032da55f8a2ef85e66f860e.tar.gz
nextcloud-server-b43f6d295e8e3d69b032da55f8a2ef85e66f860e.zip
update file system tests to take the master key into account
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
Diffstat (limited to 'tests/lib/Files/Stream/EncryptionTest.php')
-rw-r--r--tests/lib/Files/Stream/EncryptionTest.php37
1 files changed, 23 insertions, 14 deletions
diff --git a/tests/lib/Files/Stream/EncryptionTest.php b/tests/lib/Files/Stream/EncryptionTest.php
index e072dd6718d..1dc9dca0aad 100644
--- a/tests/lib/Files/Stream/EncryptionTest.php
+++ b/tests/lib/Files/Stream/EncryptionTest.php
@@ -58,7 +58,8 @@ class EncryptionTest extends \Test\TestCase {
/**
* @dataProvider dataProviderStreamOpen()
*/
- public function testStreamOpen($mode,
+ public function testStreamOpen($isMasterKeyUsed,
+ $mode,
$fullPath,
$fileExists,
$expectedSharePath,
@@ -69,6 +70,7 @@ class EncryptionTest extends \Test\TestCase {
// build mocks
$encryptionModuleMock = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
->disableOriginalConstructor()->getMock();
+ $encryptionModuleMock->expects($this->any())->method('needDetailedAccessList')->willReturn(!$isMasterKeyUsed);
$encryptionModuleMock->expects($this->once())
->method('getUnencryptedBlockSize')->willReturn(99);
$encryptionModuleMock->expects($this->once())
@@ -80,12 +82,15 @@ class EncryptionTest extends \Test\TestCase {
$fileMock = $this->getMockBuilder('\OC\Encryption\File')
->disableOriginalConstructor()->getMock();
- $fileMock->expects($this->once())->method('getAccessList')
- ->will($this->returnCallback(function($sharePath) use ($expectedSharePath) {
- $this->assertSame($expectedSharePath, $sharePath);
- return array();
- }));
-
+ if ($isMasterKeyUsed) {
+ $fileMock->expects($this->never())->method('getAccessList');
+ } else {
+ $fileMock->expects($this->once())->method('getAccessList')
+ ->will($this->returnCallback(function ($sharePath) use ($expectedSharePath) {
+ $this->assertSame($expectedSharePath, $sharePath);
+ return array();
+ }));
+ }
$utilMock = $this->getMockBuilder('\OC\Encryption\Util')
->disableOriginalConstructor()->getMock();
$utilMock->expects($this->any())
@@ -152,11 +157,14 @@ class EncryptionTest extends \Test\TestCase {
}
public function dataProviderStreamOpen() {
- return array(
- array('r', '/foo/bar/test.txt', true, '/foo/bar/test.txt', null, null, true),
- array('r', '/foo/bar/test.txt', false, '/foo/bar', null, null, true),
- array('w', '/foo/bar/test.txt', true, '/foo/bar/test.txt', 8192, 0, false),
- );
+ return [
+ [false, 'r', '/foo/bar/test.txt', true, '/foo/bar/test.txt', null, null, true],
+ [false, 'r', '/foo/bar/test.txt', false, '/foo/bar', null, null, true],
+ [false, 'w', '/foo/bar/test.txt', true, '/foo/bar/test.txt', 8192, 0, false],
+ [true, 'r', '/foo/bar/test.txt', true, '/foo/bar/test.txt', null, null, true],
+ [true, 'r', '/foo/bar/test.txt', false, '/foo/bar', null, null, true],
+ [true, 'w', '/foo/bar/test.txt', true, '/foo/bar/test.txt', 8192, 0, false],
+ ];
}
public function testWriteRead() {
@@ -193,7 +201,7 @@ class EncryptionTest extends \Test\TestCase {
$stream = $this->getStream($fileName, 'r', 6);
$this->assertEquals('barbar', fread($stream, 100));
fclose($stream);
-
+
unlink($fileName);
}
@@ -311,7 +319,7 @@ class EncryptionTest extends \Test\TestCase {
protected function buildMockModule() {
$encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
->disableOriginalConstructor()
- ->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'getUnencryptedBlockSize', 'isReadable', 'encryptAll', 'prepareDecryptAll', 'isReadyForUser'])
+ ->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'getUnencryptedBlockSize', 'isReadable', 'encryptAll', 'prepareDecryptAll', 'isReadyForUser', 'needDetailedAccessList'])
->getMock();
$encryptionModule->expects($this->any())->method('getId')->willReturn('UNIT_TEST_MODULE');
@@ -319,6 +327,7 @@ class EncryptionTest extends \Test\TestCase {
$encryptionModule->expects($this->any())->method('begin')->willReturn([]);
$encryptionModule->expects($this->any())->method('end')->willReturn('');
$encryptionModule->expects($this->any())->method('isReadable')->willReturn(true);
+ $encryptionModule->expects($this->any())->method('needDetailedAccessList')->willReturn(false);
$encryptionModule->expects($this->any())->method('encrypt')->willReturnCallback(function($data) {
// simulate different block size by adding some padding to the data
if (isset($data[6125])) {