Skip to content
Snippets Groups Projects
Commit 0d4117f6 authored by Björn Schießle's avatar Björn Schießle
Browse files

added simple test for getFileSize proxy

parent 52501d6b
No related branches found
No related tags found
No related merge requests found
<?php
/**
* Copyright (c) 2012 Sam Tuke <samtuke@owncloud.com>,
* and Robin Appelman <icewind@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
* ownCloud
*
* @author Bjoern Schiessle
* @copyright 2013 Bjoern Schiessle <schiessle@owncloud.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
// 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( $view ); // FIXME: Provide a $view object for use here
//
// $this->session->setPrivateKey(
// '-----BEGIN PRIVATE KEY-----
// MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDiH3EA4EpFA7Fx
// s2dyyfL5jwXeYXrTqQJ6DqKgGn8VsbT3eu8R9KzM2XitVwZe8c8L52DvJ06o5vg0
// GqPYxilFdOFJe/ggac5Tq8UmJiZS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CMuutK+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 PHPUnit_Framework_TestCase {
// 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->assertNotEquals($original,$stored);
// $this->assertEquals(strlen($original),strlen($fromFile));
// $this->assertEquals($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->assertNotEquals($original,$stored);
// $fromFile=$rootView->file_get_contents($userDir.'/file');
// $this->assertEquals($original,$fromFile);
//
// $fromFile=$view->file_get_contents('files/file');
// $this->assertEquals($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->assertNotEquals($original,$stored);
// $this->assertEquals(strlen($original),strlen($fromFile));
// $this->assertEquals($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->assertNotEquals($original,$stored);
// $this->assertEquals(strlen($original),strlen($fromFile));
// }
// }
require_once __DIR__ . '/../../../lib/base.php';
require_once __DIR__ . '/../lib/crypt.php';
require_once __DIR__ . '/../lib/keymanager.php';
require_once __DIR__ . '/../lib/proxy.php';
require_once __DIR__ . '/../lib/stream.php';
require_once __DIR__ . '/../lib/util.php';
require_once __DIR__ . '/../appinfo/app.php';
require_once __DIR__ . '/util.php';
use OCA\Encryption;
/**
* Class Test_Encryption_Proxy
* @brief this class provide basic proxy app tests
*/
class Test_Encryption_Proxy extends \PHPUnit_Framework_TestCase {
const TEST_ENCRYPTION_PROXY_USER1 = "test-proxy-user1";
public $userId;
public $pass;
/**
* @var \OC_FilesystemView
*/
public $view;
public $data;
public static function setUpBeforeClass() {
// reset backend
\OC_User::clearBackends();
\OC_User::useBackend('database');
\OC_Hook::clear('OC_Filesystem');
\OC_Hook::clear('OC_User');
// Filesystem related hooks
\OCA\Encryption\Helper::registerFilesystemHooks();
// clear and register hooks
\OC_FileProxy::clearProxies();
\OC_FileProxy::register(new OCA\Encryption\Proxy());
// create test user
\Test_Encryption_Util::loginHelper(\Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1, true);
}
function setUp() {
// set user id
\OC_User::setUserId(\Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1);
$this->userId = \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1;
$this->pass = \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1;
// init filesystem view
$this->view = new \OC_FilesystemView('/'. \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '/files');
// init short data
$this->data = 'hats';
}
public static function tearDownAfterClass() {
// cleanup test user
\OC_User::deleteUser(\Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1);
}
/**
* @medium
* @brief test delete file
*/
function testPostFileSize() {
// generate filename
$filename = 'tmp-' . time() . '.txt';
$this->view->file_put_contents($filename, $this->data);
\OC_FileProxy::$enabled = false;
$unencryptedSize = $this->view->filesize($filename);
\OC_FileProxy::$enabled = true;
$encryptedSize = $this->view->filesize($filename);
$this->assertTrue($encryptedSize !== $unencryptedSize);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment