Blame view
sources/apps/files_encryption/tests/proxy.php
9.09 KB
|
03e52840d
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
<?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.
*/
// 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
// s2dyyfL5jwXeYXrTqQ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JtEMeGWomeXpKx8h89EfqA8PkRGsyIDN
// 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 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));
// }
// }
|