fix unit tests

This commit is contained in:
Bjoern Schiessle 2015-04-24 16:47:27 +02:00
parent 4554df2512
commit 9a5783b284
2 changed files with 26 additions and 9 deletions

View file

@ -237,7 +237,6 @@ class Encryption extends Wrapper {
$accessList = $this->file->getAccessList($sharePath);
$this->newHeader = $this->encryptionModule->begin($this->fullPath, $this->uid, $this->header, $accessList);
if (!($path==='')){
if (
$mode === 'w'
|| $mode === 'w+'
@ -249,9 +248,9 @@ class Encryption extends Wrapper {
$this->writeHeader();
$this->size = $this->util->getHeaderSize();
} else {
parent::stream_read($this->util->getHeaderSize());
}
$this->skipHeader();
}
return true;
}
@ -432,9 +431,16 @@ class Encryption extends Wrapper {
* @return integer
* @throws EncryptionHeaderKeyExistsException if header key is already in use
*/
private function writeHeader() {
protected function writeHeader() {
$header = $this->util->createHeader($this->newHeader, $this->encryptionModule);
return parent::stream_write($header);
}
/**
* read first block to skip the header
*/
protected function skipHeader() {
parent::stream_read($this->util->getHeaderSize());
}
}

View file

@ -55,6 +55,7 @@ class Encryption extends \Test\TestCase {
$fileExists,
$expectedSharePath,
$expectedSize,
$expectedUnencryptedSize,
$expectedReadOnly) {
// build mocks
@ -77,9 +78,15 @@ class Encryption extends \Test\TestCase {
return array();
}));
$utilMock = $this->getMockBuilder('\OC\Encryption\Util')
->disableOriginalConstructor()->getMock();
$utilMock->expects($this->any())
->method('getHeaderSize')
->willReturn(8192);
// get a instance of the stream wrapper
$streamWrapper = $this->getMockBuilder('\OC\Files\Stream\Encryption')
->setMethods(['loadContext'])->disableOriginalConstructor()->getMock();
->setMethods(['loadContext', 'writeHeader', 'skipHeader'])->disableOriginalConstructor()->getMock();
// set internal properties of the stream wrapper
$stream = new \ReflectionClass('\OC\Files\Stream\Encryption');
@ -95,6 +102,10 @@ class Encryption extends \Test\TestCase {
$file->setAccessible(true);
$file->setValue($streamWrapper, $fileMock);
$file->setAccessible(false);
$util = $stream->getProperty('util');
$util->setAccessible(true);
$util->setValue($streamWrapper, $utilMock);
$util->setAccessible(false);
$fullPathP = $stream->getProperty('fullPath');
$fullPathP->setAccessible(true);
$fullPathP->setValue($streamWrapper, $fullPath);
@ -118,7 +129,7 @@ class Encryption extends \Test\TestCase {
$unencryptedSize = $stream->getProperty('unencryptedSize');
$unencryptedSize->setAccessible(true);
$this->assertSame($expectedSize,
$this->assertSame($expectedUnencryptedSize,
$unencryptedSize->getValue($streamWrapper)
);
$unencryptedSize->setAccessible(false);
@ -133,9 +144,9 @@ class Encryption extends \Test\TestCase {
public function dataProviderStreamOpen() {
return array(
array('r', '/foo/bar/test.txt', true, '/foo/bar/test.txt', null, true),
array('r', '/foo/bar/test.txt', false, '/foo/bar', null, true),
array('w', '/foo/bar/test.txt', true, '/foo/bar/test.txt', 0, false),
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),
);
}