share.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Michael Gapczynski
  6. * @copyright 2012 Michael Gapczynski mtgap@owncloud.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. class Test_Share extends UnitTestCase {
  22. protected $itemType;
  23. protected $userBackend;
  24. protected $user1;
  25. protected $user2;
  26. protected $groupBackend;
  27. protected $group1;
  28. protected $group2;
  29. public function setUp() {
  30. OC_User::clearBackends();
  31. OC_User::useBackend('dummy');
  32. $this->user1 = uniqid('user1_');
  33. $this->user2 = uniqid('user2_');
  34. $this->user3 = uniqid('user3_');
  35. $this->user4 = uniqid('user4_');
  36. OC_User::createUser($this->user1, 'pass');
  37. OC_User::createUser($this->user2, 'pass');
  38. OC_User::createUser($this->user3, 'pass');
  39. OC_User::createUser($this->user4, 'pass');
  40. OC_User::setUserId($this->user1);
  41. OC_Group::clearBackends();
  42. OC_Group::useBackend(new OC_Group_Dummy);
  43. $this->group1 = uniqid('group_');
  44. $this->group2 = uniqid('group_');
  45. OC_Group::createGroup($this->group1);
  46. OC_Group::createGroup($this->group2);
  47. OC_Group::addToGroup($this->user1, $this->group1);
  48. OC_Group::addToGroup($this->user2, $this->group1);
  49. OC_Group::addToGroup($this->user3, $this->group1);
  50. OC_Group::addToGroup($this->user2, $this->group2);
  51. OC_Group::addToGroup($this->user4, $this->group2);
  52. OCP\Share::registerBackend('test', 'Test_Share_Backend');
  53. }
  54. public function tearDown() {
  55. $query = OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `item_type` = ?');
  56. $query->execute(array('test'));
  57. }
  58. public function testShareInvalidShareType() {
  59. $message = 'Share type foobar is not valid for test.txt';
  60. try {
  61. OCP\Share::shareItem('test', 'test.txt', 'foobar', $this->user2, OCP\PERMISSION_READ);
  62. } catch (Exception $exception) {
  63. $this->assertEquals($message, $exception->getMessage());
  64. }
  65. }
  66. public function testInvalidItemType() {
  67. $message = 'Sharing backend for foobar not found';
  68. try {
  69. OCP\Share::shareItem('foobar', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ);
  70. $this->fail('Exception was expected: '.$message);
  71. } catch (Exception $exception) {
  72. $this->assertEquals($message, $exception->getMessage());
  73. }
  74. try {
  75. OCP\Share::getItemsSharedWith('foobar');
  76. $this->fail('Exception was expected: '.$message);
  77. } catch (Exception $exception) {
  78. $this->assertEquals($message, $exception->getMessage());
  79. }
  80. try {
  81. OCP\Share::getItemSharedWith('foobar', 'test.txt');
  82. $this->fail('Exception was expected: '.$message);
  83. } catch (Exception $exception) {
  84. $this->assertEquals($message, $exception->getMessage());
  85. }
  86. try {
  87. OCP\Share::getItemSharedWithBySource('foobar', 'test.txt');
  88. $this->fail('Exception was expected: '.$message);
  89. } catch (Exception $exception) {
  90. $this->assertEquals($message, $exception->getMessage());
  91. }
  92. try {
  93. OCP\Share::getItemShared('foobar', 'test.txt');
  94. $this->fail('Exception was expected: '.$message);
  95. } catch (Exception $exception) {
  96. $this->assertEquals($message, $exception->getMessage());
  97. }
  98. try {
  99. OCP\Share::unshare('foobar', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2);
  100. $this->fail('Exception was expected: '.$message);
  101. } catch (Exception $exception) {
  102. $this->assertEquals($message, $exception->getMessage());
  103. }
  104. try {
  105. OCP\Share::setPermissions('foobar', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_UPDATE);
  106. $this->fail('Exception was expected: '.$message);
  107. } catch (Exception $exception) {
  108. $this->assertEquals($message, $exception->getMessage());
  109. }
  110. }
  111. public function testShareWithUser() {
  112. // Invalid shares
  113. $message = 'Sharing test.txt failed, because the user '.$this->user1.' is the item owner';
  114. try {
  115. OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user1, OCP\PERMISSION_READ);
  116. $this->fail('Exception was expected: '.$message);
  117. } catch (Exception $exception) {
  118. $this->assertEquals($message, $exception->getMessage());
  119. }
  120. $message = 'Sharing test.txt failed, because the user foobar does not exist';
  121. try {
  122. OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, 'foobar', OCP\PERMISSION_READ);
  123. $this->fail('Exception was expected: '.$message);
  124. } catch (Exception $exception) {
  125. $this->assertEquals($message, $exception->getMessage());
  126. }
  127. $message = 'Sharing foobar failed, because the sharing backend for test could not find its source';
  128. try {
  129. OCP\Share::shareItem('test', 'foobar', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ);
  130. $this->fail('Exception was expected: '.$message);
  131. } catch (Exception $exception) {
  132. $this->assertEquals($message, $exception->getMessage());
  133. }
  134. // Valid share
  135. $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ));
  136. $this->assertEquals(array('test.txt'), OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE));
  137. OC_User::setUserId($this->user2);
  138. $this->assertEquals(array('test.txt'), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE));
  139. // Attempt to share again
  140. OC_User::setUserId($this->user1);
  141. $message = 'Sharing test.txt failed, because this item is already shared with '.$this->user2;
  142. try {
  143. OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ);
  144. $this->fail('Exception was expected: '.$message);
  145. } catch (Exception $exception) {
  146. $this->assertEquals($message, $exception->getMessage());
  147. }
  148. // Attempt to share back
  149. OC_User::setUserId($this->user2);
  150. $message = 'Sharing test.txt failed, because the user '.$this->user1.' is the original sharer';
  151. try {
  152. OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user1, OCP\PERMISSION_READ);
  153. $this->fail('Exception was expected: '.$message);
  154. } catch (Exception $exception) {
  155. $this->assertEquals($message, $exception->getMessage());
  156. }
  157. // Unshare
  158. OC_User::setUserId($this->user1);
  159. $this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2));
  160. // Attempt reshare without share permission
  161. $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ));
  162. OC_User::setUserId($this->user2);
  163. $message = 'Sharing test.txt failed, because resharing is not allowed';
  164. try {
  165. OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\PERMISSION_READ);
  166. $this->fail('Exception was expected: '.$message);
  167. } catch (Exception $exception) {
  168. $this->assertEquals($message, $exception->getMessage());
  169. }
  170. // Owner grants share and update permission
  171. OC_User::setUserId($this->user1);
  172. $this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE | OCP\PERMISSION_SHARE));
  173. // Attempt reshare with escalated permissions
  174. OC_User::setUserId($this->user2);
  175. $message = 'Sharing test.txt failed, because the permissions exceed permissions granted to '.$this->user2;
  176. try {
  177. OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\PERMISSION_READ | OCP\PERMISSION_DELETE);
  178. $this->fail('Exception was expected: '.$message);
  179. } catch (Exception $exception) {
  180. $this->assertEquals($message, $exception->getMessage());
  181. }
  182. // Valid reshare
  183. $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE));
  184. $this->assertEquals(array('test.txt'), OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE));
  185. OC_User::setUserId($this->user3);
  186. $this->assertEquals(array('test.txt'), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE));
  187. $this->assertEquals(array(OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS));
  188. // Attempt to escalate permissions
  189. OC_User::setUserId($this->user2);
  190. $message = 'Setting permissions for test.txt failed, because the permissions exceed permissions granted to '.$this->user2;
  191. try {
  192. OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\PERMISSION_READ | OCP\PERMISSION_DELETE);
  193. $this->fail('Exception was expected: '.$message);
  194. } catch (Exception $exception) {
  195. $this->assertEquals($message, $exception->getMessage());
  196. }
  197. // Remove update permission
  198. OC_User::setUserId($this->user1);
  199. $this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ | OCP\PERMISSION_SHARE));
  200. OC_User::setUserId($this->user2);
  201. $this->assertEquals(array(OCP\PERMISSION_READ | OCP\PERMISSION_SHARE), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS));
  202. OC_User::setUserId($this->user3);
  203. $this->assertEquals(array(OCP\PERMISSION_READ), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS));
  204. // Remove share permission
  205. OC_User::setUserId($this->user1);
  206. $this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ));
  207. OC_User::setUserId($this->user2);
  208. $this->assertEquals(array(OCP\PERMISSION_READ), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS));
  209. OC_User::setUserId($this->user3);
  210. $this->assertFalse(OCP\Share::getItemSharedWith('test', 'test.txt'));
  211. // Reshare again, and then have owner unshare
  212. OC_User::setUserId($this->user1);
  213. $this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ | OCP\PERMISSION_SHARE));
  214. OC_User::setUserId($this->user2);
  215. $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\PERMISSION_READ));
  216. OC_User::setUserId($this->user1);
  217. $this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2));
  218. OC_User::setUserId($this->user2);
  219. $this->assertFalse(OCP\Share::getItemSharedWith('test', 'test.txt'));
  220. OC_User::setUserId($this->user3);
  221. $this->assertFalse(OCP\Share::getItemSharedWith('test', 'test.txt'));
  222. // Attempt target conflict
  223. OC_User::setUserId($this->user1);
  224. $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ));
  225. OC_User::setUserId($this->user3);
  226. $this->assertTrue(OCP\Share::shareItem('test', 'share.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ));
  227. OC_User::setUserId($this->user2);
  228. $to_test = OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET);
  229. $this->assertEquals(2, count($to_test));
  230. $this->assertTrue(in_array('test.txt', $to_test));
  231. $this->assertTrue(in_array('test1.txt', $to_test));
  232. // Remove user
  233. OC_User::setUserId($this->user1);
  234. OC_User::deleteUser($this->user1);
  235. OC_User::setUserId($this->user2);
  236. $this->assertEquals(array('test1.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
  237. }
  238. public function testShareWithGroup() {
  239. // Invalid shares
  240. $message = 'Sharing test.txt failed, because the group foobar does not exist';
  241. try {
  242. OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, 'foobar', OCP\PERMISSION_READ);
  243. $this->fail('Exception was expected: '.$message);
  244. } catch (Exception $exception) {
  245. $this->assertEquals($message, $exception->getMessage());
  246. }
  247. $policy = OC_Appconfig::getValue('core', 'shareapi_share_policy', 'global');
  248. OC_Appconfig::setValue('core', 'shareapi_share_policy', 'groups_only');
  249. $message = 'Sharing test.txt failed, because '.$this->user1.' is not a member of the group '.$this->group2;
  250. try {
  251. OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group2, OCP\PERMISSION_READ);
  252. $this->fail('Exception was expected: '.$message);
  253. } catch (Exception $exception) {
  254. $this->assertEquals($message, $exception->getMessage());
  255. }
  256. OC_Appconfig::setValue('core', 'shareapi_share_policy', $policy);
  257. // Valid share
  258. $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\PERMISSION_READ));
  259. $this->assertEquals(array('test.txt'), OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE));
  260. OC_User::setUserId($this->user2);
  261. $this->assertEquals(array('test.txt'), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE));
  262. OC_User::setUserId($this->user3);
  263. $this->assertEquals(array('test.txt'), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE));
  264. // Attempt to share again
  265. OC_User::setUserId($this->user1);
  266. $message = 'Sharing test.txt failed, because this item is already shared with '.$this->group1;
  267. try {
  268. OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\PERMISSION_READ);
  269. $this->fail('Exception was expected: '.$message);
  270. } catch (Exception $exception) {
  271. $this->assertEquals($message, $exception->getMessage());
  272. }
  273. // Attempt to share back to owner of group share
  274. OC_User::setUserId($this->user2);
  275. $message = 'Sharing test.txt failed, because the user '.$this->user1.' is the original sharer';
  276. try {
  277. OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user1, OCP\PERMISSION_READ);
  278. $this->fail('Exception was expected: '.$message);
  279. } catch (Exception $exception) {
  280. $this->assertEquals($message, $exception->getMessage());
  281. }
  282. // Attempt to share back to group
  283. $message = 'Sharing test.txt failed, because this item is already shared with '.$this->group1;
  284. try {
  285. OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\PERMISSION_READ);
  286. $this->fail('Exception was expected: '.$message);
  287. } catch (Exception $exception) {
  288. $this->assertEquals($message, $exception->getMessage());
  289. }
  290. // Attempt to share back to member of group
  291. $message ='Sharing test.txt failed, because this item is already shared with '.$this->user3;
  292. try {
  293. OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\PERMISSION_READ);
  294. $this->fail('Exception was expected: '.$message);
  295. } catch (Exception $exception) {
  296. $this->assertEquals($message, $exception->getMessage());
  297. }
  298. // Unshare
  299. OC_User::setUserId($this->user1);
  300. $this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1));
  301. // Valid share with same person - user then group
  302. $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ | OCP\PERMISSION_DELETE | OCP\PERMISSION_SHARE));
  303. $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE));
  304. OC_User::setUserId($this->user2);
  305. $this->assertEquals(array('test.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
  306. $this->assertEquals(array(OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE | OCP\PERMISSION_DELETE | OCP\PERMISSION_SHARE), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS));
  307. OC_User::setUserId($this->user3);
  308. $this->assertEquals(array('test.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
  309. $this->assertEquals(array(OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS));
  310. // Valid reshare
  311. OC_User::setUserId($this->user2);
  312. $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user4, OCP\PERMISSION_READ));
  313. OC_User::setUserId($this->user4);
  314. $this->assertEquals(array('test.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
  315. // Unshare from user only
  316. OC_User::setUserId($this->user1);
  317. $this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2));
  318. OC_User::setUserId($this->user2);
  319. $this->assertEquals(array(OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS));
  320. OC_User::setUserId($this->user4);
  321. $this->assertEquals(array(), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
  322. // Valid share with same person - group then user
  323. OC_User::setUserId($this->user1);
  324. $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\PERMISSION_READ | OCP\PERMISSION_DELETE));
  325. OC_User::setUserId($this->user2);
  326. $this->assertEquals(array('test.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
  327. $this->assertEquals(array(OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE | OCP\PERMISSION_DELETE), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS));
  328. // Unshare from group only
  329. OC_User::setUserId($this->user1);
  330. $this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1));
  331. OC_User::setUserId($this->user2);
  332. $this->assertEquals(array(OCP\PERMISSION_READ | OCP\PERMISSION_DELETE), OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS));
  333. // Attempt user specific target conflict
  334. OC_User::setUserId($this->user3);
  335. $this->assertTrue(OCP\Share::shareItem('test', 'share.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\PERMISSION_READ | OCP\PERMISSION_SHARE));
  336. OC_User::setUserId($this->user2);
  337. $to_test = OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET);
  338. $this->assertEquals(2, count($to_test));
  339. $this->assertTrue(in_array('test.txt', $to_test));
  340. $this->assertTrue(in_array('test1.txt', $to_test));
  341. // Valid reshare
  342. $this->assertTrue(OCP\Share::shareItem('test', 'share.txt', OCP\Share::SHARE_TYPE_USER, $this->user4, OCP\PERMISSION_READ | OCP\PERMISSION_SHARE));
  343. OC_User::setUserId($this->user4);
  344. $this->assertEquals(array('test1.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
  345. // Remove user from group
  346. OC_Group::removeFromGroup($this->user2, $this->group1);
  347. OC_User::setUserId($this->user2);
  348. $this->assertEquals(array('test.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
  349. OC_User::setUserId($this->user4);
  350. $this->assertEquals(array(), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
  351. // Add user to group
  352. OC_Group::addToGroup($this->user4, $this->group1);
  353. $this->assertEquals(array('test.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
  354. // Unshare from self
  355. $this->assertTrue(OCP\Share::unshareFromSelf('test', 'test.txt'));
  356. $this->assertEquals(array(), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
  357. OC_User::setUserId($this->user2);
  358. $this->assertEquals(array('test.txt'), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
  359. // Remove group
  360. OC_Group::deleteGroup($this->group1);
  361. OC_User::setUserId($this->user4);
  362. $this->assertEquals(array(), OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET));
  363. OC_User::setUserId($this->user3);
  364. $this->assertEquals(array(), OCP\Share::getItemsShared('test'));
  365. }
  366. }