diff options
author | Sam Tuke <samtuke@owncloud.com> | 2013-01-02 19:29:22 +0000 |
---|---|---|
committer | Sam Tuke <samtuke@owncloud.com> | 2013-01-02 19:29:22 +0000 |
commit | 665261dc9a475abd53c41422a93a549c071c04c4 (patch) | |
tree | 537d9fa867225de36b0cbca4c3a5e14fdb369a40 /apps/files_encryption | |
parent | bf6967793393bd2bf42a2a76e5a3722be2dc01c4 (diff) | |
download | nextcloud-server-665261dc9a475abd53c41422a93a549c071c04c4.tar.gz nextcloud-server-665261dc9a475abd53c41422a93a549c071c04c4.zip |
Development snapshot, mocking out Session{} for crypt unit tests
Diffstat (limited to 'apps/files_encryption')
-rwxr-xr-x | apps/files_encryption/lib/crypt.php | 2 | ||||
-rw-r--r-- | apps/files_encryption/lib/session.php | 4 | ||||
-rw-r--r-- | apps/files_encryption/lib/stream.php | 8 | ||||
-rwxr-xr-x | apps/files_encryption/tests/crypt.php | 22 | ||||
-rwxr-xr-x | apps/files_encryption/tests/util.php | 19 |
5 files changed, 35 insertions, 20 deletions
diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php index 06a34c8f4d6..7895a5dd7b0 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;
diff --git a/apps/files_encryption/lib/session.php b/apps/files_encryption/lib/session.php index 946e5a6eddd..85d533fde7a 100644 --- a/apps/files_encryption/lib/session.php +++ b/apps/files_encryption/lib/session.php @@ -33,7 +33,7 @@ class Session { * @return bool * */ - public static function setPrivateKey( $privateKey, $userId ) { + public function setPrivateKey( $privateKey, $userId ) { $_SESSION['privateKey'] = $privateKey; @@ -46,7 +46,7 @@ class Session { * @returns string $privateKey The user's plaintext private key * */ - public static function getPrivateKey( $userId ) { + public function getPrivateKey( $userId ) { if ( isset( $_SESSION['privateKey'] ) diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php index 934b286e6eb..dcdad7ee561 100644 --- a/apps/files_encryption/lib/stream.php +++ b/apps/files_encryption/lib/stream.php @@ -265,7 +265,11 @@ class Stream { $session = new Session(); - $this->keyfile = Crypt::keyDecrypt( $this->encKeyfile, $session->getPrivateKey( $this->userId ) ); + $privateKey = $session->getPrivateKey( $this->userId ); + +// trigger_error( "privateKey = '".var_export( $privateKey, 1 ) ."'" ); + + $this->keyfile = Crypt::keyDecrypt( $this->encKeyfile, $privateKey ); return true; @@ -302,7 +306,7 @@ class Stream { * @note PHP automatically updates the file pointer after writing data to reflect it's length. There is generally no need to update the poitner manually using fseek */ public function stream_write( $data ) { - trigger_error("goon"); + // Disable the file proxies so that encryption is not automatically attempted when the file is written to disk - we are handling that separately here and we don't want to get into an infinite loop \OC_FileProxy::$enabled = false; diff --git a/apps/files_encryption/tests/crypt.php b/apps/files_encryption/tests/crypt.php index 3522bd40c9f..e64ec15c82f 100755 --- a/apps/files_encryption/tests/crypt.php +++ b/apps/files_encryption/tests/crypt.php @@ -7,7 +7,20 @@ * See the COPYING-README file. */ +// Load mockery files +require_once 'Mockery/Loader.php'; +require_once 'Hamcrest/Hamcrest.php'; +$loader = new \Mockery\Loader; +$loader->register(); +use \Mockery as m; + +// Overload Session{} with a mock object before it is included +$adminEncPriKey = realpath( dirname(__FILE__).'/../../../data/admin/files_encryption/admin.private.key' ); +$adminDePriKey = OCA\Encryption\Crypt::symmetricDecryptFileContent( $adminEncPriKey, 'admin' ); + +$mockSession = m::mock('overload:OCA\Encryption\Session'); +$mockSession->shouldReceive( 'getPrivateKey' )->andReturn( file_get_contents( $adminDePriKey ) ); //require_once "PHPUnit/Framework/TestCase.php"; require_once realpath( dirname(__FILE__).'/../../../3rdparty/Crypt_Blowfish/Blowfish.php' ); @@ -25,7 +38,7 @@ use OCA\Encryption; // encryption key needs to be saved in the session \OC_User::login( 'admin', 'admin' ); -trigger_error("session = ".var_export($_SESSION, 1)); +//trigger_error("session = ".var_export($_SESSION, 1)); class Test_Crypt extends \PHPUnit_Framework_TestCase { @@ -45,12 +58,17 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase { $this->view = new \OC_FilesystemView( '/' ); + \OC_User::setUserId( 'admin' ); $this->userId = 'admin'; $this->pass = 'admin'; } - function tearDown(){} + function tearDown() { + + m::close(); + + } function testGenerateKey() { diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php index 81a7ae1ff2c..30ec26d3aaa 100755 --- a/apps/files_encryption/tests/util.php +++ b/apps/files_encryption/tests/util.php @@ -14,19 +14,12 @@ require_once realpath( dirname(__FILE__).'/../lib/proxy.php' ); require_once realpath( dirname(__FILE__).'/../lib/stream.php' ); require_once realpath( dirname(__FILE__).'/../lib/util.php' ); require_once realpath( dirname(__FILE__).'/../appinfo/app.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' ); + +// Load mockery files +require_once 'Mockery/Loader.php'; +require_once 'Hamcrest/Hamcrest.php'; +$loader = new \Mockery\Loader; +$loader->register(); use \Mockery as m; use OCA\Encryption; |