aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_encryption/tests
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-06-21 17:37:53 +0200
committerRobin Appelman <icewind@owncloud.com>2012-06-21 17:38:00 +0200
commitd0455c5819099751fb8614a76c272a23c6494b65 (patch)
treec6068672ac891b51e1ae690515a897995ac9039d /apps/files_encryption/tests
parent1338279ca02af2444a7277a041bec18aab615774 (diff)
downloadnextcloud-server-d0455c5819099751fb8614a76c272a23c6494b65.tar.gz
nextcloud-server-d0455c5819099751fb8614a76c272a23c6494b65.zip
truncate decrypted files based on filelength
Diffstat (limited to 'apps/files_encryption/tests')
-rw-r--r--apps/files_encryption/tests/encryption.php2
-rw-r--r--apps/files_encryption/tests/proxy.php15
-rw-r--r--apps/files_encryption/tests/stream.php30
-rw-r--r--apps/files_encryption/tests/zerosbin0 -> 10238 bytes
4 files changed, 38 insertions, 9 deletions
diff --git a/apps/files_encryption/tests/encryption.php b/apps/files_encryption/tests/encryption.php
index 70aa1daf4c3..286770a69f5 100644
--- a/apps/files_encryption/tests/encryption.php
+++ b/apps/files_encryption/tests/encryption.php
@@ -66,7 +66,7 @@ class Test_Encryption extends UnitTestCase {
$this->assertEqual($decrypted,$source);
$encrypted=OC_Crypt::blockEncrypt($source,$key);
- $decrypted=OC_Crypt::blockDecrypt($encrypted,$key);
+ $decrypted=OC_Crypt::blockDecrypt($encrypted,$key,strlen($source));
$this->assertEqual($decrypted,$source);
}
}
diff --git a/apps/files_encryption/tests/proxy.php b/apps/files_encryption/tests/proxy.php
index 5616e2091a9..4533289265a 100644
--- a/apps/files_encryption/tests/proxy.php
+++ b/apps/files_encryption/tests/proxy.php
@@ -50,6 +50,7 @@ class Test_CryptProxy extends UnitTestCase {
$fromFile=OC_Filesystem::file_get_contents('/file');
$this->assertNotEqual($original,$stored);
+ $this->assertEqual(strlen($original),strlen($fromFile));
$this->assertEqual($original,$fromFile);
}
@@ -88,6 +89,20 @@ class Test_CryptProxy extends UnitTestCase {
$fromFile=OC_Filesystem::file_get_contents('/file');
$this->assertNotEqual($original,$stored);
+ $this->assertEqual(strlen($original),strlen($fromFile));
$this->assertEqual($original,$fromFile);
+
+ $file=__DIR__.'/zeros';
+ $original=file_get_contents($file);
+
+ OC_Filesystem::file_put_contents('/file',$original);
+
+ OC_FileProxy::$enabled=false;
+ $stored=OC_Filesystem::file_get_contents('/file');
+ OC_FileProxy::$enabled=true;
+
+ $fromFile=OC_Filesystem::file_get_contents('/file');
+ $this->assertNotEqual($original,$stored);
+ $this->assertEqual(strlen($original),strlen($fromFile));
}
}
diff --git a/apps/files_encryption/tests/stream.php b/apps/files_encryption/tests/stream.php
index 4ffeb6210a9..d95ea792f72 100644
--- a/apps/files_encryption/tests/stream.php
+++ b/apps/files_encryption/tests/stream.php
@@ -10,23 +10,23 @@ class Test_CryptStream extends UnitTestCase {
private $tmpFiles=array();
function testStream(){
- $stream=$this->getStream('test1','w');
+ $stream=$this->getStream('test1','w',strlen('foobar'));
fwrite($stream,'foobar');
fclose($stream);
- $stream=$this->getStream('test1','r');
+ $stream=$this->getStream('test1','r',strlen('foobar'));
$data=fread($stream,6);
fclose($stream);
$this->assertEqual('foobar',$data);
$file=OC::$SERVERROOT.'/3rdparty/MDB2.php';
$source=fopen($file,'r');
- $target=$this->getStream('test2','w');
+ $target=$this->getStream('test2','w',0);
OCP\Files::streamCopy($source,$target);
fclose($target);
fclose($source);
- $stream=$this->getStream('test2','r');
+ $stream=$this->getStream('test2','r',filesize($file));
$data=stream_get_contents($stream);
$original=file_get_contents($file);
$this->assertEqual(strlen($original),strlen($data));
@@ -37,9 +37,10 @@ class Test_CryptStream extends UnitTestCase {
* get a cryptstream to a temporary file
* @param string $id
* @param string $mode
+ * @param int size
* @return resource
*/
- function getStream($id,$mode){
+ function getStream($id,$mode,$size){
if($id===''){
$id=uniqid();
}
@@ -50,7 +51,7 @@ class Test_CryptStream extends UnitTestCase {
$file=$this->tmpFiles[$id];
}
$stream=fopen($file,$mode);
- OC_CryptStream::$sourceStreams[$id]=array('path'=>'dummy'.$id,'stream'=>$stream);
+ OC_CryptStream::$sourceStreams[$id]=array('path'=>'dummy'.$id,'stream'=>$stream,'size'=>$size);
return fopen('crypt://streams/'.$id,$mode);
}
@@ -58,11 +59,24 @@ class Test_CryptStream extends UnitTestCase {
$file=__DIR__.'/binary';
$source=file_get_contents($file);
- $stream=$this->getStream('test','w');
+ $stream=$this->getStream('test','w',strlen($source));
fwrite($stream,$source);
fclose($stream);
- $stream=$this->getStream('test','r');
+ $stream=$this->getStream('test','r',strlen($source));
+ $data=stream_get_contents($stream);
+ fclose($stream);
+ $this->assertEqual(strlen($data),strlen($source));
+ $this->assertEqual($source,$data);
+
+ $file=__DIR__.'/zeros';
+ $source=file_get_contents($file);
+
+ $stream=$this->getStream('test2','w',strlen($source));
+ fwrite($stream,$source);
+ fclose($stream);
+
+ $stream=$this->getStream('test2','r',strlen($source));
$data=stream_get_contents($stream);
fclose($stream);
$this->assertEqual(strlen($data),strlen($source));
diff --git a/apps/files_encryption/tests/zeros b/apps/files_encryption/tests/zeros
new file mode 100644
index 00000000000..ff982acf423
--- /dev/null
+++ b/apps/files_encryption/tests/zeros
Binary files differ