diff options
author | Robin Appelman <icewind@owncloud.com> | 2012-06-15 23:48:39 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2012-06-16 01:31:03 +0200 |
commit | 195c37f88a803055c92fd38f33a4eb7a1440e5ab (patch) | |
tree | 5080604305c9aa7cb5a395c9dd1c2c0d49d41e1b /apps/files_encryption/tests | |
parent | 8484e165167050ad19b8f2f083c04ff0d4a60755 (diff) | |
download | nextcloud-server-195c37f88a803055c92fd38f33a4eb7a1440e5ab.tar.gz nextcloud-server-195c37f88a803055c92fd38f33a4eb7a1440e5ab.zip |
fix for encryption binary files
Diffstat (limited to 'apps/files_encryption/tests')
-rw-r--r-- | apps/files_encryption/tests/encryption.php | 19 | ||||
-rw-r--r-- | apps/files_encryption/tests/stream.php | 17 |
2 files changed, 35 insertions, 1 deletions
diff --git a/apps/files_encryption/tests/encryption.php b/apps/files_encryption/tests/encryption.php index cf24a225d28..70aa1daf4c3 100644 --- a/apps/files_encryption/tests/encryption.php +++ b/apps/files_encryption/tests/encryption.php @@ -13,6 +13,7 @@ class Test_Encryption extends UnitTestCase { $source=file_get_contents($file); //nice large text file $encrypted=OC_Crypt::encrypt($source,$key); $decrypted=OC_Crypt::decrypt($encrypted,$key); + $decrypted=rtrim($decrypted, "\0"); $this->assertNotEqual($encrypted,$source); $this->assertEqual($decrypted,$source); @@ -20,6 +21,7 @@ class Test_Encryption extends UnitTestCase { $encrypted=OC_Crypt::encrypt($chunk,$key); $this->assertEqual(strlen($chunk),strlen($encrypted)); $decrypted=OC_Crypt::decrypt($encrypted,$key); + $decrypted=rtrim($decrypted, "\0"); $this->assertEqual($decrypted,$chunk); $encrypted=OC_Crypt::blockEncrypt($source,$key); @@ -43,6 +45,7 @@ class Test_Encryption extends UnitTestCase { $source=file_get_contents($file); //binary file $encrypted=OC_Crypt::encrypt($source,$key); $decrypted=OC_Crypt::decrypt($encrypted,$key); + $decrypted=rtrim($decrypted, "\0"); $this->assertEqual($decrypted,$source); $encrypted=OC_Crypt::blockEncrypt($source,$key); @@ -50,4 +53,20 @@ class Test_Encryption extends UnitTestCase { $this->assertEqual($decrypted,$source); } + + function testBinary(){ + $key=uniqid(); + + $file=__DIR__.'/binary'; + $source=file_get_contents($file); //binary file + $encrypted=OC_Crypt::encrypt($source,$key); + $decrypted=OC_Crypt::decrypt($encrypted,$key); + + $decrypted=rtrim($decrypted, "\0"); + $this->assertEqual($decrypted,$source); + + $encrypted=OC_Crypt::blockEncrypt($source,$key); + $decrypted=OC_Crypt::blockDecrypt($encrypted,$key); + $this->assertEqual($decrypted,$source); + } } diff --git a/apps/files_encryption/tests/stream.php b/apps/files_encryption/tests/stream.php index b23805d60b0..4ffeb6210a9 100644 --- a/apps/files_encryption/tests/stream.php +++ b/apps/files_encryption/tests/stream.php @@ -50,7 +50,22 @@ class Test_CryptStream extends UnitTestCase { $file=$this->tmpFiles[$id]; } $stream=fopen($file,$mode); - OC_CryptStream::$sourceStreams[$id]=array('path'=>'dummy','stream'=>$stream); + OC_CryptStream::$sourceStreams[$id]=array('path'=>'dummy'.$id,'stream'=>$stream); return fopen('crypt://streams/'.$id,$mode); } + + function testBinary(){ + $file=__DIR__.'/binary'; + $source=file_get_contents($file); + + $stream=$this->getStream('test','w'); + fwrite($stream,$source); + fclose($stream); + + $stream=$this->getStream('test','r'); + $data=stream_get_contents($stream); + fclose($stream); + $this->assertEqual(strlen($data),strlen($source)); + $this->assertEqual($source,$data); + } } |