update file system tests to take the master key into account
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
This commit is contained in:
parent
f186a5cfb1
commit
b43f6d295e
|
@ -212,7 +212,7 @@ class EncryptionTest extends Storage {
|
||||||
protected function buildMockModule() {
|
protected function buildMockModule() {
|
||||||
$this->encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
|
$this->encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
|
||||||
->disableOriginalConstructor()
|
->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();
|
->getMock();
|
||||||
|
|
||||||
$this->encryptionModule->expects($this->any())->method('getId')->willReturn('UNIT_TEST_MODULE');
|
$this->encryptionModule->expects($this->any())->method('getId')->willReturn('UNIT_TEST_MODULE');
|
||||||
|
@ -225,6 +225,7 @@ class EncryptionTest extends Storage {
|
||||||
$this->encryptionModule->expects($this->any())->method('shouldEncrypt')->willReturn(true);
|
$this->encryptionModule->expects($this->any())->method('shouldEncrypt')->willReturn(true);
|
||||||
$this->encryptionModule->expects($this->any())->method('getUnencryptedBlockSize')->willReturn(8192);
|
$this->encryptionModule->expects($this->any())->method('getUnencryptedBlockSize')->willReturn(8192);
|
||||||
$this->encryptionModule->expects($this->any())->method('isReadable')->willReturn(true);
|
$this->encryptionModule->expects($this->any())->method('isReadable')->willReturn(true);
|
||||||
|
$this->encryptionModule->expects($this->any())->method('needDetailedAccessList')->willReturn(false);
|
||||||
return $this->encryptionModule;
|
return $this->encryptionModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,8 @@ class EncryptionTest extends \Test\TestCase {
|
||||||
/**
|
/**
|
||||||
* @dataProvider dataProviderStreamOpen()
|
* @dataProvider dataProviderStreamOpen()
|
||||||
*/
|
*/
|
||||||
public function testStreamOpen($mode,
|
public function testStreamOpen($isMasterKeyUsed,
|
||||||
|
$mode,
|
||||||
$fullPath,
|
$fullPath,
|
||||||
$fileExists,
|
$fileExists,
|
||||||
$expectedSharePath,
|
$expectedSharePath,
|
||||||
|
@ -69,6 +70,7 @@ class EncryptionTest extends \Test\TestCase {
|
||||||
// build mocks
|
// build mocks
|
||||||
$encryptionModuleMock = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
|
$encryptionModuleMock = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
|
$encryptionModuleMock->expects($this->any())->method('needDetailedAccessList')->willReturn(!$isMasterKeyUsed);
|
||||||
$encryptionModuleMock->expects($this->once())
|
$encryptionModuleMock->expects($this->once())
|
||||||
->method('getUnencryptedBlockSize')->willReturn(99);
|
->method('getUnencryptedBlockSize')->willReturn(99);
|
||||||
$encryptionModuleMock->expects($this->once())
|
$encryptionModuleMock->expects($this->once())
|
||||||
|
@ -80,12 +82,15 @@ class EncryptionTest extends \Test\TestCase {
|
||||||
|
|
||||||
$fileMock = $this->getMockBuilder('\OC\Encryption\File')
|
$fileMock = $this->getMockBuilder('\OC\Encryption\File')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$fileMock->expects($this->once())->method('getAccessList')
|
if ($isMasterKeyUsed) {
|
||||||
->will($this->returnCallback(function($sharePath) use ($expectedSharePath) {
|
$fileMock->expects($this->never())->method('getAccessList');
|
||||||
$this->assertSame($expectedSharePath, $sharePath);
|
} else {
|
||||||
return array();
|
$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')
|
$utilMock = $this->getMockBuilder('\OC\Encryption\Util')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$utilMock->expects($this->any())
|
$utilMock->expects($this->any())
|
||||||
|
@ -152,11 +157,14 @@ class EncryptionTest extends \Test\TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataProviderStreamOpen() {
|
public function dataProviderStreamOpen() {
|
||||||
return array(
|
return [
|
||||||
array('r', '/foo/bar/test.txt', true, '/foo/bar/test.txt', null, null, true),
|
[false, '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),
|
[false, '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),
|
[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() {
|
public function testWriteRead() {
|
||||||
|
@ -311,7 +319,7 @@ class EncryptionTest extends \Test\TestCase {
|
||||||
protected function buildMockModule() {
|
protected function buildMockModule() {
|
||||||
$encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
|
$encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
|
||||||
->disableOriginalConstructor()
|
->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();
|
->getMock();
|
||||||
|
|
||||||
$encryptionModule->expects($this->any())->method('getId')->willReturn('UNIT_TEST_MODULE');
|
$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('begin')->willReturn([]);
|
||||||
$encryptionModule->expects($this->any())->method('end')->willReturn('');
|
$encryptionModule->expects($this->any())->method('end')->willReturn('');
|
||||||
$encryptionModule->expects($this->any())->method('isReadable')->willReturn(true);
|
$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) {
|
$encryptionModule->expects($this->any())->method('encrypt')->willReturnCallback(function($data) {
|
||||||
// simulate different block size by adding some padding to the data
|
// simulate different block size by adding some padding to the data
|
||||||
if (isset($data[6125])) {
|
if (isset($data[6125])) {
|
||||||
|
|
Loading…
Reference in New Issue