mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Development snapshot, mocking out Session{} for crypt unit tests
This commit is contained in:
parent
bf69677933
commit
665261dc9a
5 changed files with 35 additions and 20 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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'] )
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue