From 015787fbb3152661144d21119bb9ea662a8ba0a3 Mon Sep 17 00:00:00 2001 From: Sam Tuke Date: Sun, 6 Jan 2013 18:38:35 +0000 Subject: [PATCH] All in-use unit tests now passing after merge --- apps/files_encryption/hooks/hooks.php | 7 - apps/files_encryption/lib/crypt.php | 10 +- apps/files_encryption/lib/keymanager.php | 14 +- apps/files_encryption/lib/proxy.php | 9 - apps/files_encryption/lib/stream.php | 35 +-- apps/files_encryption/{tests => test}/binary | Bin .../{tests => test}/crypt.php | 5 +- .../{tests => test}/keymanager.php | 72 +++--- .../{tests => test}/legacy-encrypted-text.txt | Bin apps/files_encryption/test/proxy.php | 220 +++++++++++++++++ apps/files_encryption/test/stream.php | 226 +++++++++++++++++ .../files_encryption/{tests => test}/util.php | 4 +- apps/files_encryption/{tests => test}/zeros | Bin apps/files_encryption/tests/proxy.php | 224 ----------------- apps/files_encryption/tests/stream.php | 227 ------------------ 15 files changed, 513 insertions(+), 540 deletions(-) rename apps/files_encryption/{tests => test}/binary (100%) rename apps/files_encryption/{tests => test}/crypt.php (99%) rename apps/files_encryption/{tests => test}/keymanager.php (56%) rename apps/files_encryption/{tests => test}/legacy-encrypted-text.txt (100%) create mode 100644 apps/files_encryption/test/proxy.php create mode 100644 apps/files_encryption/test/stream.php rename apps/files_encryption/{tests => test}/util.php (98%) rename apps/files_encryption/{tests => test}/zeros (100%) delete mode 100644 apps/files_encryption/tests/proxy.php delete mode 100644 apps/files_encryption/tests/stream.php diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 59bf4921913..c2f97247835 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -60,10 +60,6 @@ class Hooks { # TODO: dont manually encrypt the private keyfile - use the config options of openssl_pkey_export instead for better mobile compatibility - //trigger_error( "\$encryptedKey = ".var_export($encryptedKey)." \n\n\$params['password'] = ".var_export($params['password'] ) ); - -// trigger_error( "\$params['password'] = {$params['password']}" ); - $privateKey = Crypt::symmetricDecryptFileContent( $encryptedKey, $params['password'] ); $session = new Session(); @@ -80,7 +76,6 @@ class Hooks { ) { $_SESSION['legacyenckey'] = Crypt::legacyDecrypt( $legacyKey, $params['password'] ); -// trigger_error('leg enc key = '.$_SESSION['legacyenckey']); } // } @@ -103,8 +98,6 @@ class Hooks { // Get existing decrypted private key $privateKey = $_SESSION['privateKey']; - trigger_error( "\$privateKey = ". var_export($privateKey, 1)); - // Encrypt private key with new user pwd as passphrase $encryptedPrivateKey = Crypt::symmetricEncryptFileContent( $privateKey, $params['password'] ); diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php index 4e2128e89f4..96176210bf1 100755 --- a/apps/files_encryption/lib/crypt.php +++ b/apps/files_encryption/lib/crypt.php @@ -454,7 +454,7 @@ class Crypt { * @returns decrypted file */ public static function keyDecrypt( $encryptedContent, $privatekey ) { - //trigger_error(var_export($privatekey, 1)); + openssl_private_decrypt( $encryptedContent, $plainContent, $privatekey ); return $plainContent; @@ -490,8 +490,6 @@ class Crypt { // Decrypt the keyfile with the user's private key $decryptedKeyfile = self::keyDecrypt( $keyfile, $privateKey ); -// trigger_error( "\$keyfile = ".var_export($keyfile, 1)); - // Decrypt the catfile symmetrically using the decrypted keyfile $decryptedData = self::symmetricDecryptFileContent( $catfile, $decryptedKeyfile ); @@ -682,8 +680,6 @@ class Crypt { */ public static function legacyEncrypt( $content, $passphrase = '' ) { - //trigger_error("OC2 enc \$content = $content \$passphrase = ".var_export($passphrase, 1) ); - $bf = self::getBlowfish( $passphrase ); return $bf->encrypt( $content ); @@ -700,12 +696,8 @@ class Crypt { */ public static function legacyDecrypt( $content, $passphrase = '' ) { - //trigger_error("OC2 dec \$content = $content \$key = ".strlen($passphrase) ); - $bf = self::getBlowfish( $passphrase ); -// trigger_error(var_export($bf, 1) ); - $decrypted = $bf->decrypt( $content ); $trimmed = rtrim( $decrypted, "\0" ); diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index c25c547f0d0..706e1c2661e 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -36,16 +36,20 @@ class Keymanager { * @return string private key or false * @note the key returned by this method must be decrypted before use */ - public static function getPrivateKey( $view, $user ) { + public static function getPrivateKey( \OC_FilesystemView $view, $user ) { - return $view->file_get_contents( '/' . $user . '/' . 'files_encryption' . '/' . $user.'.private.key' ); + $path = '/' . $user . '/' . 'files_encryption' . '/' . $user.'.private.key'; + + $key = $view->file_get_contents( $path ); + + return $key; } /** * @brief retrieve public key for a specified user * @return string public key or false */ - public static function getPublicKey( $view, $userId ) { + public static function getPublicKey( \OC_FilesystemView $view, $userId ) { return $view->file_get_contents( '/public-keys/' . '/' . $userId . '.public.key' ); @@ -55,7 +59,7 @@ class Keymanager { * @brief retrieve both keys from a user (private and public) * @return array keys: privateKey, publicKey */ - public static function getUserKeys( $view, $userId ) { + public static function getUserKeys( \OC_FilesystemView $view, $userId ) { return array( 'publicKey' => self::getPublicKey( $view, $userId ) @@ -71,7 +75,7 @@ class Keymanager { * @note Checks that the sharing app is enabled should be performed * by client code, that isn't checked here */ - public static function getPublicKeys( $view, $userId, $filePath ) { + public static function getPublicKeys( \OC_FilesystemView $view, $userId, $filePath ) { $path = ltrim( $path, '/' ); diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index 0084af94c77..52f47dba294 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -146,7 +146,6 @@ class Proxy extends \OC_FileProxy { Crypt::mode() == 'server' && Crypt::isEncryptedContent( $data ) ) { -// trigger_error("bong"); $split = explode( '/', $path ); @@ -171,10 +170,8 @@ class Proxy extends \OC_FileProxy { && isset( $_SESSION['legacyenckey'] ) && Crypt::isEncryptedMeta( $path ) ) { - trigger_error("mong"); $decrypted = Crypt::legacyDecrypt( $data, $_SESSION['legacyenckey'] ); - //trigger_error($data); } @@ -207,8 +204,6 @@ class Proxy extends \OC_FileProxy { $meta = stream_get_meta_data( $result ); -// trigger_error("\$meta(result) = ".var_export($meta, 1)); - $view = new \OC_FilesystemView( '' ); $util = new Util( $view, \OCP\USER::getUser()); @@ -243,12 +238,8 @@ class Proxy extends \OC_FileProxy { ) { $x = $view->file_get_contents( $path ); - //trigger_error( "size = ".var_export( $x, 1 ) ); - $tmp = tmpfile(); -// trigger_error("Result meta = ".var_export($meta, 1)); - // // Make a temporary copy of the original file // \OCP\Files::streamCopy( $result, $tmp ); // diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php index a98f5bec833..076492cfe3d 100644 --- a/apps/files_encryption/lib/stream.php +++ b/apps/files_encryption/lib/stream.php @@ -134,8 +134,6 @@ class Stream { $this->handle = self::$view->fopen( $this->path_f, $mode ); - //file_put_contents('/home/samtuke/newtmp.txt', 'fucking hopeless = '.$path ); - \OC_FileProxy::$enabled = true; if ( !is_resource( $this->handle ) ) { @@ -170,8 +168,6 @@ class Stream { public function stream_read( $count ) { -// file_put_contents('/home/samtuke/newtmp.txt', "\$count = $count" ); - $this->writeCache = ''; if ( $count != 8192 ) { @@ -188,31 +184,13 @@ class Stream { // // Get the data from the file handle $data = fread( $this->handle, 8192 ); - - //echo "\n\nPRE DECRYPTION = $data\n\n"; -// + if ( strlen( $data ) ) { $this->getKey(); - //$key = file_get_contents( '/home/samtuke/owncloud/git/oc3/data/admin/files_encryption/keyfiles/tmp-1346255589.key' ); - $result = Crypt::symmetricDecryptFileContent( $data, $this->keyfile ); -// file_put_contents('/home/samtuke/newtmp.txt', '$result = '.$result ); - -// echo "\n\n\n\n-----------------------------\n\nNEWS"; -// -// echo "\n\n\$data = $data"; -// -// echo "\n\n\$key = {$this->keyfile}"; -// -// echo "\n\n\$result = $result"; -// -// echo "\n\n\n\n-----------------------------\n\n"; - - //trigger_error("CAT $result"); - } else { $result = ''; @@ -275,8 +253,6 @@ class Stream { $privateKey = $session->getPrivateKey( $this->userId ); -// trigger_error( "privateKey = '".var_export( $privateKey, 1 ) ."'" ); - $this->keyfile = Crypt::keyDecrypt( $this->encKeyfile, $privateKey ); return true; @@ -521,13 +497,16 @@ class Stream { $this->flush(); - if ($this->meta['mode']!='r' and $this->meta['mode']!='rb') { + if ( + $this->meta['mode']!='r' + and $this->meta['mode']!='rb' + ) { - \OC_FileCache::put($this->path,array('encrypted'=>true,'size'=>$this->size),''); + \OC_FileCache::put( $this->path, array( 'encrypted' => true, 'size' => $this->size ), '' ); } - return fclose($this->handle); + return fclose( $this->handle ); } diff --git a/apps/files_encryption/tests/binary b/apps/files_encryption/test/binary similarity index 100% rename from apps/files_encryption/tests/binary rename to apps/files_encryption/test/binary diff --git a/apps/files_encryption/tests/crypt.php b/apps/files_encryption/test/crypt.php similarity index 99% rename from apps/files_encryption/tests/crypt.php rename to apps/files_encryption/test/crypt.php index 4ac53a646b1..5a7820dc9da 100755 --- a/apps/files_encryption/tests/crypt.php +++ b/apps/files_encryption/test/crypt.php @@ -53,6 +53,9 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase { $this->userId = 'admin'; $this->pass = 'admin'; + \OC_Filesystem::init( '/' ); + \OC_Filesystem::mount( 'OC_Filestorage_Local', array('datadir' => \OC_User::getHome($this->userId)), '/' ); + } function tearDown() { @@ -230,8 +233,6 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase { // Get file contents without using any wrapper to get it's actual contents on disk $retreivedCryptedFile = $this->view->file_get_contents( $this->userId . '/files/' . $filename ); - //echo "$retreivedCryptedFile = ".var_export($retreivedCryptedFile, 1); - // Check that the file was encrypted before being written to disk $this->assertNotEquals( $this->dataShort, $retreivedCryptedFile ); diff --git a/apps/files_encryption/tests/keymanager.php b/apps/files_encryption/test/keymanager.php similarity index 56% rename from apps/files_encryption/tests/keymanager.php rename to apps/files_encryption/test/keymanager.php index e31bbe2ab27..f02d6eb5f7a 100644 --- a/apps/files_encryption/tests/keymanager.php +++ b/apps/files_encryption/test/keymanager.php @@ -17,22 +17,36 @@ require_once realpath( dirname(__FILE__).'/../appinfo/app.php' ); use OCA\Encryption; +// This has to go here because otherwise session errors arise, and the private +// encryption key needs to be saved in the session +\OC_User::login( 'admin', 'admin' ); + class Test_Keymanager extends \PHPUnit_Framework_TestCase { function setUp() { - // Set data for use in tests - $this->data = realpath( dirname(__FILE__).'/../lib/crypt.php' ); - $this->user = 'admin'; - $this->passphrase = 'admin'; - $this->filePath = '/testing'; - $this->view = new \OC_FilesystemView( '' ); - - // Disable encryption proxy to prevent recursive calls \OC_FileProxy::$enabled = false; - // Notify system which iser is logged in etc. + // set content for encrypting / decrypting in tests + $this->dataLong = file_get_contents( realpath( dirname(__FILE__).'/../lib/crypt.php' ) ); + $this->dataShort = 'hats'; + $this->dataUrl = realpath( dirname(__FILE__).'/../lib/crypt.php' ); + $this->legacyData = realpath( dirname(__FILE__).'/legacy-text.txt' ); + $this->legacyEncryptedData = realpath( dirname(__FILE__).'/legacy-encrypted-text.txt' ); + $this->randomKey = Encryption\Crypt::generateKey(); + + $keypair = Encryption\Crypt::createKeypair(); + $this->genPublicKey = $keypair['publicKey']; + $this->genPrivateKey = $keypair['privateKey']; + + $this->view = new \OC_FilesystemView( '/' ); + \OC_User::setUserId( 'admin' ); + $this->userId = 'admin'; + $this->pass = 'admin'; + + \OC_Filesystem::init( '/' ); + \OC_Filesystem::mount( 'OC_Filestorage_Local', array('datadir' => \OC_User::getHome($this->userId)), '/' ); } @@ -44,17 +58,16 @@ class Test_Keymanager extends \PHPUnit_Framework_TestCase { function testGetPrivateKey() { - $key = Encryption\Keymanager::getPrivateKey( $this->view, $this->user ); + $key = Encryption\Keymanager::getPrivateKey( $this->view, $this->userId ); - - // Will this length vary? Perhaps we should use a range instead + // Will this length vary? Perhaps we should use a range instead $this->assertEquals( 2296, strlen( $key ) ); } function testGetPublicKey() { - $key = Encryption\Keymanager::getPublicKey( $this->view, $this->user ); + $key = Encryption\Keymanager::getPublicKey( $this->view, $this->userId ); $this->assertEquals( 451, strlen( $key ) ); @@ -72,28 +85,31 @@ class Test_Keymanager extends \PHPUnit_Framework_TestCase { // // $view = new \OC_FilesystemView( '/tmp/' ); // -// //$view = new \OC_FilesystemView( '/' . $this->user . '/files_encryption/keyfiles' ); +// //$view = new \OC_FilesystemView( '/' . $this->userId . '/files_encryption/keyfiles' ); // // Encryption\Keymanager::setFileKey( $tmpPath, $key['key'], $view ); } - function testGetPrivateKey_decrypt() { - - $key = Encryption\Keymanager::getPrivateKey( $this->view, $this->user ); - - # TODO: replace call to Crypt with a mock object? - $decrypted = Encryption\Crypt::symmetricDecryptFileContent( $key, $this->passphrase ); - - $this->assertEquals( 1704, strlen( $decrypted ) ); - - $this->assertEquals( '-----BEGIN PRIVATE KEY-----', substr( $decrypted, 0, 27 ) ); - - } +// /** +// * @depends testGetPrivateKey +// */ +// function testGetPrivateKey_decrypt() { +// +// $key = Encryption\Keymanager::getPrivateKey( $this->view, $this->userId ); +// +// # TODO: replace call to Crypt with a mock object? +// $decrypted = Encryption\Crypt::symmetricDecryptFileContent( $key, $this->passphrase ); +// +// $this->assertEquals( 1704, strlen( $decrypted ) ); +// +// $this->assertEquals( '-----BEGIN PRIVATE KEY-----', substr( $decrypted, 0, 27 ) ); +// +// } function testGetUserKeys() { - $keys = Encryption\Keymanager::getUserKeys( $this->view, $this->user ); + $keys = Encryption\Keymanager::getUserKeys( $this->view, $this->userId ); $this->assertEquals( 451, strlen( $keys['publicKey'] ) ); $this->assertEquals( '-----BEGIN PUBLIC KEY-----', substr( $keys['publicKey'], 0, 26 ) ); @@ -109,7 +125,7 @@ class Test_Keymanager extends \PHPUnit_Framework_TestCase { function testGetFileKey() { -// Encryption\Keymanager::getFileKey( $this->view, $this->user, $this->filePath ); +// Encryption\Keymanager::getFileKey( $this->view, $this->userId, $this->filePath ); } diff --git a/apps/files_encryption/tests/legacy-encrypted-text.txt b/apps/files_encryption/test/legacy-encrypted-text.txt similarity index 100% rename from apps/files_encryption/tests/legacy-encrypted-text.txt rename to apps/files_encryption/test/legacy-encrypted-text.txt diff --git a/apps/files_encryption/test/proxy.php b/apps/files_encryption/test/proxy.php new file mode 100644 index 00000000000..51e77100baa --- /dev/null +++ b/apps/files_encryption/test/proxy.php @@ -0,0 +1,220 @@ +, + * and Robin Appelman + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +// require_once "PHPUnit/Framework/TestCase.php"; +// require_once realpath( dirname(__FILE__).'/../../../lib/base.php' ); +// require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery.php' ); +// require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/Generator.php' ); +// require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/MockInterface.php' ); +// require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/Mock.php' ); +// require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/Container.php' ); +// require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/Configuration.php' ); +// require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/CompositeExpectation.php' ); +// require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/ExpectationDirector.php' ); +// require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/Expectation.php' ); +// require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/Exception.php' ); +// require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/CountValidator/CountValidatorAbstract.php' ); +// require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/CountValidator/Exception.php' ); +// require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/CountValidator/Exact.php' ); +// +// use \Mockery as m; +// use OCA\Encryption; + +// class Test_Util extends \PHPUnit_Framework_TestCase { +// +// public function setUp() { +// +// $this->proxy = new Encryption\Proxy(); +// +// $this->tmpFileName = "tmpFile-".time(); +// +// $this->privateKey = file_get_contents( realpath( dirname(__FILE__).'/data/admin.public.key' ) ); +// $this->publicKey = file_get_contents( realpath( dirname(__FILE__).'/data/admin.private.key' ) ); +// $this->encDataShort = file_get_contents( realpath( dirname(__FILE__).'/data/yoga-manchester-enc' ) ); +// $this->encDataShortKey = file_get_contents( realpath( dirname(__FILE__).'/data/yoga-manchester.key' ) ); +// +// $this->dataShort = file_get_contents( realpath( dirname(__FILE__).'/data/yoga-manchester' ) ); +// $this->dataLong = file_get_contents( realpath( dirname(__FILE__).'/../lib/crypt.php' ) ); +// $this->longDataPath = realpath( dirname(__FILE__).'/../lib/crypt.php' ); +// +// $this->data1 = file_get_contents( realpath( dirname(__FILE__).'/../../../data/admin/files/enc-test.txt' ) ); +// +// \OC_FileProxy::$enabled = false; +// $this->Encdata1 = file_get_contents( realpath( dirname(__FILE__).'/../../../data/admin/files/enc-test.txt' ) ); +// \OC_FileProxy::$enabled = true; +// +// $this->userId = 'admin'; +// $this->pass = 'admin'; +// +// $this->session = new Encryption\Session(); +// +// $this->session->setPrivateKey( +// '-----BEGIN PRIVATE KEY----- +// MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDiH3EA4EpFA7Fx +// s2dyyfL5jwXeYXrTqQJ6DqKgGn8VsbT3eu8R9KzM2XitVwZe8c8L52DvJ06o5vg0 +// GqPYxilFdOFJe/ggac5Tq8UmJiZS4EqYEMwxBIfIyWTxeGV06/0HOwnVAkqHMcBz +// 64qldtgi5O8kZMEM2/gKBgU0kMLJzM+8oEWhL1+gsUWQhxd8cKLXypS6iWgqFJrz +// f/X0hJsJR+gyYxNpahtnjzd/LxLAETrOMsl2tue+BAxmjbAM0aG0NEM0div+b59s +// 2uz/iWbxImp5pOdYVKcVW89D4XBMyGegR40trV2VwiuX1blKCfdjMsJhiaL9pymp +// ug1wzyQFAgMBAAECggEAK6c+PZkPPXuVCgpEcliiW6NM0r2m5K3AGKgypQ34csu3 +// z/8foCvIIFPrhCtEw5eTDQ1CHWlNOjY8vHJYJ0U6Onpx86nHIRrMBkMm8FJ1G5LJ +// U8oKYXwqaozWu/cuPwA//OFc6I5krOzh5n8WaRMkbrgbor8AtebRX74By0AXGrXe +// cswJI7zR96oFn4Dm7Pgvpg5Zhk1vFJ+w6QtH+4DDJ6PBvlZsRkGxYBLGVd/3qhAI +// sBAyjFlSzuP4eCRhHOhHC/e4gmAH9evFVXB88jFyRZm3K+jQ5W5CwrVRBCV2lph6 +// 2B6P7CBJN+IjGKMhy+75y13UvvKPv9IwH8Fzl2x1gQKBgQD8qQOr7a6KhSj16wQE +// jim2xqt9gQ2jH5No405NrKs/PFQQZnzD4YseQsiK//NUjOJiUhaT+L5jhIpzINHt +// RJpt3bGkEZmLyjdjgTpB3GwZdXa28DNK9VdXZ19qIl/ZH0qAjKmJCRahUDASMnVi +// M4Pkk9yx9ZIKkri4TcuMWqc0DQKBgQDlHKBTITZq/arYPD6Nl3NsoOdqVRqJrGay +// 0TjXAVbBXe46+z5lnMsqwXb79nx14hdmSEsZULrw/3f+MnQbdjMTYLFP24visZg9 +// MN8vAiALiiiR1a+Crz+DTA1Q8sGOMVCMqMDmD7QBys3ZuWxuapm0txAiIYUtsjJZ +// XN76T4nZ2QKBgQCHaT3igzwsWTmesxowJtEMeGWomeXpKx8h89EfqA8PkRGsyIDN +// qq+YxEoe1RZgljEuaLhZDdNcGsjo8woPk9kAUPTH7fbRCMuutK+4ZJ469s1tNkcH +// QX5SBcEJbOrZvv967ehe3VQXmJZq6kgnHVzuwKBjcC2ZJRGDFY6l5l/+cQKBgCqh +// +Adf/8NK7paMJ0urqfPFwSodKfICXZ3apswDWMRkmSbqh4La+Uc8dsqN5Dz/VEFZ +// JHhSeGbN8uMfOlG93eU2MehdPxtw1pZUWMNjjtj23XO9ooob2CKzbSrp8TBnZsi1 +// widNNr66oTFpeo7VUUK6acsgF6sYJJxSVr+XO1yJAoGAEhvitq8shNKcEY0xCipS +// k1kbgyS7KKB7opVxI5+ChEqyUDijS3Y9FZixrRIWE6i2uGu86UG+v2lbKvSbM4Qm +// xvbOcX9OVMnlRb7n8woOP10UMY+ZE2x+YEUXQTLtPYq7F66e1OfxltstMxLQA+3d +// Y1d5piFV8PXK3Fg2F+Cj5qg= +// -----END PRIVATE KEY----- +// ' +// , $this->userId +// ); +// +// \OC_User::setUserId( $this->userId ); +// +// } +// +// public function testpreFile_get_contents() { +// +// // This won't work for now because mocking of the static keymanager class isn't working :( +// +// // $mock = m::mock( 'alias:OCA\Encryption\Keymanager' ); +// // +// // $mock->shouldReceive( 'getFileKey' )->times(2)->andReturn( $this->encDataShort ); +// // +// // $encrypted = $this->proxy->postFile_get_contents( 'data/'.$this->tmpFileName, $this->encDataShortKey ); +// // +// // $this->assertNotEquals( $this->dataShort, $encrypted ); +// +// $decrypted = $this->proxy->postFile_get_contents( 'data/admin/files/enc-test.txt', $this->data1 ); +// +// } +// +// } + +// class Test_CryptProxy extends UnitTestCase { +// private $oldConfig; +// private $oldKey; +// +// public function setUp(){ +// $user=OC_User::getUser(); +// +// $this->oldConfig=OCP\Config::getAppValue('files_encryption','enable_encryption','true'); +// OCP\Config::setAppValue('files_encryption','enable_encryption','true'); +// $this->oldKey=isset($_SESSION['privateKey'])?$_SESSION['privateKey']:null; +// +// +// //set testing key +// $_SESSION['privateKey']=md5(time()); +// +// //clear all proxies and hooks so we can do clean testing +// OC_FileProxy::clearProxies(); +// OC_Hook::clear('OC_Filesystem'); +// +// //enable only the encryption hook +// OC_FileProxy::register(new OC_FileProxy_Encryption()); +// +// //set up temporary storage +// OC_Filesystem::clearMounts(); +// OC_Filesystem::mount('OC_Filestorage_Temporary',array(),'/'); +// +// OC_Filesystem::init('/'.$user.'/files'); +// +// //set up the users home folder in the temp storage +// $rootView=new OC_FilesystemView(''); +// $rootView->mkdir('/'.$user); +// $rootView->mkdir('/'.$user.'/files'); +// } +// +// public function tearDown(){ +// OCP\Config::setAppValue('files_encryption','enable_encryption',$this->oldConfig); +// if(!is_null($this->oldKey)){ +// $_SESSION['privateKey']=$this->oldKey; +// } +// } +// +// public function testSimple(){ +// $file=OC::$SERVERROOT.'/3rdparty/MDB2.php'; +// $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)); +// $this->assertEqual($original,$fromFile); +// +// } +// +// public function testView(){ +// $file=OC::$SERVERROOT.'/3rdparty/MDB2.php'; +// $original=file_get_contents($file); +// +// $rootView=new OC_FilesystemView(''); +// $view=new OC_FilesystemView('/'.OC_User::getUser()); +// $userDir='/'.OC_User::getUser().'/files'; +// +// $rootView->file_put_contents($userDir.'/file',$original); +// +// OC_FileProxy::$enabled=false; +// $stored=$rootView->file_get_contents($userDir.'/file'); +// OC_FileProxy::$enabled=true; +// +// $this->assertNotEqual($original,$stored); +// $fromFile=$rootView->file_get_contents($userDir.'/file'); +// $this->assertEqual($original,$fromFile); +// +// $fromFile=$view->file_get_contents('files/file'); +// $this->assertEqual($original,$fromFile); +// } +// +// public function testBinary(){ +// $file=__DIR__.'/binary'; +// $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)); +// $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/test/stream.php b/apps/files_encryption/test/stream.php new file mode 100644 index 00000000000..4211cab3104 --- /dev/null +++ b/apps/files_encryption/test/stream.php @@ -0,0 +1,226 @@ +// +// * This file is licensed under the Affero General Public License version 3 or +// * later. +// * See the COPYING-README file. +// */ +// +// namespace OCA\Encryption; +// +// class Test_Stream extends \PHPUnit_Framework_TestCase { +// +// function setUp() { +// +// \OC_Filesystem::mount( 'OC_Filestorage_Local', array(), '/' ); +// +// $this->empty = ''; +// +// $this->stream = new Stream(); +// +// $this->dataLong = file_get_contents( realpath( dirname(__FILE__).'/../lib/crypt.php' ) ); +// $this->dataShort = 'hats'; +// +// $this->emptyTmpFilePath = \OCP\Files::tmpFile(); +// +// $this->dataTmpFilePath = \OCP\Files::tmpFile(); +// +// file_put_contents( $this->dataTmpFilePath, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In rutrum accumsan ultricies. Mauris vitae nisi at sem facilisis semper ac in est." ); +// +// } +// +// function testStreamOpen() { +// +// $stream1 = new Stream(); +// +// $handle1 = $stream1->stream_open( $this->emptyTmpFilePath, 'wb', array(), $this->empty ); +// +// // Test that resource was returned successfully +// $this->assertTrue( $handle1 ); +// +// // Test that file has correct size +// $this->assertEquals( 0, $stream1->size ); +// +// // Test that path is correct +// $this->assertEquals( $this->emptyTmpFilePath, $stream1->rawPath ); +// +// $stream2 = new Stream(); +// +// $handle2 = $stream2->stream_open( 'crypt://' . $this->emptyTmpFilePath, 'wb', array(), $this->empty ); +// +// // Test that protocol identifier is removed from path +// $this->assertEquals( $this->emptyTmpFilePath, $stream2->rawPath ); +// +// // "Stat failed error" prevents this test from executing +// // $stream3 = new Stream(); +// // +// // $handle3 = $stream3->stream_open( $this->dataTmpFilePath, 'r', array(), $this->empty ); +// // +// // $this->assertEquals( 0, $stream3->size ); +// +// } +// +// function testStreamWrite() { +// +// $stream1 = new Stream(); +// +// $handle1 = $stream1->stream_open( $this->emptyTmpFilePath, 'r+b', array(), $this->empty ); +// +// # what about the keymanager? there is no key for the newly created temporary file! +// +// $stream1->stream_write( $this->dataShort ); +// +// } +// +// // function getStream( $id, $mode, $size ) { +// // +// // if ( $id === '' ) { +// // +// // $id = uniqid(); +// // } +// // +// // +// // if ( !isset( $this->tmpFiles[$id] ) ) { +// // +// // // If tempfile with given name does not already exist, create it +// // +// // $file = OCP\Files::tmpFile(); +// // +// // $this->tmpFiles[$id] = $file; +// // +// // } else { +// // +// // $file = $this->tmpFiles[$id]; +// // +// // } +// // +// // $stream = fopen( $file, $mode ); +// // +// // Stream::$sourceStreams[$id] = array( 'path' => 'dummy' . $id, 'stream' => $stream, 'size' => $size ); +// // +// // return fopen( 'crypt://streams/'.$id, $mode ); +// // +// // } +// // +// // function testStream( ){ +// // +// // $stream = $this->getStream( 'test1', 'w', strlen( 'foobar' ) ); +// // +// // fwrite( $stream, 'foobar' ); +// // +// // fclose( $stream ); +// // +// // +// // $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', 0 ); +// // +// // OCP\Files::streamCopy( $source, $target ); +// // +// // fclose( $target ); +// // +// // fclose( $source ); +// // +// // +// // $stream = $this->getStream( 'test2', 'r', filesize( $file ) ); +// // +// // $data = stream_get_contents( $stream ); +// // +// // $original = file_get_contents( $file ); +// // +// // $this->assertEqual( strlen( $original ), strlen( $data ) ); +// // +// // $this->assertEqual( $original, $data ); +// // +// // } +// +// } +// +// // class Test_CryptStream extends UnitTestCase { +// // private $tmpFiles=array(); +// // +// // function testStream(){ +// // $stream=$this->getStream('test1','w',strlen('foobar')); +// // fwrite($stream,'foobar'); +// // fclose($stream); +// // +// // $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',0); +// // OCP\Files::streamCopy($source,$target); +// // fclose($target); +// // fclose($source); +// // +// // $stream=$this->getStream('test2','r',filesize($file)); +// // $data=stream_get_contents($stream); +// // $original=file_get_contents($file); +// // $this->assertEqual(strlen($original),strlen($data)); +// // $this->assertEqual($original,$data); +// // } +// // +// // /** +// // * get a cryptstream to a temporary file +// // * @param string $id +// // * @param string $mode +// // * @param int size +// // * @return resource +// // */ +// // function getStream($id,$mode,$size){ +// // if($id===''){ +// // $id=uniqid(); +// // } +// // if(!isset($this->tmpFiles[$id])){ +// // $file=OCP\Files::tmpFile(); +// // $this->tmpFiles[$id]=$file; +// // }else{ +// // $file=$this->tmpFiles[$id]; +// // } +// // $stream=fopen($file,$mode); +// // OC_CryptStream::$sourceStreams[$id]=array('path'=>'dummy'.$id,'stream'=>$stream,'size'=>$size); +// // return fopen('crypt://streams/'.$id,$mode); +// // } +// // +// // function testBinary(){ +// // $file=__DIR__.'/binary'; +// // $source=file_get_contents($file); +// // +// // $stream=$this->getStream('test','w',strlen($source)); +// // fwrite($stream,$source); +// // fclose($stream); +// // +// // $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)); +// // $this->assertEqual($source,$data); +// // } +// // } diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/test/util.php similarity index 98% rename from apps/files_encryption/tests/util.php rename to apps/files_encryption/test/util.php index 30ec26d3aaa..016787fbfba 100755 --- a/apps/files_encryption/tests/util.php +++ b/apps/files_encryption/test/util.php @@ -24,9 +24,11 @@ $loader->register(); use \Mockery as m; use OCA\Encryption; -class Test_Util extends \PHPUnit_Framework_TestCase { +class Test_Enc_Util extends \PHPUnit_Framework_TestCase { function setUp() { + + \OC_Filesystem::mount( 'OC_Filestorage_Local', array(), '/' ); // set content for encrypting / decrypting in tests $this->dataUrl = realpath( dirname(__FILE__).'/../lib/crypt.php' ); diff --git a/apps/files_encryption/tests/zeros b/apps/files_encryption/test/zeros similarity index 100% rename from apps/files_encryption/tests/zeros rename to apps/files_encryption/test/zeros diff --git a/apps/files_encryption/tests/proxy.php b/apps/files_encryption/tests/proxy.php deleted file mode 100644 index 87151234e0e..00000000000 --- a/apps/files_encryption/tests/proxy.php +++ /dev/null @@ -1,224 +0,0 @@ -, - * and Robin Appelman - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -require_once "PHPUnit/Framework/TestCase.php"; -require_once realpath( dirname(__FILE__).'/../../../lib/base.php' ); -require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery.php' ); -require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/Generator.php' ); -require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/MockInterface.php' ); -require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/Mock.php' ); -require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/Container.php' ); -require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/Configuration.php' ); -require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/CompositeExpectation.php' ); -require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/ExpectationDirector.php' ); -require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/Expectation.php' ); -require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/Exception.php' ); -require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/CountValidator/CountValidatorAbstract.php' ); -require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/CountValidator/Exception.php' ); -require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/CountValidator/Exact.php' ); - -use \Mockery as m; -use OCA\Encryption; - -class Test_Util extends \PHPUnit_Framework_TestCase { - - public function setUp() { - - $this->proxy = new Encryption\Proxy(); - - $this->tmpFileName = "tmpFile-".time(); - - $this->privateKey = file_get_contents( realpath( dirname(__FILE__).'/data/admin.public.key' ) ); - $this->publicKey = file_get_contents( realpath( dirname(__FILE__).'/data/admin.private.key' ) ); - $this->encDataShort = file_get_contents( realpath( dirname(__FILE__).'/data/yoga-manchester-enc' ) ); - $this->encDataShortKey = file_get_contents( realpath( dirname(__FILE__).'/data/yoga-manchester.key' ) ); - - $this->dataShort = file_get_contents( realpath( dirname(__FILE__).'/data/yoga-manchester' ) ); - $this->dataLong = file_get_contents( realpath( dirname(__FILE__).'/../lib/crypt.php' ) ); - $this->longDataPath = realpath( dirname(__FILE__).'/../lib/crypt.php' ); - - $this->data1 = file_get_contents( realpath( dirname(__FILE__).'/../../../data/admin/files/enc-test.txt' ) ); - - \OC_FileProxy::$enabled = false; - $this->Encdata1 = file_get_contents( realpath( dirname(__FILE__).'/../../../data/admin/files/enc-test.txt' ) ); - \OC_FileProxy::$enabled = true; - - $this->userId = 'admin'; - $this->pass = 'admin'; - - $this->session = new Encryption\Session(); - -$this->session->setPrivateKey( -'-----BEGIN PRIVATE KEY----- -MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDiH3EA4EpFA7Fx -s2dyyfL5jwXeYXrTqQJ6DqKgGn8VsbT3eu8R9KzM2XitVwZe8c8L52DvJ06o5vg0 -GqPYxilFdOFJe/ggac5Tq8UmJiZS4EqYEMwxBIfIyWTxeGV06/0HOwnVAkqHMcBz -64qldtgi5O8kZMEM2/gKBgU0kMLJzM+8oEWhL1+gsUWQhxd8cKLXypS6iWgqFJrz -f/X0hJsJR+gyYxNpahtnjzd/LxLAETrOMsl2tue+BAxmjbAM0aG0NEM0div+b59s -2uz/iWbxImp5pOdYVKcVW89D4XBMyGegR40trV2VwiuX1blKCfdjMsJhiaL9pymp -ug1wzyQFAgMBAAECggEAK6c+PZkPPXuVCgpEcliiW6NM0r2m5K3AGKgypQ34csu3 -z/8foCvIIFPrhCtEw5eTDQ1CHWlNOjY8vHJYJ0U6Onpx86nHIRrMBkMm8FJ1G5LJ -U8oKYXwqaozWu/cuPwA//OFc6I5krOzh5n8WaRMkbrgbor8AtebRX74By0AXGrXe -cswJI7zR96oFn4Dm7Pgvpg5Zhk1vFJ+w6QtH+4DDJ6PBvlZsRkGxYBLGVd/3qhAI -sBAyjFlSzuP4eCRhHOhHC/e4gmAH9evFVXB88jFyRZm3K+jQ5W5CwrVRBCV2lph6 -2B6P7CBJN+IjGKMhy+75y13UvvKPv9IwH8Fzl2x1gQKBgQD8qQOr7a6KhSj16wQE -jim2xqt9gQ2jH5No405NrKs/PFQQZnzD4YseQsiK//NUjOJiUhaT+L5jhIpzINHt -RJpt3bGkEZmLyjdjgTpB3GwZdXa28DNK9VdXZ19qIl/ZH0qAjKmJCRahUDASMnVi -M4Pkk9yx9ZIKkri4TcuMWqc0DQKBgQDlHKBTITZq/arYPD6Nl3NsoOdqVRqJrGay -0TjXAVbBXe46+z5lnMsqwXb79nx14hdmSEsZULrw/3f+MnQbdjMTYLFP24visZg9 -MN8vAiALiiiR1a+Crz+DTA1Q8sGOMVCMqMDmD7QBys3ZuWxuapm0txAiIYUtsjJZ -XN76T4nZ2QKBgQCHaT3igzwsWTmesxowJtEMeGWomeXpKx8h89EfqA8PkRGsyIDN -qq+YxEoe1RZgljEuaLhZDdNcGsjo8woPk9kAUPTH7fbRCMuutK+4ZJ469s1tNkcH -QX5SBcEJbOrZvv967ehe3VQXmJZq6kgnHVzuwKBjcC2ZJRGDFY6l5l/+cQKBgCqh -+Adf/8NK7paMJ0urqfPFwSodKfICXZ3apswDWMRkmSbqh4La+Uc8dsqN5Dz/VEFZ -JHhSeGbN8uMfOlG93eU2MehdPxtw1pZUWMNjjtj23XO9ooob2CKzbSrp8TBnZsi1 -widNNr66oTFpeo7VUUK6acsgF6sYJJxSVr+XO1yJAoGAEhvitq8shNKcEY0xCipS -k1kbgyS7KKB7opVxI5+ChEqyUDijS3Y9FZixrRIWE6i2uGu86UG+v2lbKvSbM4Qm -xvbOcX9OVMnlRb7n8woOP10UMY+ZE2x+YEUXQTLtPYq7F66e1OfxltstMxLQA+3d -Y1d5piFV8PXK3Fg2F+Cj5qg= ------END PRIVATE KEY----- -' -, $this->userId -); - - \OC_User::setUserId( $this->userId ); - - } - - public function testpreFile_get_contents() { - - // This won't work for now because mocking of the static keymanager class isn't working :( - -// $mock = m::mock( 'alias:OCA\Encryption\Keymanager' ); -// -// $mock->shouldReceive( 'getFileKey' )->times(2)->andReturn( $this->encDataShort ); -// -// $encrypted = $this->proxy->postFile_get_contents( 'data/'.$this->tmpFileName, $this->encDataShortKey ); -// -// $this->assertNotEquals( $this->dataShort, $encrypted ); -// -// var_dump($encrypted); - - $decrypted = $this->proxy->postFile_get_contents( 'data/admin/files/enc-test.txt', $this->data1 ); - - var_dump($decrypted); - - } - -} - -// class Test_CryptProxy extends UnitTestCase { -// private $oldConfig; -// private $oldKey; -// -// public function setUp(){ -// $user=OC_User::getUser(); -// -// $this->oldConfig=OCP\Config::getAppValue('files_encryption','enable_encryption','true'); -// OCP\Config::setAppValue('files_encryption','enable_encryption','true'); -// $this->oldKey=isset($_SESSION['privateKey'])?$_SESSION['privateKey']:null; -// -// -// //set testing key -// $_SESSION['privateKey']=md5(time()); -// -// //clear all proxies and hooks so we can do clean testing -// OC_FileProxy::clearProxies(); -// OC_Hook::clear('OC_Filesystem'); -// -// //enable only the encryption hook -// OC_FileProxy::register(new OC_FileProxy_Encryption()); -// -// //set up temporary storage -// OC_Filesystem::clearMounts(); -// OC_Filesystem::mount('OC_Filestorage_Temporary',array(),'/'); -// -// OC_Filesystem::init('/'.$user.'/files'); -// -// //set up the users home folder in the temp storage -// $rootView=new OC_FilesystemView(''); -// $rootView->mkdir('/'.$user); -// $rootView->mkdir('/'.$user.'/files'); -// } -// -// public function tearDown(){ -// OCP\Config::setAppValue('files_encryption','enable_encryption',$this->oldConfig); -// if(!is_null($this->oldKey)){ -// $_SESSION['privateKey']=$this->oldKey; -// } -// } -// -// public function testSimple(){ -// $file=OC::$SERVERROOT.'/3rdparty/MDB2.php'; -// $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)); -// $this->assertEqual($original,$fromFile); -// -// } -// -// public function testView(){ -// $file=OC::$SERVERROOT.'/3rdparty/MDB2.php'; -// $original=file_get_contents($file); -// -// $rootView=new OC_FilesystemView(''); -// $view=new OC_FilesystemView('/'.OC_User::getUser()); -// $userDir='/'.OC_User::getUser().'/files'; -// -// $rootView->file_put_contents($userDir.'/file',$original); -// -// OC_FileProxy::$enabled=false; -// $stored=$rootView->file_get_contents($userDir.'/file'); -// OC_FileProxy::$enabled=true; -// -// $this->assertNotEqual($original,$stored); -// $fromFile=$rootView->file_get_contents($userDir.'/file'); -// $this->assertEqual($original,$fromFile); -// -// $fromFile=$view->file_get_contents('files/file'); -// $this->assertEqual($original,$fromFile); -// } -// -// public function testBinary(){ -// $file=__DIR__.'/binary'; -// $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)); -// $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 deleted file mode 100644 index 52e85fe4850..00000000000 --- a/apps/files_encryption/tests/stream.php +++ /dev/null @@ -1,227 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -namespace OCA\Encryption; - -require_once "PHPUnit/Framework/TestCase.php"; -require_once realpath( dirname(__FILE__).'/../../../lib/base.php' ); - -class Test_Stream extends \PHPUnit_Framework_TestCase { - - function setUp() { - - $this->empty = ''; - - $this->stream = new Stream(); - - $this->dataLong = file_get_contents( realpath( dirname(__FILE__).'/../lib/crypt.php' ) ); - $this->dataShort = 'hats'; - - $this->emptyTmpFilePath = \OCP\Files::tmpFile(); - - $this->dataTmpFilePath = \OCP\Files::tmpFile(); - - file_put_contents( $this->dataTmpFilePath, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In rutrum accumsan ultricies. Mauris vitae nisi at sem facilisis semper ac in est." ); - - } - - function testStreamOpen() { - - $stream1 = new Stream(); - - $handle1 = $stream1->stream_open( $this->emptyTmpFilePath, 'wb', array(), $this->empty ); - - // Test that resource was returned successfully - $this->assertTrue( $handle1 ); - - // Test that file has correct size - $this->assertEquals( 0, $stream1->size ); - - // Test that path is correct - $this->assertEquals( $this->emptyTmpFilePath, $stream1->rawPath ); - - $stream2 = new Stream(); - - $handle2 = $stream2->stream_open( 'crypt://' . $this->emptyTmpFilePath, 'wb', array(), $this->empty ); - - // Test that protocol identifier is removed from path - $this->assertEquals( $this->emptyTmpFilePath, $stream2->rawPath ); - - // "Stat failed error" prevents this test from executing -// $stream3 = new Stream(); -// -// $handle3 = $stream3->stream_open( $this->dataTmpFilePath, 'r', array(), $this->empty ); -// -// $this->assertEquals( 0, $stream3->size ); - - } - - function testStreamWrite() { - - $stream1 = new Stream(); - - $handle1 = $stream1->stream_open( $this->emptyTmpFilePath, 'r+b', array(), $this->empty ); - - # what about the keymanager? there is no key for the newly created temporary file! - - $stream1->stream_write( $this->dataShort ); - - } - -// function getStream( $id, $mode, $size ) { -// -// if ( $id === '' ) { -// -// $id = uniqid(); -// } -// -// -// if ( !isset( $this->tmpFiles[$id] ) ) { -// -// // If tempfile with given name does not already exist, create it -// -// $file = OCP\Files::tmpFile(); -// -// $this->tmpFiles[$id] = $file; -// -// } else { -// -// $file = $this->tmpFiles[$id]; -// -// } -// -// $stream = fopen( $file, $mode ); -// -// Stream::$sourceStreams[$id] = array( 'path' => 'dummy' . $id, 'stream' => $stream, 'size' => $size ); -// -// return fopen( 'crypt://streams/'.$id, $mode ); -// -// } -// -// function testStream( ){ -// -// $stream = $this->getStream( 'test1', 'w', strlen( 'foobar' ) ); -// -// fwrite( $stream, 'foobar' ); -// -// fclose( $stream ); -// -// -// $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', 0 ); -// -// OCP\Files::streamCopy( $source, $target ); -// -// fclose( $target ); -// -// fclose( $source ); -// -// -// $stream = $this->getStream( 'test2', 'r', filesize( $file ) ); -// -// $data = stream_get_contents( $stream ); -// -// $original = file_get_contents( $file ); -// -// $this->assertEqual( strlen( $original ), strlen( $data ) ); -// -// $this->assertEqual( $original, $data ); -// -// } - -} - -// class Test_CryptStream extends UnitTestCase { -// private $tmpFiles=array(); -// -// function testStream(){ -// $stream=$this->getStream('test1','w',strlen('foobar')); -// fwrite($stream,'foobar'); -// fclose($stream); -// -// $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',0); -// OCP\Files::streamCopy($source,$target); -// fclose($target); -// fclose($source); -// -// $stream=$this->getStream('test2','r',filesize($file)); -// $data=stream_get_contents($stream); -// $original=file_get_contents($file); -// $this->assertEqual(strlen($original),strlen($data)); -// $this->assertEqual($original,$data); -// } -// -// /** -// * get a cryptstream to a temporary file -// * @param string $id -// * @param string $mode -// * @param int size -// * @return resource -// */ -// function getStream($id,$mode,$size){ -// if($id===''){ -// $id=uniqid(); -// } -// if(!isset($this->tmpFiles[$id])){ -// $file=OCP\Files::tmpFile(); -// $this->tmpFiles[$id]=$file; -// }else{ -// $file=$this->tmpFiles[$id]; -// } -// $stream=fopen($file,$mode); -// OC_CryptStream::$sourceStreams[$id]=array('path'=>'dummy'.$id,'stream'=>$stream,'size'=>$size); -// return fopen('crypt://streams/'.$id,$mode); -// } -// -// function testBinary(){ -// $file=__DIR__.'/binary'; -// $source=file_get_contents($file); -// -// $stream=$this->getStream('test','w',strlen($source)); -// fwrite($stream,$source); -// fclose($stream); -// -// $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)); -// $this->assertEqual($source,$data); -// } -// } -- 2.39.5