diff options
author | Florin Peter <github@florin-peter.de> | 2013-05-15 02:38:08 +0200 |
---|---|---|
committer | Florin Peter <github@florin-peter.de> | 2013-05-15 02:38:08 +0200 |
commit | 7461e9c2b5bdabd0b712f91a22445a0d933cf88f (patch) | |
tree | b7401fd89860c5c8df1b68574987dbdf402d674f | |
parent | 499fe6ca8e28d559ad8aba7724766c111c65290a (diff) | |
download | nextcloud-server-7461e9c2b5bdabd0b712f91a22445a0d933cf88f.tar.gz nextcloud-server-7461e9c2b5bdabd0b712f91a22445a0d933cf88f.zip |
improved tests and added new tests for file rename and move
-rwxr-xr-x | apps/files_encryption/tests/crypt.php | 105 | ||||
-rw-r--r-- | apps/files_encryption/tests/keymanager.php | 25 | ||||
-rwxr-xr-x | apps/files_encryption/tests/share.php | 1 | ||||
-rwxr-xr-x | apps/files_encryption/tests/util.php | 18 |
4 files changed, 117 insertions, 32 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(); diff --git a/apps/files_encryption/tests/keymanager.php b/apps/files_encryption/tests/keymanager.php index 3acc781a096..d24dcaa0360 100644 --- a/apps/files_encryption/tests/keymanager.php +++ b/apps/files_encryption/tests/keymanager.php @@ -26,6 +26,7 @@ class Test_Keymanager extends \PHPUnit_Framework_TestCase { function setUp() { // reset backend + \OC_User::clearBackends(); \OC_User::useBackend('database'); \OC_FileProxy::$enabled = false; @@ -41,18 +42,26 @@ class Test_Keymanager extends \PHPUnit_Framework_TestCase { $keypair = Encryption\Crypt::createKeypair(); $this->genPublicKey = $keypair['publicKey']; $this->genPrivateKey = $keypair['privateKey']; - - $this->view = new \OC_FilesystemView( '/' ); - - \OC_User::setUserId( 'admin' ); - $this->userId = 'admin'; - $this->pass = 'admin'; + + $this->view = new \OC_FilesystemView( '/' ); + + \OC_User::setUserId( 'admin' ); + $this->userId = 'admin'; + $this->pass = 'admin'; $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; diff --git a/apps/files_encryption/tests/share.php b/apps/files_encryption/tests/share.php index b8433821d3b..e2e26aa75b5 100755 --- a/apps/files_encryption/tests/share.php +++ b/apps/files_encryption/tests/share.php @@ -462,6 +462,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase \OC_Util::tearDownFS(); \OC_User::setUserId(''); + \OC\Files\Filesystem::setView(false); \OC_Util::setupFS($user); \OC_User::setUserId($user); diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php index efd3f03bc62..2abf4096902 100755 --- a/apps/files_encryption/tests/util.php +++ b/apps/files_encryption/tests/util.php @@ -51,14 +51,22 @@ class Test_Enc_Util extends \PHPUnit_Framework_TestCase { $this->keyfilesPath = $this->encryptionDir . '/' . 'keyfiles'; $this->publicKeyPath = $this->publicKeyDir . '/' . $this->userId . '.public.key'; // e.g. data/public-keys/admin.public.key $this->privateKeyPath = $this->encryptionDir . '/' . $this->userId . '.private.key'; // e.g. data/admin/admin.private.key - - $this->view = new \OC_FilesystemView( '/' ); + + $this->view = new \OC_FilesystemView( '/' ); $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; @@ -170,7 +178,7 @@ class Test_Enc_Util extends \PHPUnit_Framework_TestCase { $util = new Encryption\Util( $this->view, $this->userId ); - $files = $util->findEncFiles( '/', 'encrypted' ); + $files = $util->findEncFiles( '/'.$this->userId.'/'); //var_dump( $files ); |