summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption
diff options
context:
space:
mode:
authorFlorin Peter <github@florin-peter.de>2013-05-16 00:30:01 +0200
committerFlorin Peter <github@florin-peter.de>2013-05-16 00:30:01 +0200
commit8f963b95e53e54220bcce1931599496d9aa797b1 (patch)
tree9b5c6d21d80d412f7bd372b31ad76c10966872d0 /apps/files_encryption
parentb75a0abb6bee24b3f6e8276d129af3271a05e5d1 (diff)
downloadnextcloud-server-8f963b95e53e54220bcce1931599496d9aa797b1.tar.gz
nextcloud-server-8f963b95e53e54220bcce1931599496d9aa797b1.zip
added test for share with group
Diffstat (limited to 'apps/files_encryption')
-rwxr-xr-xapps/files_encryption/tests/share.php74
1 files changed, 74 insertions, 0 deletions
diff --git a/apps/files_encryption/tests/share.php b/apps/files_encryption/tests/share.php
index 6962cadc443..e5427fdf504 100755
--- a/apps/files_encryption/tests/share.php
+++ b/apps/files_encryption/tests/share.php
@@ -79,6 +79,11 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
$this->loginHelper('user1', true);
$this->loginHelper('user2', true);
$this->loginHelper('user3', true);
+
+ // create group and assign users
+ \OC_Group::createGroup('group1');
+ \OC_Group::addToGroup('user2', 'group1');
+ \OC_Group::addToGroup('user3', 'group1');
}
function tearDown()
@@ -90,10 +95,15 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
OC_App::disable('files_trashbin');
}
+ // clean group
+ \OC_Group::deleteGroup('group1');
+
// cleanup users
\OC_User::deleteUser('user1');
\OC_User::deleteUser('user2');
\OC_User::deleteUser('user3');
+
+ \OC_FileProxy::clearProxies();
}
function testShareFile($withTeardown = true)
@@ -454,6 +464,70 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
$this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.admin.shareKey'));
}
+ function testShareFileWithGroup()
+ {
+ // 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']);
+
+ // 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 user2 and user3 exists
+ $this->assertTrue($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.user2.shareKey'));
+ $this->assertTrue($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.user3.shareKey'));
+
+ // login as user1
+ $this->loginHelper('user2');
+
+ // get file contents
+ $retrievedCryptedFile = $this->view->file_get_contents('/user2/files/Shared/' . $this->filename);
+
+ // check if data is the same as we previously written
+ $this->assertEquals($this->dataShort, $retrievedCryptedFile);
+
+ // login as admin
+ $this->loginHelper('admin');
+
+ // unshare the file
+ \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'));
+ $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.user3.shareKey'));
+
+ // cleanup
+ $this->view->unlink('/admin/files/' . $this->filename);
+
+ // check if share key not exists
+ $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.admin.shareKey'));
+
+ }
+
function loginHelper($user, $create = false)
{
if ($create) {