adding unit tests for stream wrapper
This commit is contained in:
parent
a905f641b3
commit
498625ea3a
|
@ -112,10 +112,10 @@ class Encryption extends Wrapper {
|
|||
* @param string $internalPath relative to mount point
|
||||
* @param string $fullPath relative to data/
|
||||
* @param array $header
|
||||
* @param sting $uid
|
||||
* @param string $uid
|
||||
* @param \OCP\Encryption\IEncryptionModule $encryptionModule
|
||||
* @param \OC\Files\Storage\Storage $storage
|
||||
* @param OC\Files\Storage\Wrapper\Encryption $encStorage
|
||||
* @param \OC\Files\Storage\Wrapper\Encryption $encStorage
|
||||
* @param \OC\Encryption\Util $util
|
||||
* @param string $mode
|
||||
* @param int $size
|
||||
|
@ -125,9 +125,14 @@ class Encryption extends Wrapper {
|
|||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public static function wrap($source, $internalPath, $fullPath, array $header,
|
||||
$uid, \OCP\Encryption\IEncryptionModule $encryptionModule,
|
||||
\OC\Files\Storage\Storage $storage, \OC\Files\Storage\Wrapper\Encryption $encStorage,
|
||||
\OC\Encryption\Util $util, $mode, $size, $unencryptedSize) {
|
||||
$uid,
|
||||
\OCP\Encryption\IEncryptionModule $encryptionModule,
|
||||
\OC\Files\Storage\Storage $storage,
|
||||
\OC\Files\Storage\Wrapper\Encryption $encStorage,
|
||||
\OC\Encryption\Util $util,
|
||||
$mode,
|
||||
$size,
|
||||
$unencryptedSize) {
|
||||
|
||||
$context = stream_context_create(array(
|
||||
'ocencryption' => array(
|
||||
|
@ -298,7 +303,7 @@ class Encryption extends Wrapper {
|
|||
$this->position += $remainingLength;
|
||||
$length += $remainingLength;
|
||||
$data = '';
|
||||
// if $data doens't fit the current block, the fill the current block and reiterate
|
||||
// if $data doesn't fit the current block, the fill the current block and reiterate
|
||||
// after the block is filled, it is flushed and $data is updatedxxx
|
||||
} else {
|
||||
$this->cache = substr($this->cache, 0, $blockPosition) .
|
||||
|
@ -358,6 +363,7 @@ class Encryption extends Wrapper {
|
|||
|
||||
public function stream_close() {
|
||||
$this->flush();
|
||||
$this->encryptionStorage->updateUnencryptedSize($this->fullPath, $this->unencryptedSize);
|
||||
return parent::stream_close();
|
||||
}
|
||||
|
||||
|
@ -374,7 +380,6 @@ class Encryption extends Wrapper {
|
|||
$encrypted = $this->encryptionModule->encrypt($this->cache);
|
||||
parent::stream_write($encrypted);
|
||||
$this->writeFlag = false;
|
||||
$this->encryptionStorage->updateUnencryptedSize($this->fullPath, $this->unencryptedSize);
|
||||
$this->size = max($this->size, parent::stream_tell());
|
||||
}
|
||||
// always empty the cache (otherwise readCache() will not fill it with the new block)
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Test\Files\Stream;
|
||||
|
||||
use OC\Files\View;
|
||||
use OCA\Encryption_Dummy\DummyModule;
|
||||
|
||||
class Encryption extends \Test\TestCase {
|
||||
|
||||
/**
|
||||
* @param string $mode
|
||||
* @param integer $limit
|
||||
*/
|
||||
protected function getStream($mode) {
|
||||
|
||||
$source = fopen('php://temp', $mode);
|
||||
$internalPath = '';
|
||||
$fullPath = '';
|
||||
$header = [];
|
||||
$uid = '';
|
||||
$encryptionModule = new DummyModule();
|
||||
$storage = $this->getMockBuilder('\OC\Files\Storage\Storage')
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$encStorage = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption')
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$util = new \OC\Encryption\Util(new View(), new \OC\User\Manager());;
|
||||
$size = 12;
|
||||
$unencryptedSize = 8000;
|
||||
|
||||
return \OC\Files\Stream\Encryption::wrap($source, $internalPath,
|
||||
$fullPath, $header, $uid, $encryptionModule, $storage, $encStorage,
|
||||
$util, $mode, $size, $unencryptedSize);
|
||||
}
|
||||
|
||||
public function testWriteEnoughSpace() {
|
||||
$stream = $this->getStream('w+');
|
||||
$this->assertEquals(6, fwrite($stream, 'foobar'));
|
||||
rewind($stream);
|
||||
$this->assertEquals('foobar', fread($stream, 100));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue