Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorin Peter <github@florin-peter.de>2013-04-30 03:35:46 +0400
committerFlorin Peter <github@florin-peter.de>2013-04-30 03:35:46 +0400
commit27ce7845b4205650e50f3777d8b152470440cbe6 (patch)
treefe207f00a7d47c960f35837de40aa8dacfa72115
parent882a747b47371ab9d71ba6c336a873873805c696 (diff)
fixed tests, now tests should work via autotest.sh
files_encryption app is now enabled in enable_all.php
-rw-r--r--apps/files_encryption/lib/util.php7
-rw-r--r--apps/files_encryption/tests/keymanager.php4
-rwxr-xr-xapps/files_encryption/tests/util.php61
-rw-r--r--tests/enable_all.php1
4 files changed, 50 insertions, 23 deletions
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index fe040d88775..4097250b252 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -204,7 +204,12 @@ class Util {
$this->view->file_put_contents( $this->privateKeyPath, $encryptedPrivateKey );
\OC_FileProxy::$enabled = true;
-
+
+ // create database configuration
+ $sql = 'INSERT INTO `*PREFIX*encryption` (`uid`,`mode`,`recovery`) VALUES (?,?,?)';
+ $args = array( $this->userId, 'server-side', 0);
+ $query = \OCP\DB::prepare( $sql );
+ $query->execute( $args );
}
return true;
diff --git a/apps/files_encryption/tests/keymanager.php b/apps/files_encryption/tests/keymanager.php
index 3dba6d0df97..7fe37838a42 100644
--- a/apps/files_encryption/tests/keymanager.php
+++ b/apps/files_encryption/tests/keymanager.php
@@ -50,8 +50,8 @@ class Test_Keymanager extends \PHPUnit_Framework_TestCase {
$userHome = \OC_User::getHome($this->userId);
$this->dataDir = str_replace('/'.$this->userId, '', $userHome);
- \OC_Filesystem::init( $this->userId, '/' );
- \OC_Filesystem::mount( 'OC_Filestorage_Local', array('datadir' => $this->dataDir), '/' );
+ \OC\Files\Filesystem::init( $this->userId, '/' );
+ \OC\Files\Filesystem::mount( 'OC_Filestorage_Local', array('datadir' => $this->dataDir), '/' );
}
diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php
index 3ebc484809b..0659b468a37 100755
--- a/apps/files_encryption/tests/util.php
+++ b/apps/files_encryption/tests/util.php
@@ -29,19 +29,20 @@ use OCA\Encryption;
class Test_Enc_Util extends \PHPUnit_Framework_TestCase {
function setUp() {
-
- \OC_Filesystem::mount( 'OC_Filestorage_Local', array(), '/' );
-
- // set content for encrypting / decrypting in tests
+ // reset backend
+ \OC_User::useBackend('database');
+
+ \OC_User::setUserId( 'admin' );
+ $this->userId = 'admin';
+ $this->pass = 'admin';
+
+ // set content for encrypting / decrypting in tests
$this->dataUrl = realpath( dirname(__FILE__).'/../lib/crypt.php' );
$this->dataShort = 'hats';
$this->dataLong = file_get_contents( realpath( dirname(__FILE__).'/../lib/crypt.php' ) );
$this->legacyData = realpath( dirname(__FILE__).'/legacy-text.txt' );
$this->legacyEncryptedData = realpath( dirname(__FILE__).'/legacy-encrypted-text.txt' );
-
- $this->userId = 'admin';
- $this->pass = 'admin';
-
+
$keypair = Encryption\Crypt::createKeypair();
$this->genPublicKey = $keypair['publicKey'];
@@ -54,9 +55,15 @@ class Test_Enc_Util extends \PHPUnit_Framework_TestCase {
$this->privateKeyPath = $this->encryptionDir . '/' . $this->userId . '.private.key'; // e.g. data/admin/admin.private.key
$this->view = new \OC_FilesystemView( '/' );
-
- $this->mockView = m::mock('OC_FilesystemView');
- $this->util = new Encryption\Util( $this->mockView, $this->userId );
+
+ $userHome = \OC_User::getHome($this->userId);
+ $this->dataDir = str_replace('/'.$this->userId, '', $userHome);
+
+ \OC\Files\Filesystem::init( $this->userId, '/' );
+ \OC\Files\Filesystem::mount( 'OC_Filestorage_Local', array('datadir' => $this->dataDir), '/' );
+
+ $mockView = m::mock('OC_FilesystemView');
+ $this->util = new Encryption\Util( $mockView, $this->userId );
}
@@ -90,8 +97,8 @@ class Test_Enc_Util extends \PHPUnit_Framework_TestCase {
$mockView = m::mock('OC_FilesystemView');
- $mockView->shouldReceive( 'file_exists' )->times(5)->andReturn( false );
- $mockView->shouldReceive( 'mkdir' )->times(4)->andReturn( true );
+ $mockView->shouldReceive( 'file_exists' )->times(7)->andReturn( false );
+ $mockView->shouldReceive( 'mkdir' )->times(6)->andReturn( true );
$mockView->shouldReceive( 'file_put_contents' )->withAnyArgs();
$util = new Encryption\Util( $mockView, $this->userId );
@@ -107,7 +114,7 @@ class Test_Enc_Util extends \PHPUnit_Framework_TestCase {
$mockView = m::mock('OC_FilesystemView');
- $mockView->shouldReceive( 'file_exists' )->times(6)->andReturn( true );
+ $mockView->shouldReceive( 'file_exists' )->times(8)->andReturn( true );
$mockView->shouldReceive( 'file_put_contents' )->withAnyArgs();
$util = new Encryption\Util( $mockView, $this->userId );
@@ -141,7 +148,7 @@ class Test_Enc_Util extends \PHPUnit_Framework_TestCase {
$mockView = m::mock('OC_FilesystemView');
- $mockView->shouldReceive( 'file_exists' )->times(3)->andReturn( true );
+ $mockView->shouldReceive( 'file_exists' )->times(5)->andReturn( true );
$util = new Encryption\Util( $mockView, $this->userId );
@@ -190,11 +197,25 @@ class Test_Enc_Util extends \PHPUnit_Framework_TestCase {
function testGetUidAndFilename() {
\OC_User::setUserId( 'admin' );
-
- $this->util->getUidAndFilename( 'test1.txt' );
-
-
-
+
+ $filename = 'tmp-'.time().'.test';
+
+ // Disable encryption proxy to prevent recursive calls
+ $proxyStatus = \OC_FileProxy::$enabled;
+ \OC_FileProxy::$enabled = false;
+
+ $this->view->file_put_contents($this->userId . '/files/' . $filename, $this->dataShort);
+
+ // Re-enable proxy - our work is done
+ \OC_FileProxy::$enabled = $proxyStatus;
+
+ $util = new Encryption\Util( $this->view, $this->userId );
+
+ list($fileOwnerUid, $file) = $util->getUidAndFilename( $filename );
+
+ $this->assertEquals('admin', $fileOwnerUid);
+
+ $this->assertEquals($file, $filename);
}
// /**
diff --git a/tests/enable_all.php b/tests/enable_all.php
index 44af0115650..111ed0e1357 100644
--- a/tests/enable_all.php
+++ b/tests/enable_all.php
@@ -8,6 +8,7 @@
require_once __DIR__.'/../lib/base.php';
+OC_App::enable('files_encryption');
OC_App::enable('calendar');
OC_App::enable('contacts');
OC_App::enable('apptemplateadvanced');