2012-08-15 17:01:43 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2012 Sam Tuke <samtuke@owncloud.com>
|
|
|
|
* 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_Keymanager extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
|
|
|
function setUp() {
|
|
|
|
|
2012-08-23 19:43:10 +04:00
|
|
|
// Set data for use in tests
|
|
|
|
$this->data = realpath( dirname(__FILE__).'/../lib/crypt.php' );
|
2012-08-15 17:01:43 +04:00
|
|
|
$this->user = 'admin';
|
2012-08-15 17:13:03 +04:00
|
|
|
$this->passphrase = 'admin';
|
2012-08-15 17:01:43 +04:00
|
|
|
$this->view = new \OC_FilesystemView( '' );
|
|
|
|
|
|
|
|
// Disable encryption proxy to prevent recursive calls
|
|
|
|
\OC_FileProxy::$enabled = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function tearDown(){
|
|
|
|
|
2012-08-15 17:13:03 +04:00
|
|
|
\OC_FileProxy::$enabled = true;
|
2012-08-15 17:01:43 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-08-15 17:13:03 +04:00
|
|
|
function testGetEncryptedPrivateKey() {
|
2012-08-15 17:01:43 +04:00
|
|
|
|
|
|
|
$key = Keymanager::getPrivateKey( $this->user, $this->view );
|
|
|
|
|
|
|
|
$this->assertEquals( 2302, strlen( $key ) );
|
2012-08-15 17:13:03 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-08-23 19:43:10 +04:00
|
|
|
function testSetFileKey() {
|
|
|
|
|
|
|
|
# NOTE: This cannot be tested until we are able to break out of the FileSystemView data directory root
|
|
|
|
|
|
|
|
// $key = Crypt::symmetricEncryptFileContentKeyfile( $this->data, 'hat' );
|
|
|
|
//
|
|
|
|
// $tmpPath = sys_get_temp_dir(). '/' . 'testSetFileKey';
|
|
|
|
//
|
|
|
|
// $view = new \OC_FilesystemView( '/tmp/' );
|
|
|
|
//
|
|
|
|
// //$view = new \OC_FilesystemView( '/' . $this->user . '/files_encryption/keyfiles' );
|
|
|
|
//
|
|
|
|
// Keymanager::setFileKey( $tmpPath, $key['key'], $view );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-08-15 17:13:03 +04:00
|
|
|
function testGetDecryptedPrivateKey() {
|
|
|
|
|
|
|
|
$key = Keymanager::getPrivateKey( $this->user, $this->view );
|
|
|
|
|
2012-08-15 21:49:53 +04:00
|
|
|
# TODO: replace call to Crypt with a mock object?
|
2012-08-15 17:13:03 +04:00
|
|
|
$decrypted = Crypt::symmetricDecryptFileContent( $key, $this->passphrase );
|
|
|
|
|
|
|
|
$this->assertEquals( 1708, strlen( $decrypted ) );
|
2012-08-15 17:01:43 +04:00
|
|
|
|
2012-08-15 17:13:03 +04:00
|
|
|
$this->assertEquals( '-----BEGIN PRIVATE KEY-----', substr( $decrypted, 0, 27 ) );
|
2012-08-15 17:01:43 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-08-23 19:43:10 +04:00
|
|
|
|
|
|
|
|
2012-08-15 17:01:43 +04:00
|
|
|
}
|