2015-03-30 14:59:48 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Test\Files\Stream;
|
|
|
|
|
2018-07-25 11:19:14 +03:00
|
|
|
use OC\Files\Cache\CacheEntry;
|
2015-03-30 14:59:48 +03:00
|
|
|
use OC\Files\View;
|
2016-09-07 21:01:13 +03:00
|
|
|
use OC\Memcache\ArrayCache;
|
2019-11-20 16:22:00 +03:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2018-07-25 11:19:14 +03:00
|
|
|
use OCP\Files\Cache\ICache;
|
2017-10-24 16:26:53 +03:00
|
|
|
use OCP\IConfig;
|
2019-02-24 10:54:43 +03:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
2015-03-30 14:59:48 +03:00
|
|
|
|
2016-05-20 16:38:20 +03:00
|
|
|
class EncryptionTest extends \Test\TestCase {
|
2015-03-30 14:59:48 +03:00
|
|
|
|
2015-05-18 17:40:58 +03:00
|
|
|
/** @var \OCP\Encryption\IEncryptionModule | \PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $encryptionModule;
|
|
|
|
|
2015-03-30 14:59:48 +03:00
|
|
|
/**
|
2015-04-17 13:38:54 +03:00
|
|
|
* @param string $fileName
|
2015-03-30 14:59:48 +03:00
|
|
|
* @param string $mode
|
2015-04-17 13:38:54 +03:00
|
|
|
* @param integer $unencryptedSize
|
|
|
|
* @return resource
|
2015-03-30 14:59:48 +03:00
|
|
|
*/
|
2015-05-20 15:29:20 +03:00
|
|
|
protected function getStream($fileName, $mode, $unencryptedSize, $wrapper = '\OC\Files\Stream\Encryption') {
|
2015-04-20 18:30:10 +03:00
|
|
|
clearstatcache();
|
2015-04-02 17:16:06 +03:00
|
|
|
$size = filesize($fileName);
|
2015-04-02 12:07:07 +03:00
|
|
|
$source = fopen($fileName, $mode);
|
|
|
|
$internalPath = $fileName;
|
|
|
|
$fullPath = $fileName;
|
2015-03-30 14:59:48 +03:00
|
|
|
$header = [];
|
|
|
|
$uid = '';
|
2015-05-18 17:40:58 +03:00
|
|
|
$this->encryptionModule = $this->buildMockModule();
|
2018-07-25 11:19:14 +03:00
|
|
|
$cache = $this->createMock(ICache::class);
|
2015-03-30 14:59:48 +03:00
|
|
|
$storage = $this->getMockBuilder('\OC\Files\Storage\Storage')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$encStorage = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
2017-10-24 16:26:53 +03:00
|
|
|
$config = $this->getMockBuilder(IConfig::class)
|
2015-03-31 00:19:35 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2016-09-07 21:01:13 +03:00
|
|
|
$arrayCache = $this->createMock(ArrayCache::class);
|
2015-04-15 14:19:17 +03:00
|
|
|
$groupManager = $this->getMockBuilder('\OC\Group\Manager')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-04-02 12:07:07 +03:00
|
|
|
$file = $this->getMockBuilder('\OC\Encryption\File')
|
|
|
|
->disableOriginalConstructor()
|
2015-04-09 18:45:57 +03:00
|
|
|
->setMethods(['getAccessList'])
|
2015-04-02 12:07:07 +03:00
|
|
|
->getMock();
|
2015-04-09 18:45:57 +03:00
|
|
|
$file->expects($this->any())->method('getAccessList')->willReturn([]);
|
2016-09-07 21:01:13 +03:00
|
|
|
$util = $this->getMockBuilder('\OC\Encryption\Util')
|
|
|
|
->setMethods(['getUidAndFilename'])
|
2019-11-20 16:22:00 +03:00
|
|
|
->setConstructorArgs([new View(), new \OC\User\Manager($config, $this->createMock(EventDispatcherInterface::class), $this->createMock(IEventDispatcher::class)), $groupManager, $config, $arrayCache])
|
2016-09-07 21:01:13 +03:00
|
|
|
->getMock();
|
2015-04-02 12:07:07 +03:00
|
|
|
$util->expects($this->any())
|
|
|
|
->method('getUidAndFilename')
|
|
|
|
->willReturn(['user1', $internalPath]);
|
2018-07-25 11:19:14 +03:00
|
|
|
$storage->expects($this->any())->method('getCache')->willReturn($cache);
|
|
|
|
$entry = new CacheEntry([
|
|
|
|
'fileid' => 5,
|
|
|
|
'encryptedVersion' => 2,
|
|
|
|
]);
|
2020-04-09 17:07:47 +03:00
|
|
|
$cache->expects($this->any())->method('get')->willReturn($entry);
|
2018-07-25 11:19:14 +03:00
|
|
|
$cache->expects($this->any())->method('update')->with(5, ['encrypted' => 3, 'encryptedVersion' => 3]);
|
2015-03-30 14:59:48 +03:00
|
|
|
|
2015-05-20 15:29:20 +03:00
|
|
|
|
|
|
|
return $wrapper::wrap($source, $internalPath,
|
2015-05-18 17:40:58 +03:00
|
|
|
$fullPath, $header, $uid, $this->encryptionModule, $storage, $encStorage,
|
2015-05-20 15:29:20 +03:00
|
|
|
$util, $file, $mode, $size, $unencryptedSize, 8192, $wrapper);
|
2015-03-30 14:59:48 +03:00
|
|
|
}
|
|
|
|
|
2015-04-17 13:38:54 +03:00
|
|
|
/**
|
|
|
|
* @dataProvider dataProviderStreamOpen()
|
|
|
|
*/
|
2017-05-31 16:26:10 +03:00
|
|
|
public function testStreamOpen($isMasterKeyUsed,
|
|
|
|
$mode,
|
2015-04-17 13:38:54 +03:00
|
|
|
$fullPath,
|
|
|
|
$fileExists,
|
|
|
|
$expectedSharePath,
|
|
|
|
$expectedSize,
|
2015-04-24 17:47:27 +03:00
|
|
|
$expectedUnencryptedSize,
|
2015-04-17 13:38:54 +03:00
|
|
|
$expectedReadOnly) {
|
|
|
|
|
|
|
|
// build mocks
|
|
|
|
$encryptionModuleMock = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
2017-05-31 16:26:10 +03:00
|
|
|
$encryptionModuleMock->expects($this->any())->method('needDetailedAccessList')->willReturn(!$isMasterKeyUsed);
|
2015-04-17 13:38:54 +03:00
|
|
|
$encryptionModuleMock->expects($this->once())
|
|
|
|
->method('getUnencryptedBlockSize')->willReturn(99);
|
|
|
|
$encryptionModuleMock->expects($this->once())
|
|
|
|
->method('begin')->willReturn(true);
|
|
|
|
|
|
|
|
$storageMock = $this->getMockBuilder('\OC\Files\Storage\Storage')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$storageMock->expects($this->once())->method('file_exists')->willReturn($fileExists);
|
|
|
|
|
|
|
|
$fileMock = $this->getMockBuilder('\OC\Encryption\File')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
2017-05-31 16:26:10 +03:00
|
|
|
if ($isMasterKeyUsed) {
|
|
|
|
$fileMock->expects($this->never())->method('getAccessList');
|
|
|
|
} else {
|
|
|
|
$fileMock->expects($this->once())->method('getAccessList')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function ($sharePath) use ($expectedSharePath) {
|
2017-05-31 16:26:10 +03:00
|
|
|
$this->assertSame($expectedSharePath, $sharePath);
|
2020-03-26 11:30:18 +03:00
|
|
|
return [];
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2017-05-31 16:26:10 +03:00
|
|
|
}
|
2015-04-24 17:47:27 +03:00
|
|
|
$utilMock = $this->getMockBuilder('\OC\Encryption\Util')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$utilMock->expects($this->any())
|
|
|
|
->method('getHeaderSize')
|
|
|
|
->willReturn(8192);
|
|
|
|
|
2015-04-17 13:38:54 +03:00
|
|
|
// get a instance of the stream wrapper
|
|
|
|
$streamWrapper = $this->getMockBuilder('\OC\Files\Stream\Encryption')
|
2015-04-24 17:47:27 +03:00
|
|
|
->setMethods(['loadContext', 'writeHeader', 'skipHeader'])->disableOriginalConstructor()->getMock();
|
2015-04-17 13:38:54 +03:00
|
|
|
|
|
|
|
// set internal properties of the stream wrapper
|
|
|
|
$stream = new \ReflectionClass('\OC\Files\Stream\Encryption');
|
|
|
|
$encryptionModule = $stream->getProperty('encryptionModule');
|
|
|
|
$encryptionModule->setAccessible(true);
|
|
|
|
$encryptionModule->setValue($streamWrapper, $encryptionModuleMock);
|
|
|
|
$encryptionModule->setAccessible(false);
|
|
|
|
$storage = $stream->getProperty('storage');
|
|
|
|
$storage->setAccessible(true);
|
|
|
|
$storage->setValue($streamWrapper, $storageMock);
|
|
|
|
$storage->setAccessible(false);
|
|
|
|
$file = $stream->getProperty('file');
|
|
|
|
$file->setAccessible(true);
|
|
|
|
$file->setValue($streamWrapper, $fileMock);
|
|
|
|
$file->setAccessible(false);
|
2015-04-24 17:47:27 +03:00
|
|
|
$util = $stream->getProperty('util');
|
|
|
|
$util->setAccessible(true);
|
|
|
|
$util->setValue($streamWrapper, $utilMock);
|
|
|
|
$util->setAccessible(false);
|
2015-04-17 13:38:54 +03:00
|
|
|
$fullPathP = $stream->getProperty('fullPath');
|
|
|
|
$fullPathP->setAccessible(true);
|
|
|
|
$fullPathP->setValue($streamWrapper, $fullPath);
|
|
|
|
$fullPathP->setAccessible(false);
|
|
|
|
$header = $stream->getProperty('header');
|
|
|
|
$header->setAccessible(true);
|
2020-03-26 11:30:18 +03:00
|
|
|
$header->setValue($streamWrapper, []);
|
2015-04-17 13:38:54 +03:00
|
|
|
$header->setAccessible(false);
|
2016-01-05 21:01:03 +03:00
|
|
|
$this->invokePrivate($streamWrapper, 'signed', [true]);
|
2015-04-17 13:38:54 +03:00
|
|
|
|
|
|
|
// call stream_open, that's the method we want to test
|
|
|
|
$dummyVar = 'foo';
|
|
|
|
$streamWrapper->stream_open('', $mode, '', $dummyVar);
|
|
|
|
|
|
|
|
// check internal properties
|
|
|
|
$size = $stream->getProperty('size');
|
|
|
|
$size->setAccessible(true);
|
|
|
|
$this->assertSame($expectedSize,
|
|
|
|
$size->getValue($streamWrapper)
|
|
|
|
);
|
|
|
|
$size->setAccessible(false);
|
|
|
|
|
|
|
|
$unencryptedSize = $stream->getProperty('unencryptedSize');
|
|
|
|
$unencryptedSize->setAccessible(true);
|
2015-04-24 17:47:27 +03:00
|
|
|
$this->assertSame($expectedUnencryptedSize,
|
2015-04-17 13:38:54 +03:00
|
|
|
$unencryptedSize->getValue($streamWrapper)
|
|
|
|
);
|
|
|
|
$unencryptedSize->setAccessible(false);
|
|
|
|
|
|
|
|
$readOnly = $stream->getProperty('readOnly');
|
|
|
|
$readOnly->setAccessible(true);
|
|
|
|
$this->assertSame($expectedReadOnly,
|
|
|
|
$readOnly->getValue($streamWrapper)
|
|
|
|
);
|
|
|
|
$readOnly->setAccessible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dataProviderStreamOpen() {
|
2017-05-31 16:26:10 +03:00
|
|
|
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],
|
|
|
|
];
|
2015-04-17 13:38:54 +03:00
|
|
|
}
|
|
|
|
|
2015-04-02 12:07:07 +03:00
|
|
|
public function testWriteRead() {
|
|
|
|
$fileName = tempnam("/tmp", "FOO");
|
2015-04-02 17:16:06 +03:00
|
|
|
$stream = $this->getStream($fileName, 'w+', 0);
|
2015-03-30 14:59:48 +03:00
|
|
|
$this->assertEquals(6, fwrite($stream, 'foobar'));
|
2015-04-02 12:07:07 +03:00
|
|
|
fclose($stream);
|
|
|
|
|
2015-04-02 17:16:06 +03:00
|
|
|
$stream = $this->getStream($fileName, 'r', 6);
|
2015-03-30 14:59:48 +03:00
|
|
|
$this->assertEquals('foobar', fread($stream, 100));
|
2015-04-02 12:07:07 +03:00
|
|
|
fclose($stream);
|
2015-04-23 14:42:18 +03:00
|
|
|
|
2015-04-22 14:06:02 +03:00
|
|
|
$stream = $this->getStream($fileName, 'r+', 6);
|
|
|
|
$this->assertEquals(3, fwrite($stream, 'bar'));
|
|
|
|
fclose($stream);
|
|
|
|
|
|
|
|
$stream = $this->getStream($fileName, 'r', 6);
|
|
|
|
$this->assertEquals('barbar', fread($stream, 100));
|
|
|
|
fclose($stream);
|
2015-05-18 12:32:29 +03:00
|
|
|
|
|
|
|
unlink($fileName);
|
2015-04-22 14:06:02 +03:00
|
|
|
}
|
2015-04-21 18:36:25 +03:00
|
|
|
|
2015-04-22 13:52:01 +03:00
|
|
|
public function testRewind() {
|
|
|
|
$fileName = tempnam("/tmp", "FOO");
|
|
|
|
$stream = $this->getStream($fileName, 'w+', 0);
|
|
|
|
$this->assertEquals(6, fwrite($stream, 'foobar'));
|
2020-03-25 23:53:04 +03:00
|
|
|
$this->assertEquals(true, rewind($stream));
|
2015-04-22 13:52:01 +03:00
|
|
|
$this->assertEquals('foobar', fread($stream, 100));
|
2020-03-25 23:53:04 +03:00
|
|
|
$this->assertEquals(true, rewind($stream));
|
2015-04-22 13:52:01 +03:00
|
|
|
$this->assertEquals(3, fwrite($stream, 'bar'));
|
|
|
|
fclose($stream);
|
|
|
|
|
|
|
|
$stream = $this->getStream($fileName, 'r', 6);
|
|
|
|
$this->assertEquals('barbar', fread($stream, 100));
|
|
|
|
fclose($stream);
|
2017-05-31 16:26:10 +03:00
|
|
|
|
2015-05-18 12:32:29 +03:00
|
|
|
unlink($fileName);
|
2020-04-10 15:19:56 +03:00
|
|
|
}
|
2015-04-21 18:36:25 +03:00
|
|
|
|
2015-04-02 13:48:41 +03:00
|
|
|
public function testSeek() {
|
|
|
|
$fileName = tempnam("/tmp", "FOO");
|
2018-07-25 11:19:14 +03:00
|
|
|
|
2015-04-02 17:16:06 +03:00
|
|
|
$stream = $this->getStream($fileName, 'w+', 0);
|
2015-04-02 13:48:41 +03:00
|
|
|
$this->assertEquals(6, fwrite($stream, 'foobar'));
|
|
|
|
$this->assertEquals(0, fseek($stream, 3));
|
|
|
|
$this->assertEquals(6, fwrite($stream, 'foobar'));
|
|
|
|
fclose($stream);
|
|
|
|
|
2015-04-02 17:16:06 +03:00
|
|
|
$stream = $this->getStream($fileName, 'r', 9);
|
2015-04-02 13:48:41 +03:00
|
|
|
$this->assertEquals('foofoobar', fread($stream, 100));
|
2015-05-18 12:32:29 +03:00
|
|
|
$this->assertEquals(-1, fseek($stream, 10));
|
|
|
|
$this->assertEquals(0, fseek($stream, 9));
|
2015-05-18 12:55:48 +03:00
|
|
|
$this->assertEquals(-1, fseek($stream, -10, SEEK_CUR));
|
|
|
|
$this->assertEquals(0, fseek($stream, -9, SEEK_CUR));
|
|
|
|
$this->assertEquals(-1, fseek($stream, -10, SEEK_END));
|
|
|
|
$this->assertEquals(0, fseek($stream, -9, SEEK_END));
|
2015-04-02 13:48:41 +03:00
|
|
|
fclose($stream);
|
2015-04-23 14:42:18 +03:00
|
|
|
|
|
|
|
unlink($fileName);
|
2015-04-02 13:48:41 +03:00
|
|
|
}
|
|
|
|
|
2020-04-10 17:51:06 +03:00
|
|
|
public function dataFilesProvider() {
|
2015-04-20 18:30:10 +03:00
|
|
|
return [
|
|
|
|
['lorem-big.txt'],
|
|
|
|
['block-aligned.txt'],
|
|
|
|
['block-aligned-plus-one.txt'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataFilesProvider
|
|
|
|
*/
|
|
|
|
public function testWriteReadBigFile($testFile) {
|
|
|
|
$expectedData = file_get_contents(\OC::$SERVERROOT . '/tests/data/' . $testFile);
|
2015-04-02 16:19:09 +03:00
|
|
|
// write it
|
|
|
|
$fileName = tempnam("/tmp", "FOO");
|
2015-04-02 17:16:06 +03:00
|
|
|
$stream = $this->getStream($fileName, 'w+', 0);
|
2015-05-18 17:40:58 +03:00
|
|
|
// while writing the file from the beginning to the end we should never try
|
|
|
|
// to read parts of the file. This should only happen for write operations
|
|
|
|
// in the middle of a file
|
|
|
|
$this->encryptionModule->expects($this->never())->method('decrypt');
|
2015-04-02 16:19:09 +03:00
|
|
|
fwrite($stream, $expectedData);
|
|
|
|
fclose($stream);
|
|
|
|
|
|
|
|
// read it all
|
2015-04-02 17:16:06 +03:00
|
|
|
$stream = $this->getStream($fileName, 'r', strlen($expectedData));
|
2015-04-02 16:19:09 +03:00
|
|
|
$data = stream_get_contents($stream);
|
|
|
|
fclose($stream);
|
|
|
|
|
|
|
|
$this->assertEquals($expectedData, $data);
|
2015-04-20 18:30:10 +03:00
|
|
|
|
|
|
|
// another read test with a loop like we do in several places:
|
|
|
|
$stream = $this->getStream($fileName, 'r', strlen($expectedData));
|
|
|
|
$data = '';
|
|
|
|
while (!feof($stream)) {
|
|
|
|
$data .= fread($stream, 8192);
|
|
|
|
}
|
|
|
|
fclose($stream);
|
|
|
|
|
|
|
|
$this->assertEquals($expectedData, $data);
|
2015-04-23 14:42:18 +03:00
|
|
|
|
|
|
|
unlink($fileName);
|
2015-04-02 16:19:09 +03:00
|
|
|
}
|
|
|
|
|
2015-05-20 15:29:20 +03:00
|
|
|
/**
|
|
|
|
* simulate a non-seekable storage
|
|
|
|
*
|
|
|
|
* @dataProvider dataFilesProvider
|
|
|
|
*/
|
|
|
|
public function testWriteToNonSeekableStorage($testFile) {
|
|
|
|
$wrapper = $this->getMockBuilder('\OC\Files\Stream\Encryption')
|
|
|
|
->setMethods(['parentSeekStream'])->getMock();
|
|
|
|
$wrapper->expects($this->any())->method('parentSeekStream')->willReturn(false);
|
|
|
|
|
|
|
|
$expectedData = file_get_contents(\OC::$SERVERROOT . '/tests/data/' . $testFile);
|
|
|
|
// write it
|
|
|
|
$fileName = tempnam("/tmp", "FOO");
|
|
|
|
$stream = $this->getStream($fileName, 'w+', 0, '\Test\Files\Stream\DummyEncryptionWrapper');
|
|
|
|
// while writing the file from the beginning to the end we should never try
|
|
|
|
// to read parts of the file. This should only happen for write operations
|
|
|
|
// in the middle of a file
|
|
|
|
$this->encryptionModule->expects($this->never())->method('decrypt');
|
|
|
|
fwrite($stream, $expectedData);
|
|
|
|
fclose($stream);
|
|
|
|
|
|
|
|
// read it all
|
|
|
|
$stream = $this->getStream($fileName, 'r', strlen($expectedData), '\Test\Files\Stream\DummyEncryptionWrapper');
|
|
|
|
$data = stream_get_contents($stream);
|
|
|
|
fclose($stream);
|
|
|
|
|
|
|
|
$this->assertEquals($expectedData, $data);
|
|
|
|
|
|
|
|
// another read test with a loop like we do in several places:
|
|
|
|
$stream = $this->getStream($fileName, 'r', strlen($expectedData));
|
|
|
|
$data = '';
|
|
|
|
while (!feof($stream)) {
|
|
|
|
$data .= fread($stream, 8192);
|
|
|
|
}
|
|
|
|
fclose($stream);
|
|
|
|
|
|
|
|
$this->assertEquals($expectedData, $data);
|
|
|
|
|
|
|
|
unlink($fileName);
|
|
|
|
}
|
|
|
|
|
2015-04-02 12:07:07 +03:00
|
|
|
/**
|
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject
|
|
|
|
*/
|
|
|
|
protected function buildMockModule() {
|
|
|
|
$encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
|
|
|
|
->disableOriginalConstructor()
|
2017-05-31 16:26:10 +03:00
|
|
|
->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'getUnencryptedBlockSize', 'isReadable', 'encryptAll', 'prepareDecryptAll', 'isReadyForUser', 'needDetailedAccessList'])
|
2015-04-02 12:07:07 +03:00
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$encryptionModule->expects($this->any())->method('getId')->willReturn('UNIT_TEST_MODULE');
|
|
|
|
$encryptionModule->expects($this->any())->method('getDisplayName')->willReturn('Unit test module');
|
|
|
|
$encryptionModule->expects($this->any())->method('begin')->willReturn([]);
|
|
|
|
$encryptionModule->expects($this->any())->method('end')->willReturn('');
|
2015-05-12 19:49:25 +03:00
|
|
|
$encryptionModule->expects($this->any())->method('isReadable')->willReturn(true);
|
2017-05-31 16:26:10 +03:00
|
|
|
$encryptionModule->expects($this->any())->method('needDetailedAccessList')->willReturn(false);
|
2020-04-09 14:53:40 +03:00
|
|
|
$encryptionModule->expects($this->any())->method('encrypt')->willReturnCallback(function ($data) {
|
2015-04-20 18:30:10 +03:00
|
|
|
// simulate different block size by adding some padding to the data
|
|
|
|
if (isset($data[6125])) {
|
|
|
|
return str_pad($data, 8192, 'X');
|
|
|
|
}
|
|
|
|
// last block
|
|
|
|
return $data;
|
|
|
|
});
|
2020-04-09 14:53:40 +03:00
|
|
|
$encryptionModule->expects($this->any())->method('decrypt')->willReturnCallback(function ($data) {
|
2015-04-20 18:30:10 +03:00
|
|
|
if (isset($data[8191])) {
|
|
|
|
return substr($data, 0, 6126);
|
|
|
|
}
|
|
|
|
// last block
|
|
|
|
return $data;
|
|
|
|
});
|
2015-04-02 12:07:07 +03:00
|
|
|
$encryptionModule->expects($this->any())->method('update')->willReturn(true);
|
|
|
|
$encryptionModule->expects($this->any())->method('shouldEncrypt')->willReturn(true);
|
2015-04-20 18:30:10 +03:00
|
|
|
$encryptionModule->expects($this->any())->method('getUnencryptedBlockSize')->willReturn(6126);
|
2015-04-02 12:07:07 +03:00
|
|
|
return $encryptionModule;
|
2015-03-30 14:59:48 +03:00
|
|
|
}
|
|
|
|
}
|