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-05-15 04:38:08 +0400
committerFlorin Peter <github@florin-peter.de>2013-05-15 04:38:08 +0400
commit7461e9c2b5bdabd0b712f91a22445a0d933cf88f (patch)
treeb7401fd89860c5c8df1b68574987dbdf402d674f /apps/files_encryption/tests/crypt.php
parent499fe6ca8e28d559ad8aba7724766c111c65290a (diff)
improved tests and added new tests for file rename and move
Diffstat (limited to 'apps/files_encryption/tests/crypt.php')
-rwxr-xr-xapps/files_encryption/tests/crypt.php105
1 files changed, 86 insertions, 19 deletions
diff --git a/apps/files_encryption/tests/crypt.php b/apps/files_encryption/tests/crypt.php
index b2dea2f6538..de7ae38b173 100755
--- a/apps/files_encryption/tests/crypt.php
+++ b/apps/files_encryption/tests/crypt.php
@@ -35,6 +35,7 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase {
function setUp() {
// reset backend
+ \OC_User::clearBackends();
\OC_User::useBackend('database');
// set content for encrypting / decrypting in tests
@@ -58,17 +59,26 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase {
$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), '/' );
+ // Filesystem related hooks
+ \OCA\Encryption\Helper::registerFilesystemHooks();
+
+ \OC_FileProxy::register(new OCA\Encryption\Proxy());
+
+ \OC_Util::tearDownFS();
+ \OC_User::setUserId('');
+ \OC\Files\Filesystem::setView(false);
+ \OC_Util::setupFS($this->userId);
+ \OC_User::setUserId($this->userId);
$params['uid'] = $this->userId;
$params['password'] = $this->pass;
OCA\Encryption\Hooks::login($params);
+
}
function tearDown() {
- }
+ }
function testGenerateKey() {
@@ -272,7 +282,7 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase {
$this->assertEquals( $this->dataShort, $manualDecrypt );
// Teardown
- $this->view->unlink( $filename );
+ $this->view->unlink( $this->userId . '/files/' . $filename );
Encryption\Keymanager::deleteFileKey( $this->view, $this->userId, $filename );
}
@@ -350,7 +360,7 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase {
// Teardown
- $this->view->unlink( $filename );
+ $this->view->unlink( $this->userId . '/files/' . $filename );
Encryption\Keymanager::deleteFileKey( $this->view, $this->userId, $filename );
@@ -368,15 +378,14 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase {
// Test that data was successfully written
$this->assertTrue( is_int( $cryptedFile ) );
-
-
- // Get file contents without using any wrapper to get it's actual contents on disk
- $retreivedCryptedFile = $this->view->file_get_contents( $this->userId . '/files/' . $filename );
-
- $decrypt = file_get_contents( 'crypt://' . $filename );
+
+ // Get file decrypted contents
+ $decrypt = file_get_contents( 'crypt://' . $filename );
$this->assertEquals( $this->dataShort, $decrypt );
-
+
+ // tear down
+ $this->view->unlink( $this->userId . '/files/' . $filename );
}
function testSymmetricStreamDecryptLongFileContent() {
@@ -388,15 +397,14 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase {
// Test that data was successfully written
$this->assertTrue( is_int( $cryptedFile ) );
-
-
- // Get file contents without using any wrapper to get it's actual contents on disk
- $retreivedCryptedFile = $this->view->file_get_contents( $this->userId . '/files/' . $filename );
-
+
+ // Get file decrypted contents
$decrypt = file_get_contents( 'crypt://' . $filename );
-
+
$this->assertEquals( $this->dataLong, $decrypt );
-
+
+ // tear down
+ $this->view->unlink( $this->userId . '/files/' . $filename );
}
// Is this test still necessary?
@@ -623,6 +631,65 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase {
}
+ function testRenameFile() {
+
+ $filename = 'tmp-'.time();
+
+ // Save long data as encrypted file using stream wrapper
+ $cryptedFile = file_put_contents( 'crypt://' . $filename, $this->dataLong );
+
+ // Test that data was successfully written
+ $this->assertTrue( is_int( $cryptedFile ) );
+
+ // Get file decrypted contents
+ $decrypt = file_get_contents( 'crypt://' . $filename );
+
+ $this->assertEquals( $this->dataLong, $decrypt );
+
+ $newFilename = 'tmp-new-'.time();
+ $view = new \OC\Files\View('/' . $this->userId . '/files');
+ $view->rename( $filename, $newFilename );
+
+ // Get file decrypted contents
+ $newDecrypt = file_get_contents( 'crypt://' . $newFilename );
+
+ $this->assertEquals( $this->dataLong, $newDecrypt );
+
+ // tear down
+ $view->unlink( $newFilename );
+ }
+
+ function testMoveFileIntoFolder() {
+
+ $filename = 'tmp-'.time();
+
+ // Save long data as encrypted file using stream wrapper
+ $cryptedFile = file_put_contents( 'crypt://' . $filename, $this->dataLong );
+
+ // Test that data was successfully written
+ $this->assertTrue( is_int( $cryptedFile ) );
+
+ // Get file decrypted contents
+ $decrypt = file_get_contents( 'crypt://' . $filename );
+
+ $this->assertEquals( $this->dataLong, $decrypt );
+
+ $newFolder = '/newfolder1';
+ $newFilename = 'tmp-new-'.time();
+ $view = new \OC\Files\View('/' . $this->userId . '/files');
+ $view->mkdir($newFolder);
+ $view->rename( $filename, $newFolder . '/' . $newFilename );
+
+ // Get file decrypted contents
+ $newDecrypt = file_get_contents( 'crypt://' . $newFolder . '/' . $newFilename );
+
+ $this->assertEquals( $this->dataLong, $newDecrypt );
+
+ // tear down
+ $view->unlink( $newFolder . '/' . $newFilename );
+ $view->unlink( $newFolder );
+ }
+
// function testEncryption(){
//
// $key=uniqid();