diff options
author | Michael Gapczynski <mtgap@owncloud.com> | 2012-08-19 22:29:01 -0400 |
---|---|---|
committer | Michael Gapczynski <mtgap@owncloud.com> | 2012-08-19 22:29:01 -0400 |
commit | 82d81e8d39ce69211ec6b29fe3f803c57714b8dd (patch) | |
tree | 09dbd675480a02fd626f6634e083f3d6a01b4404 /tests | |
parent | f893d21660695d1d1cd594c102e2bcba6919dee3 (diff) | |
parent | 5eca531f99f9615d1a09bbb0b03dda2063901aa7 (diff) | |
download | nextcloud-server-82d81e8d39ce69211ec6b29fe3f803c57714b8dd.tar.gz nextcloud-server-82d81e8d39ce69211ec6b29fe3f803c57714b8dd.zip |
Merge branch 'share_api'
Conflicts:
apps/contacts/lib/vcard.php
apps/files/index.php
lib/files.php
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/filestorage.php | 10 | ||||
-rw-r--r-- | tests/lib/share/backend.php | 67 | ||||
-rw-r--r-- | tests/lib/share/share.php | 380 |
3 files changed, 452 insertions, 5 deletions
diff --git a/tests/lib/filestorage.php b/tests/lib/filestorage.php index e554a75e441..0a8715600d5 100644 --- a/tests/lib/filestorage.php +++ b/tests/lib/filestorage.php @@ -31,13 +31,13 @@ abstract class Test_FileStorage extends UnitTestCase { */ public function testRoot(){ $this->assertTrue($this->instance->file_exists('/'),'Root folder does not exist'); - $this->assertTrue($this->instance->is_readable('/'),'Root folder is not readable'); + $this->assertTrue($this->instance->isReadable('/'),'Root folder is not readable'); $this->assertTrue($this->instance->is_dir('/'),'Root folder is not a directory'); $this->assertFalse($this->instance->is_file('/'),'Root folder is a file'); $this->assertEqual('dir',$this->instance->filetype('/')); //without this, any further testing would be useless, not an acutal requirement for filestorage though - $this->assertTrue($this->instance->is_writable('/'),'Root folder is not writable'); + $this->assertTrue($this->instance->isUpdatable('/'),'Root folder is not writable'); } public function testDirectories(){ @@ -50,8 +50,8 @@ abstract class Test_FileStorage extends UnitTestCase { $this->assertFalse($this->instance->is_file('/folder')); $this->assertEqual('dir',$this->instance->filetype('/folder')); $this->assertEqual(0,$this->instance->filesize('/folder')); - $this->assertTrue($this->instance->is_readable('/folder')); - $this->assertTrue($this->instance->is_writable('/folder')); + $this->assertTrue($this->instance->isReadable('/folder')); + $this->assertTrue($this->instance->isUpdatable('/folder')); $dh=$this->instance->opendir('/'); $content=array(); @@ -154,7 +154,7 @@ abstract class Test_FileStorage extends UnitTestCase { $textFile=OC::$SERVERROOT.'/tests/data/lorem.txt'; $ctimeStart=time(); $this->instance->file_put_contents('/lorem.txt',file_get_contents($textFile)); - $this->assertTrue($this->instance->is_readable('/lorem.txt')); + $this->assertTrue($this->instance->isReadable('/lorem.txt')); $ctimeEnd=time(); $cTime=$this->instance->filectime('/lorem.txt'); $mTime=$this->instance->filemtime('/lorem.txt'); diff --git a/tests/lib/share/backend.php b/tests/lib/share/backend.php new file mode 100644 index 00000000000..9fe625a1fa3 --- /dev/null +++ b/tests/lib/share/backend.php @@ -0,0 +1,67 @@ +<?php +/** +* ownCloud +* +* @author Michael Gapczynski +* @copyright 2012 Michael Gapczynski mtgap@owncloud.com +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +*/ + +class Test_Share_Backend implements OCP\Share_Backend { + + const FORMAT_SOURCE = 0; + const FORMAT_TARGET = 1; + const FORMAT_PERMISSIONS = 2; + + private $testItem = 'test.txt'; + + public function isValidSource($itemSource, $uidOwner) { + if ($itemSource == $this->testItem) { + return true; + } + } + + public function generateTarget($itemSource, $shareWith, $exclude = null) { + $target = $itemSource; + if (isset($exclude)) { + $pos = strrpos($target, '.'); + $name = substr($target, 0, $pos); + $ext = substr($target, $pos); + $append = ''; + $i = 1; + while (in_array($name.$append.$ext, $exclude)) { + $append = $i; + $i++; + } + $target = $name.$append.$ext; + } + return $target; + } + + public function formatItems($items, $format, $parameters = null) { + $testItems = array(); + foreach ($items as $item) { + if ($format == self::FORMAT_SOURCE) { + $testItems[] = $item['item_source']; + } else if ($format == self::FORMAT_TARGET) { + $testItems[] = $item['item_target']; + } else if ($format == self::FORMAT_PERMISSIONS) { + $testItems[] = $item['permissions']; + } + } + return $testItems; + } + +} diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php new file mode 100644 index 00000000000..89f0fbc976c --- /dev/null +++ b/tests/lib/share/share.php @@ -0,0 +1,380 @@ +<?php +/** +* ownCloud +* +* @author Michael Gapczynski +* @copyright 2012 Michael Gapczynski mtgap@owncloud.com +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +*/ + +class Test_Share extends UnitTestCase { + + protected $itemType; + protected $userBackend; + protected $user1; + protected $user2; + protected $groupBackend; + protected $group1; + protected $group2; + + + public function setUp() { + OC_User::clearBackends(); + OC_User::useBackend('dummy'); + $this->user1 = uniqid('user_'); + $this->user2 = uniqid('user_'); + $this->user3 = uniqid('user_'); + $this->user4 = uniqid('user_'); + OC_User::createUser($this->user1, 'pass'); + OC_User::createUser($this->user2, 'pass'); + OC_User::createUser($this->user3, 'pass'); + OC_User::createUser($this->user4, 'pass'); + OC_User::setUserId($this->user1); + OC_Group::clearBackends(); + OC_Group::useBackend(new OC_Group_Dummy); + $this->group1 = uniqid('group_'); + $this->group2 = uniqid('group_'); + OC_Group::createGroup($this->group1); + OC_Group::createGroup($this->group2); + OC_Group::addToGroup($this->user1, $this->group1); + OC_Group::addToGroup($this->user2, $this->group1); + OC_Group::addToGroup($this->user3, $this->group1); + OC_Group::addToGroup($this->user2, $this->group2); + OC_Group::addToGroup($this->user4, $this->group2); + OCP\Share::registerBackend('test', 'Test_Share_Backend'); + } + + public function tearDown() { + $query = OC_DB::prepare('DELETE FROM *PREFIX*share WHERE item_type = ?'); + $query->execute(array('test')); + } + + public function testShareInvalidShareType() { + $this->expectException(new Exception('Share type foobar is not valid for test.txt')); + OCP\Share::shareItem('test', 'test.txt', 'test.txt', 'foobar', $this->user2, OCP\Share::PERMISSION_READ); + } + + public function testInvalidItemType() { + $message = 'Sharing backend for foobar not found'; + try { + OCP\Share::shareItem('foobar', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + try { + OCP\Share::getItemsSharedWith('foobar'); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + try { + OCP\Share::getItemSharedWith('foobar', 'test.txt'); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + try { + OCP\Share::getItemSharedWithBySource('foobar', 'test.txt'); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + try { + OCP\Share::getItemShared('foobar', 'test.txt'); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + try { + OCP\Share::unshare('foobar', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + try { + OCP\Share::setPermissions('foobar', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_UPDATE); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + } + + public function testShareWithUser() { + // Invalid shares + $message = 'Sharing test.txt failed, because the user '.$this->user1.' is the item owner'; + try { + OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user1, OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + $message = 'Sharing test.txt failed, because the user foobar does not exist'; + try { + OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, 'foobar', OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + $message = 'Sharing foobar failed, because the sharing backend for test could not find its source'; + try { + OCP\Share::shareItem('test', 'foobar', 'foobar', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + + // Valid share + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); + $this->assertEqual(OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt')); + OC_User::setUserId($this->user2); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt')); + + // Attempt to share again + OC_User::setUserId($this->user1); + $message = 'Sharing test.txt failed, because this item is already shared with '.$this->user2; + try { + OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + + // Attempt to share back + OC_User::setUserId($this->user2); + $message = 'Sharing test.txt failed, because the user '.$this->user1.' is the original sharer'; + try { + OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user1, OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + + // Unshare + OC_User::setUserId($this->user1); + $this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2)); + + // Attempt reshare without share permission + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); + OC_User::setUserId($this->user2); + $message = 'Sharing test.txt failed, because resharing is not allowed'; + try { + OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + + // Owner grants share and update permission + OC_User::setUserId($this->user1); + $this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_SHARE)); + + // Attempt reshare with escalated permissions + OC_User::setUserId($this->user2); + $message = 'Sharing test.txt failed, because the permissions exceed permissions granted to '.$this->user2; + try { + OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_DELETE); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + + // Valid reshare + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE)); + $this->assertEqual(OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt')); + OC_User::setUserId($this->user3); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt')); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE)); + + // Attempt to escalate permissions + OC_User::setUserId($this->user2); + $message = 'Setting permissions for test.txt failed, because the permissions exceed permissions granted to '.$this->user2; + try { + OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_DELETE); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + + // Remove update permission + OC_User::setUserId($this->user1); + $this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE)); + OC_User::setUserId($this->user2); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE)); + OC_User::setUserId($this->user3); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ)); + + // Remove share permission + OC_User::setUserId($this->user1); + $this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); + OC_User::setUserId($this->user2); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ)); + OC_User::setUserId($this->user3); + $this->assertFalse(OCP\Share::getItemSharedWith('test', 'test.txt')); + + // Reshare again, and then have owner unshare + OC_User::setUserId($this->user1); + $this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE)); + OC_User::setUserId($this->user2); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ)); + OC_User::setUserId($this->user1); + $this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2)); + OC_User::setUserId($this->user2); + $this->assertFalse(OCP\Share::getItemSharedWith('test', 'test.txt')); + OC_User::setUserId($this->user3); + $this->assertFalse(OCP\Share::getItemSharedWith('test', 'test.txt')); + + // Attempt target conflict + OC_User::setUserId($this->user1); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); + OC_User::setUserId($this->user3); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); + OC_User::setUserId($this->user2); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt', 'test1.txt')); + + // Remove user + OC_User::deleteUser($this->user1); + OC_User::setUserId($this->user2); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test1.txt')); + } + + public function testShareWithGroup() { + // Invalid shares + $message = 'Sharing test.txt failed, because the group foobar does not exist'; + try { + OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, 'foobar', OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + $message = 'Sharing test.txt failed, because '.$this->user1.' is not a member of the group '.$this->group2; + try { + OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group2, OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + + // Valid share + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ)); + $this->assertEqual(OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt')); + OC_User::setUserId($this->user2); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt')); + OC_User::setUserId($this->user3); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt')); + + // Attempt to share again + OC_User::setUserId($this->user1); + $message = 'Sharing test.txt failed, because this item is already shared with '.$this->group1; + try { + OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + + // Attempt to share back to owner of group share + OC_User::setUserId($this->user2); + $message = 'Sharing test.txt failed, because the user '.$this->user1.' is the original sharer'; + try { + OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user1, OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + + // Attempt to share back to group + $message = 'Sharing test.txt failed, because the item was orignally shared with the group '.$this->group1; + try { + OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + + // Attempt to share back to member of group + $message = 'Sharing test.txt failed, because the user '.$this->user3.' is a member of the original group share'; + try { + OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + + // Unshare + OC_User::setUserId($this->user1); + $this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1)); + + // Valid share with same person - user then group + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_DELETE | OCP\Share::PERMISSION_SHARE)); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE)); + OC_User::setUserId($this->user2); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt')); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_DELETE | OCP\Share::PERMISSION_SHARE)); + OC_User::setUserId($this->user3); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt')); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE)); + + // Valid reshare + OC_User::setUserId($this->user2); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user4, OCP\Share::PERMISSION_READ)); + OC_User::setUserId($this->user4); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt')); + + // Unshare from user only + OC_User::setUserId($this->user1); + $this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2)); + OC_User::setUserId($this->user2); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE)); + OC_User::setUserId($this->user4); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array()); + + // Valid share with same person - group then user + OC_User::setUserId($this->user1); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_DELETE)); + OC_User::setUserId($this->user2); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt')); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_DELETE)); + + // Unshare from group only + OC_User::setUserId($this->user1); + $this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1)); + OC_User::setUserId($this->user2); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_DELETE)); + + // Attempt user specific target conflict + OC_User::setUserId($this->user3); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE)); + OC_User::setUserId($this->user2); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt', 'test1.txt')); + + // Valid reshare TODO Broken + $this->assertTrue(OCP\Share::shareItem('test', 'test1.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user4, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE)); + OC_User::setUserId($this->user4); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test1.txt')); + + // Remove user from group + OC_Group::removeFromGroup($this->user2, $this->group1); + OC_User::setUserId($this->user2); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt')); + OC_User::setUserId($this->user4); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array()); + + // Add user to group + + // Remove group + } + +} |