]> source.dussan.org Git - nextcloud-server.git/commitdiff
fixed tests, now tests should work via autotest.sh
authorFlorin Peter <github@florin-peter.de>
Mon, 29 Apr 2013 23:35:46 +0000 (01:35 +0200)
committerFlorin Peter <github@florin-peter.de>
Mon, 29 Apr 2013 23:35:46 +0000 (01:35 +0200)
files_encryption app is now enabled in enable_all.php

apps/files_encryption/lib/util.php
apps/files_encryption/tests/keymanager.php
apps/files_encryption/tests/util.php
tests/enable_all.php

index fe040d88775b7f3325f2efb6095e8a4617a583fd..4097250b252c18a4d92a71dd7650a160f012467b 100644 (file)
@@ -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;
index 3dba6d0df974dff03aedc635b609748ce1280e26..7fe37838a42ea483de8f36e29bda86dcfc2a785c 100644 (file)
@@ -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), '/' );
        
        }
        
index 3ebc484809b430176a4da5f3d052ee8ad132375e..0659b468a37d8c32ce7e8bd544ce71318424990a 100755 (executable)
@@ -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);
        }
 
 //     /**
index 44af0115650dff1e6f52f756c96ae49b3bfc6067..111ed0e13572770ecbd170cf67bb498c973d4b33 100644 (file)
@@ -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');