aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_encryption/tests
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_encryption/tests')
-rw-r--r--apps/files_encryption/tests/binarybin9734 -> 0 bytes
-rw-r--r--apps/files_encryption/tests/encryption.php72
-rw-r--r--apps/files_encryption/tests/proxy.php117
-rw-r--r--apps/files_encryption/tests/stream.php85
-rw-r--r--apps/files_encryption/tests/zerosbin10238 -> 0 bytes
5 files changed, 0 insertions, 274 deletions
diff --git a/apps/files_encryption/tests/binary b/apps/files_encryption/tests/binary
deleted file mode 100644
index 79bc99479da..00000000000
--- a/apps/files_encryption/tests/binary
+++ /dev/null
Binary files differ
diff --git a/apps/files_encryption/tests/encryption.php b/apps/files_encryption/tests/encryption.php
deleted file mode 100644
index 0e119f55bea..00000000000
--- a/apps/files_encryption/tests/encryption.php
+++ /dev/null
@@ -1,72 +0,0 @@
-<?php
-/**
- * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-class Test_Encryption extends UnitTestCase {
- function testEncryption() {
- $key=uniqid();
- $file=OC::$SERVERROOT.'/3rdparty/MDB2.php';
- $source=file_get_contents($file); //nice large text file
- $encrypted=OC_Crypt::encrypt($source, $key);
- $decrypted=OC_Crypt::decrypt($encrypted, $key);
- $decrypted=rtrim($decrypted, "\0");
- $this->assertNotEqual($encrypted, $source);
- $this->assertEqual($decrypted, $source);
-
- $chunk=substr($source, 0, 8192);
- $encrypted=OC_Crypt::encrypt($chunk, $key);
- $this->assertEqual(strlen($chunk), strlen($encrypted));
- $decrypted=OC_Crypt::decrypt($encrypted, $key);
- $decrypted=rtrim($decrypted, "\0");
- $this->assertEqual($decrypted, $chunk);
-
- $encrypted=OC_Crypt::blockEncrypt($source, $key);
- $decrypted=OC_Crypt::blockDecrypt($encrypted, $key);
- $this->assertNotEqual($encrypted, $source);
- $this->assertEqual($decrypted, $source);
-
- $tmpFileEncrypted=OCP\Files::tmpFile();
- OC_Crypt::encryptfile($file, $tmpFileEncrypted, $key);
- $encrypted=file_get_contents($tmpFileEncrypted);
- $decrypted=OC_Crypt::blockDecrypt($encrypted, $key);
- $this->assertNotEqual($encrypted, $source);
- $this->assertEqual($decrypted, $source);
-
- $tmpFileDecrypted=OCP\Files::tmpFile();
- OC_Crypt::decryptfile($tmpFileEncrypted, $tmpFileDecrypted, $key);
- $decrypted=file_get_contents($tmpFileDecrypted);
- $this->assertEqual($decrypted, $source);
-
- $file=OC::$SERVERROOT.'/core/img/weather-clear.png';
- $source=file_get_contents($file); //binary file
- $encrypted=OC_Crypt::encrypt($source, $key);
- $decrypted=OC_Crypt::decrypt($encrypted, $key);
- $decrypted=rtrim($decrypted, "\0");
- $this->assertEqual($decrypted, $source);
-
- $encrypted=OC_Crypt::blockEncrypt($source, $key);
- $decrypted=OC_Crypt::blockDecrypt($encrypted, $key);
- $this->assertEqual($decrypted, $source);
-
- }
-
- function testBinary() {
- $key=uniqid();
-
- $file=__DIR__.'/binary';
- $source=file_get_contents($file); //binary file
- $encrypted=OC_Crypt::encrypt($source, $key);
- $decrypted=OC_Crypt::decrypt($encrypted, $key);
-
- $decrypted=rtrim($decrypted, "\0");
- $this->assertEqual($decrypted, $source);
-
- $encrypted=OC_Crypt::blockEncrypt($source, $key);
- $decrypted=OC_Crypt::blockDecrypt($encrypted, $key, strlen($source));
- $this->assertEqual($decrypted, $source);
- }
-}
diff --git a/apps/files_encryption/tests/proxy.php b/apps/files_encryption/tests/proxy.php
deleted file mode 100644
index 5aa617e7472..00000000000
--- a/apps/files_encryption/tests/proxy.php
+++ /dev/null
@@ -1,117 +0,0 @@
-<?php
-/**
- * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-class Test_CryptProxy extends UnitTestCase {
- 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['enckey'])?$_SESSION['enckey']:null;
-
-
- //set testing key
- $_SESSION['enckey']=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['enckey']=$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->assertNotEqual($original, $stored);
- $this->assertEqual(strlen($original), strlen($fromFile));
- $this->assertEqual($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->assertNotEqual($original, $stored);
- $fromFile=$rootView->file_get_contents($userDir.'/file');
- $this->assertEqual($original, $fromFile);
-
- $fromFile=$view->file_get_contents('files/file');
- $this->assertEqual($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->assertNotEqual($original, $stored);
- $this->assertEqual(strlen($original), strlen($fromFile));
- $this->assertEqual($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->assertNotEqual($original, $stored);
- $this->assertEqual(strlen($original), strlen($fromFile));
- }
-}
diff --git a/apps/files_encryption/tests/stream.php b/apps/files_encryption/tests/stream.php
deleted file mode 100644
index e4af17d47b5..00000000000
--- a/apps/files_encryption/tests/stream.php
+++ /dev/null
@@ -1,85 +0,0 @@
-<?php
-/**
- * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-class Test_CryptStream extends UnitTestCase {
- private $tmpFiles=array();
-
- function testStream() {
- $stream=$this->getStream('test1', 'w', strlen('foobar'));
- fwrite($stream, 'foobar');
- fclose($stream);
-
- $stream=$this->getStream('test1', 'r', strlen('foobar'));
- $data=fread($stream, 6);
- fclose($stream);
- $this->assertEqual('foobar', $data);
-
- $file=OC::$SERVERROOT.'/3rdparty/MDB2.php';
- $source=fopen($file, 'r');
- $target=$this->getStream('test2', 'w', 0);
- OCP\Files::streamCopy($source, $target);
- fclose($target);
- fclose($source);
-
- $stream=$this->getStream('test2', 'r', filesize($file));
- $data=stream_get_contents($stream);
- $original=file_get_contents($file);
- $this->assertEqual(strlen($original), strlen($data));
- $this->assertEqual($original, $data);
- }
-
- /**
- * get a cryptstream to a temporary file
- * @param string $id
- * @param string $mode
- * @param int size
- * @return resource
- */
- function getStream($id, $mode, $size) {
- if ($id==='') {
- $id=uniqid();
- }
- if ( ! isset($this->tmpFiles[$id])) {
- $file=OCP\Files::tmpFile();
- $this->tmpFiles[$id]=$file;
- } else {
- $file=$this->tmpFiles[$id];
- }
- $stream=fopen($file, $mode);
- OC_CryptStream::$sourceStreams[$id]=array('path'=>'dummy'.$id, 'stream'=>$stream, 'size'=>$size);
- return fopen('crypt://streams/'.$id, $mode);
- }
-
- function testBinary() {
- $file=__DIR__.'/binary';
- $source=file_get_contents($file);
-
- $stream=$this->getStream('test', 'w', strlen($source));
- fwrite($stream, $source);
- fclose($stream);
-
- $stream=$this->getStream('test', 'r', strlen($source));
- $data=stream_get_contents($stream);
- fclose($stream);
- $this->assertEqual(strlen($data), strlen($source));
- $this->assertEqual($source, $data);
-
- $file=__DIR__.'/zeros';
- $source=file_get_contents($file);
-
- $stream=$this->getStream('test2', 'w', strlen($source));
- fwrite($stream, $source);
- fclose($stream);
-
- $stream=$this->getStream('test2', 'r', strlen($source));
- $data=stream_get_contents($stream);
- fclose($stream);
- $this->assertEqual(strlen($data), strlen($source));
- $this->assertEqual($source, $data);
- }
-}
diff --git a/apps/files_encryption/tests/zeros b/apps/files_encryption/tests/zeros
deleted file mode 100644
index ff982acf423..00000000000
--- a/apps/files_encryption/tests/zeros
+++ /dev/null
Binary files differ