diff options
author | Florin Peter <github@florin-peter.de> | 2013-05-20 21:46:28 +0200 |
---|---|---|
committer | Florin Peter <github@florin-peter.de> | 2013-05-20 21:46:28 +0200 |
commit | 1c8e5d6873b1190d73b4139ca9fd7e710ae5d1a3 (patch) | |
tree | 534ec37bf115ad2845031915c8a6d68b7dd23594 | |
parent | 1fa2f19ee44cc4a25bda784aee46ab2dac28e658 (diff) | |
download | nextcloud-server-1c8e5d6873b1190d73b4139ca9fd7e710ae5d1a3.tar.gz nextcloud-server-1c8e5d6873b1190d73b4139ca9fd7e710ae5d1a3.zip |
added test for failed sharing
-rw-r--r-- | apps/files_encryption/hooks/hooks.php | 4 | ||||
-rwxr-xr-x | apps/files_encryption/tests/crypt.php | 2 | ||||
-rw-r--r-- | apps/files_encryption/tests/encryption.key | 1 | ||||
-rwxr-xr-x | apps/files_encryption/tests/share.php | 64 |
4 files changed, 70 insertions, 1 deletions
diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 90a93b4c52d..e3196480457 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -208,6 +208,9 @@ class Hooks { /*
* @brief check if files can be encrypted to every user.
*/
+ /**
+ * @param $params
+ */
public static function preShared($params) {
$users = array();
@@ -229,7 +232,6 @@ class Hooks { $params['run']->run = false;
// TODO: Make sure files_sharing provides user
// feedback on failed share
- break;
}
}
}
diff --git a/apps/files_encryption/tests/crypt.php b/apps/files_encryption/tests/crypt.php index 5b5a2189a48..6a1f1aef659 100755 --- a/apps/files_encryption/tests/crypt.php +++ b/apps/files_encryption/tests/crypt.php @@ -51,6 +51,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase $this->dataUrl = realpath(dirname(__FILE__) . '/../lib/crypt.php'); $this->legacyData = realpath(dirname(__FILE__) . '/legacy-text.txt'); $this->legacyEncryptedData = realpath(dirname(__FILE__) . '/legacy-encrypted-text.txt'); + $this->legacyEncryptedDataKey = realpath(dirname(__FILE__) . '/encryption.key'); $this->randomKey = Encryption\Crypt::generateKey(); $keypair = Encryption\Crypt::createKeypair(); @@ -884,6 +885,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase // tear down $view->unlink($filename); } + // function testEncryption(){ // // $key=uniqid(); diff --git a/apps/files_encryption/tests/encryption.key b/apps/files_encryption/tests/encryption.key new file mode 100644 index 00000000000..4495cee78e2 --- /dev/null +++ b/apps/files_encryption/tests/encryption.key @@ -0,0 +1 @@ +E_cP6HVs
\ No newline at end of file diff --git a/apps/files_encryption/tests/share.php b/apps/files_encryption/tests/share.php index a9ee8d00235..f302aa0a3ef 100755 --- a/apps/files_encryption/tests/share.php +++ b/apps/files_encryption/tests/share.php @@ -691,6 +691,70 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase $this->assertTrue($util->setRecoveryForUser(0)); } + function testFailShareFile() + { + // login as admin + $this->loginHelper('admin'); + + // save file with content + $cryptedFile = file_put_contents('crypt://' . $this->filename, $this->dataShort); + + // test that data was successfully written + $this->assertTrue(is_int($cryptedFile)); + + // disable encryption proxy to prevent recursive calls + $proxyStatus = \OC_FileProxy::$enabled; + \OC_FileProxy::$enabled = false; + + // get the file info from previous created file + $fileInfo = $this->view->getFileInfo('/admin/files/' . $this->filename); + + // check if we have a valid file info + $this->assertTrue(is_array($fileInfo)); + + // check if the unencrypted file size is stored + $this->assertGreaterThan(0, $fileInfo['unencrypted_size']); + + // break users public key + $this->view->rename('/public-keys/user2.public.key', '/public-keys/user2.public.key_backup'); + + // re-enable the file proxy + \OC_FileProxy::$enabled = $proxyStatus; + + // share the file + \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, 'group1', OCP\PERMISSION_ALL); + + // login as admin + $this->loginHelper('admin'); + + // check if share key for user1 not exists + $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.user2.shareKey')); + + // disable encryption proxy to prevent recursive calls + $proxyStatus = \OC_FileProxy::$enabled; + \OC_FileProxy::$enabled = false; + + // break user1 public key + $this->view->rename('/public-keys/user2.public.key_backup', '/public-keys/user2.public.key'); + + // remove share file + $this->view->unlink('/admin/files_encryption/share-keys/' . $this->filename . '.user2.shareKey'); + + // re-enable the file proxy + \OC_FileProxy::$enabled = $proxyStatus; + + // unshare the file with user1 + \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, 'group1'); + + // check if share key not exists + $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.user2.shareKey')); + + // cleanup + $this->view->unlink('/admin/files/' . $this->filename); + } + + + /** * @param $user * @param bool $create |