summaryrefslogtreecommitdiffstats
path: root/tests/lib/files/stream
diff options
context:
space:
mode:
authorBjörn Schießle <bjoern@schiessle.org>2015-04-22 11:32:21 +0200
committerBjörn Schießle <bjoern@schiessle.org>2015-04-22 11:32:21 +0200
commit570718fb6bbad4dfd721b1ef451580749e9e0bdd (patch)
treec3a71fb88f42447ecb13026edefbcdb070480636 /tests/lib/files/stream
parentd7bdf6055902054233b0803a1a69ddd9d6ffce52 (diff)
parent76dad297ffc4084d2057e2c2312f0c53f1e15f5b (diff)
downloadnextcloud-server-570718fb6bbad4dfd721b1ef451580749e9e0bdd.tar.gz
nextcloud-server-570718fb6bbad4dfd721b1ef451580749e9e0bdd.zip
Merge pull request #15757 from owncloud/enc-fixfeofforlastblock
Fix encryption feof to not return too early
Diffstat (limited to 'tests/lib/files/stream')
-rw-r--r--tests/lib/files/stream/encryption.php46
1 files changed, 40 insertions, 6 deletions
diff --git a/tests/lib/files/stream/encryption.php b/tests/lib/files/stream/encryption.php
index 4d932abfa39..25e7e54335e 100644
--- a/tests/lib/files/stream/encryption.php
+++ b/tests/lib/files/stream/encryption.php
@@ -14,7 +14,7 @@ class Encryption extends \Test\TestCase {
* @return resource
*/
protected function getStream($fileName, $mode, $unencryptedSize) {
-
+ clearstatcache();
$size = filesize($fileName);
$source = fopen($fileName, $mode);
$internalPath = $fileName;
@@ -163,8 +163,19 @@ class Encryption extends \Test\TestCase {
fclose($stream);
}
- public function testWriteReadBigFile() {
- $expectedData = file_get_contents(\OC::$SERVERROOT . '/tests/data/lorem-big.txt');
+ function dataFilesProvider() {
+ 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);
// write it
$fileName = tempnam("/tmp", "FOO");
$stream = $this->getStream($fileName, 'w+', 0);
@@ -177,6 +188,16 @@ class Encryption extends \Test\TestCase {
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);
}
/**
@@ -192,11 +213,24 @@ class Encryption extends \Test\TestCase {
$encryptionModule->expects($this->any())->method('getDisplayName')->willReturn('Unit test module');
$encryptionModule->expects($this->any())->method('begin')->willReturn([]);
$encryptionModule->expects($this->any())->method('end')->willReturn('');
- $encryptionModule->expects($this->any())->method('encrypt')->willReturnArgument(0);
- $encryptionModule->expects($this->any())->method('decrypt')->willReturnArgument(0);
+ $encryptionModule->expects($this->any())->method('encrypt')->willReturnCallback(function($data) {
+ // 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;
+ });
+ $encryptionModule->expects($this->any())->method('decrypt')->willReturnCallback(function($data) {
+ if (isset($data[8191])) {
+ return substr($data, 0, 6126);
+ }
+ // last block
+ return $data;
+ });
$encryptionModule->expects($this->any())->method('update')->willReturn(true);
$encryptionModule->expects($this->any())->method('shouldEncrypt')->willReturn(true);
- $encryptionModule->expects($this->any())->method('getUnencryptedBlockSize')->willReturn(8192);
+ $encryptionModule->expects($this->any())->method('getUnencryptedBlockSize')->willReturn(6126);
return $encryptionModule;
}
}