diff options
author | Morris Jobke <hey@morrisjobke.de> | 2017-08-15 11:26:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-15 11:26:26 +0200 |
commit | c5c23b30b9f510ce211d9fa3187dc3c8cff4116e (patch) | |
tree | 630b3e9fd7c83f4b491457e37d3c6d5a20225ba7 /tests/lib/Share/ShareTest.php | |
parent | cc40f02684a3b5e68003a6bb29afcce2bc639a86 (diff) | |
parent | f640b56bfac72d2c3fd394fe6564e93020243b7f (diff) | |
download | nextcloud-server-c5c23b30b9f510ce211d9fa3187dc3c8cff4116e.tar.gz nextcloud-server-c5c23b30b9f510ce211d9fa3187dc3c8cff4116e.zip |
Merge pull request #6116 from nextcloud/cleanup-unused-methods
Cleanup unused methods
Diffstat (limited to 'tests/lib/Share/ShareTest.php')
-rw-r--r-- | tests/lib/Share/ShareTest.php | 880 |
1 files changed, 0 insertions, 880 deletions
diff --git a/tests/lib/Share/ShareTest.php b/tests/lib/Share/ShareTest.php index 4ce40a2accd..0442e06fc45 100644 --- a/tests/lib/Share/ShareTest.php +++ b/tests/lib/Share/ShareTest.php @@ -143,282 +143,6 @@ class ShareTest extends \Test\TestCase { } } - public function testInvalidItemType() { - $message = 'Sharing backend for foobar not found'; - try { - \OCP\Share::shareItem('foobar', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ); - $this->fail('Exception was expected: '.$message); - } catch (\Exception $exception) { - $this->assertEquals($message, $exception->getMessage()); - } - try { - \OCP\Share::getItemsSharedWith('foobar'); - $this->fail('Exception was expected: '.$message); - } catch (\Exception $exception) { - $this->assertEquals($message, $exception->getMessage()); - } - try { - \OCP\Share::getItemSharedWith('foobar', 'test.txt'); - $this->fail('Exception was expected: '.$message); - } catch (\Exception $exception) { - $this->assertEquals($message, $exception->getMessage()); - } - try { - \OCP\Share::getItemSharedWithBySource('foobar', 'test.txt'); - $this->fail('Exception was expected: '.$message); - } catch (\Exception $exception) { - $this->assertEquals($message, $exception->getMessage()); - } - try { - \OCP\Share::getItemShared('foobar', 'test.txt'); - $this->fail('Exception was expected: '.$message); - } catch (\Exception $exception) { - $this->assertEquals($message, $exception->getMessage()); - } - try { - \OCP\Share::unshare('foobar', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2); - $this->fail('Exception was expected: '.$message); - } catch (\Exception $exception) { - $this->assertEquals($message, $exception->getMessage()); - } - try { - \OCP\Share::setPermissions('foobar', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_UPDATE); - $this->fail('Exception was expected: '.$message); - } catch (\Exception $exception) { - $this->assertEquals($message, $exception->getMessage()); - } - } - - protected function shareUserOneTestFileWithUserTwo() { - \OC_User::setUserId($this->user1->getUID()); - $this->assertTrue( - \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2->getUID(), \OCP\Constants::PERMISSION_READ), - 'Failed asserting that user 1 successfully shared text.txt with user 2.' - ); - $this->assertContains( - 'test.txt', - \OCP\Share::getItemShared('test', 'test.txt', Backend::FORMAT_SOURCE), - 'Failed asserting that test.txt is a shared file of user 1.' - ); - - \OC_User::setUserId($this->user2->getUID()); - $this->assertContains( - 'test.txt', - \OCP\Share::getItemSharedWith('test', 'test.txt', Backend::FORMAT_SOURCE), - 'Failed asserting that user 2 has access to test.txt after initial sharing.' - ); - } - - protected function shareUserTestFileAsLink() { - \OC_User::setUserId($this->user1->getUID()); - $result = \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_LINK, null, \OCP\Constants::PERMISSION_READ); - $this->assertTrue(is_string($result)); - } - - /** - * @param string $sharer - * @param string $receiver - */ - protected function shareUserTestFileWithUser($sharer, $receiver) { - \OC_User::setUserId($sharer); - $this->assertTrue( - \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $receiver, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE), - 'Failed asserting that ' . $sharer . ' successfully shared text.txt with ' . $receiver . '.' - ); - $this->assertContains( - 'test.txt', - \OCP\Share::getItemShared('test', 'test.txt', Backend::FORMAT_SOURCE), - 'Failed asserting that test.txt is a shared file of ' . $sharer . '.' - ); - - \OC_User::setUserId($receiver); - $this->assertContains( - 'test.txt', - \OCP\Share::getItemSharedWith('test', 'test.txt', Backend::FORMAT_SOURCE), - 'Failed asserting that ' . $receiver . ' has access to test.txt after initial sharing.' - ); - } - - public function testShareWithUser() { - // Invalid shares - $message = 'Sharing test.txt failed, because you can not share with yourself'; - try { - \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user1->getUID(), \OCP\Constants::PERMISSION_READ); - $this->fail('Exception was expected: '.$message); - } catch (\Exception $exception) { - $this->assertEquals($message, $exception->getMessage()); - } - $message = 'Sharing test.txt failed, because the user foobar does not exist'; - try { - \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, 'foobar', \OCP\Constants::PERMISSION_READ); - $this->fail('Exception was expected: '.$message); - } catch (\Exception $exception) { - $this->assertEquals($message, $exception->getMessage()); - } - $message = 'Sharing foobar failed, because the sharing backend for test could not find its source'; - try { - \OCP\Share::shareItem('test', 'foobar', \OCP\Share::SHARE_TYPE_USER, $this->user2->getUID(), \OCP\Constants::PERMISSION_READ); - $this->fail('Exception was expected: '.$message); - } catch (\Exception $exception) { - $this->assertEquals($message, $exception->getMessage()); - } - - // Valid share - $this->shareUserOneTestFileWithUserTwo(); - - // Attempt to share again - \OC_User::setUserId($this->user1->getUID()); - $message = 'Sharing test.txt failed, because this item is already shared with '.$this->user2->getUID(); - try { - \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2->getUID(), \OCP\Constants::PERMISSION_READ); - $this->fail('Exception was expected: '.$message); - } catch (\Exception $exception) { - $this->assertEquals($message, $exception->getMessage()); - } - - // Attempt to share back - \OC_User::setUserId($this->user2->getUID()); - $message = 'Sharing failed, because the user '.$this->user1->getUID().' is the original sharer'; - try { - \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user1->getUID(), \OCP\Constants::PERMISSION_READ); - $this->fail('Exception was expected: '.$message); - } catch (\Exception $exception) { - $this->assertEquals($message, $exception->getMessage()); - } - - // Unshare - \OC_User::setUserId($this->user1->getUID()); - $this->assertTrue(\OCP\Share::unshare('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2->getUID())); - - // Attempt reshare without share permission - $this->assertTrue(\OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2->getUID(), \OCP\Constants::PERMISSION_READ)); - \OC_User::setUserId($this->user2->getUID()); - $message = 'Sharing test.txt failed, because resharing is not allowed'; - try { - \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user3->getUID(), \OCP\Constants::PERMISSION_READ); - $this->fail('Exception was expected: '.$message); - } catch (\Exception $exception) { - $this->assertEquals($message, $exception->getMessage()); - } - - // Owner grants share and update permission - \OC_User::setUserId($this->user1->getUID()); - $this->assertTrue(\OCP\Share::setPermissions('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2->getUID(), \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE)); - - // Attempt reshare with escalated permissions - \OC_User::setUserId($this->user2->getUID()); - $message = 'Sharing test.txt failed, because the permissions exceed permissions granted to '.$this->user2->getUID(); - try { - \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user3->getUID(), \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_DELETE); - $this->fail('Exception was expected: '.$message); - } catch (\Exception $exception) { - $this->assertEquals($message, $exception->getMessage()); - } - - // Valid reshare - $this->assertTrue(\OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user3->getUID(), \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE)); - $this->assertEquals(array('test.txt'), \OCP\Share::getItemShared('test', 'test.txt', Backend::FORMAT_SOURCE)); - \OC_User::setUserId($this->user3->getUID()); - $this->assertEquals(array('test.txt'), \OCP\Share::getItemSharedWith('test', 'test.txt', Backend::FORMAT_SOURCE)); - $this->assertEquals(array(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE), \OCP\Share::getItemSharedWith('test', 'test.txt', Backend::FORMAT_PERMISSIONS)); - - // Attempt to escalate permissions - \OC_User::setUserId($this->user2->getUID()); - $message = 'Setting permissions for test.txt failed, because the permissions exceed permissions granted to '.$this->user2->getUID(); - try { - \OCP\Share::setPermissions('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user3->getUID(), \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_DELETE); - $this->fail('Exception was expected: '.$message); - } catch (\Exception $exception) { - $this->assertEquals($message, $exception->getMessage()); - } - - // Remove update permission - \OC_User::setUserId($this->user1->getUID()); - $this->assertTrue(\OCP\Share::setPermissions('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2->getUID(), \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE)); - \OC_User::setUserId($this->user2->getUID()); - $this->assertEquals(array(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE), \OCP\Share::getItemSharedWith('test', 'test.txt', Backend::FORMAT_PERMISSIONS)); - \OC_User::setUserId($this->user3->getUID()); - $this->assertEquals(array(\OCP\Constants::PERMISSION_READ), \OCP\Share::getItemSharedWith('test', 'test.txt', Backend::FORMAT_PERMISSIONS)); - - // Remove share permission - \OC_User::setUserId($this->user1->getUID()); - $this->assertTrue(\OCP\Share::setPermissions('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2->getUID(), \OCP\Constants::PERMISSION_READ)); - \OC_User::setUserId($this->user2->getUID()); - $this->assertEquals(array(\OCP\Constants::PERMISSION_READ), \OCP\Share::getItemSharedWith('test', 'test.txt', Backend::FORMAT_PERMISSIONS)); - \OC_User::setUserId($this->user3->getUID()); - $this->assertSame(array(), \OCP\Share::getItemSharedWith('test', 'test.txt')); - - // Reshare again, and then have owner unshare - \OC_User::setUserId($this->user1->getUID()); - $this->assertTrue(\OCP\Share::setPermissions('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2->getUID(), \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE)); - \OC_User::setUserId($this->user2->getUID()); - $this->assertTrue(\OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user3->getUID(), \OCP\Constants::PERMISSION_READ)); - \OC_User::setUserId($this->user1->getUID()); - $this->assertTrue(\OCP\Share::unshare('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2->getUID())); - \OC_User::setUserId($this->user2->getUID()); - $this->assertSame(array(), \OCP\Share::getItemSharedWith('test', 'test.txt')); - \OC_User::setUserId($this->user3->getUID()); - $this->assertSame(array(), \OCP\Share::getItemSharedWith('test', 'test.txt')); - - // Attempt target conflict - \OC_User::setUserId($this->user1->getUID()); - $this->assertTrue(\OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2->getUID(), \OCP\Constants::PERMISSION_READ)); - \OC_User::setUserId($this->user3->getUID()); - $this->assertTrue(\OCP\Share::shareItem('test', 'share.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2->getUID(), \OCP\Constants::PERMISSION_READ)); - - \OC_User::setUserId($this->user2->getUID()); - $to_test = \OCP\Share::getItemsSharedWith('test', Backend::FORMAT_TARGET); - $this->assertEquals(2, count($to_test)); - $this->assertTrue(in_array('test.txt', $to_test)); - $this->assertTrue(in_array('test1.txt', $to_test)); - - // Unshare from self - $this->assertTrue(\OCP\Share::unshareFromSelf('test', 'test.txt')); - $this->assertEquals(array('test1.txt'), \OCP\Share::getItemsSharedWith('test', Backend::FORMAT_TARGET)); - - // Unshare from self via source - $this->assertTrue(\OCP\Share::unshareFromSelf('test', 'share.txt', true)); - $this->assertEquals(array(), \OCP\Share::getItemsSharedWith('test', Backend::FORMAT_TARGET)); - - \OC_User::setUserId($this->user1->getUID()); - $this->assertTrue(\OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2->getUID(), \OCP\Constants::PERMISSION_READ)); - \OC_User::setUserId($this->user3->getUID()); - $this->assertTrue(\OCP\Share::shareItem('test', 'share.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2->getUID(), \OCP\Constants::PERMISSION_READ)); - - \OC_User::setUserId($this->user2->getUID()); - $to_test = \OCP\Share::getItemsSharedWith('test', Backend::FORMAT_TARGET); - $this->assertEquals(2, count($to_test)); - $this->assertTrue(in_array('test.txt', $to_test)); - $this->assertTrue(in_array('test1.txt', $to_test)); - - // Remove user - \OC_User::setUserId($this->user1->getUID()); - $user = \OC::$server->getUserManager()->get($this->user1->getUID()); - if ($user !== null) { $user->delete(); } - \OC_User::setUserId($this->user2->getUID()); - $this->assertEquals(array('test1.txt'), \OCP\Share::getItemsSharedWith('test', Backend::FORMAT_TARGET)); - } - - public function testShareWithUserExpirationExpired() { - \OC_User::setUserId($this->user1->getUID()); - $this->shareUserOneTestFileWithUserTwo(); - $this->shareUserTestFileAsLink(); - - // manipulate share table and set expire date to the past - $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `item_type` = ? AND `item_source` = ? AND `uid_owner` = ? AND `share_type` = ?'); - $query->bindValue(1, new \DateTime($this->dateInPast), 'datetime'); - $query->bindValue(2, 'test'); - $query->bindValue(3, 'test.txt'); - $query->bindValue(4, $this->user1->getUID()); - $query->bindValue(5, \OCP\Share::SHARE_TYPE_LINK); - $query->execute(); - - $shares = \OCP\Share::getItemsShared('test'); - $this->assertSame(1, count($shares)); - $share = reset($shares); - $this->assertSame(\OCP\Share::SHARE_TYPE_USER, $share['share_type']); - } - public function testGetShareFromOutsideFilesFolder() { \OC_User::setUserId($this->user1->getUID()); $view = new \OC\Files\View('/' . $this->user1->getUID() . '/'); @@ -459,73 +183,6 @@ class ShareTest extends \Test\TestCase { $this->assertEmpty($result, 'Share must not be returned for files outside of "files"'); } - public function testSetExpireDateInPast() { - \OC_User::setUserId($this->user1->getUID()); - $this->shareUserOneTestFileWithUserTwo(); - $this->shareUserTestFileAsLink(); - - $setExpireDateFailed = false; - try { - $this->assertTrue( - \OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInPast, ''), - 'Failed asserting that user 1 successfully set an expiration date for the test.txt share.' - ); - } catch (\Exception $e) { - $setExpireDateFailed = true; - } - - $this->assertTrue($setExpireDateFailed); - } - - public function testShareWithUserExpirationValid() { - \OC_User::setUserId($this->user1->getUID()); - $this->shareUserOneTestFileWithUserTwo(); - $this->shareUserTestFileAsLink(); - - - $this->assertTrue( - \OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInFuture, ''), - 'Failed asserting that user 1 successfully set an expiration date for the test.txt share.' - ); - - $shares = \OCP\Share::getItemsShared('test'); - $this->assertSame(2, count($shares)); - - } - - /* - * if user is in a group excluded from resharing, then the share permission should - * be removed - */ - public function testShareWithUserAndUserIsExcludedFromResharing() { - - \OC_User::setUserId($this->user1->getUID()); - $this->assertTrue( - \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user4->getUID(), \OCP\Constants::PERMISSION_ALL), - 'Failed asserting that user 1 successfully shared text.txt with user 4.' - ); - $this->assertContains( - 'test.txt', - \OCP\Share::getItemShared('test', 'test.txt', Backend::FORMAT_SOURCE), - 'Failed asserting that test.txt is a shared file of user 1.' - ); - - // exclude group2 from sharing - \OC::$server->getAppConfig()->setValue('core', 'shareapi_exclude_groups_list', $this->group2->getGID()); - \OC::$server->getAppConfig()->setValue('core', 'shareapi_exclude_groups', "yes"); - - \OC_User::setUserId($this->user4->getUID()); - - $share = \OCP\Share::getItemSharedWith('test', 'test.txt'); - - $this->assertSame(\OCP\Constants::PERMISSION_ALL & ~\OCP\Constants::PERMISSION_SHARE, $share['permissions'], - 'Failed asserting that user 4 is excluded from re-sharing'); - - \OC::$server->getAppConfig()->deleteKey('core', 'shareapi_exclude_groups_list'); - \OC::$server->getAppConfig()->deleteKey('core', 'shareapi_exclude_groups'); - - } - public function testSharingAFolderThatIsSharedWithAGroupOfTheOwner() { \OC_User::setUserId($this->user1->getUID()); $view = new \OC\Files\View('/' . $this->user1->getUID() . '/'); @@ -595,33 +252,6 @@ class ShareTest extends \Test\TestCase { } } - protected function shareUserOneTestFileWithGroupOne() { - \OC_User::setUserId($this->user1->getUID()); - $this->assertTrue( - \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_GROUP, $this->group1->getGID(), \OCP\Constants::PERMISSION_READ), - 'Failed asserting that user 1 successfully shared text.txt with group 1.' - ); - $this->assertContains( - 'test.txt', - \OCP\Share::getItemShared('test', 'test.txt', Backend::FORMAT_SOURCE), - 'Failed asserting that test.txt is a shared file of user 1.' - ); - - \OC_User::setUserId($this->user2->getUID()); - $this->assertContains( - 'test.txt', - \OCP\Share::getItemSharedWith('test', 'test.txt', Backend::FORMAT_SOURCE), - 'Failed asserting that user 2 has access to test.txt after initial sharing.' - ); - - \OC_User::setUserId($this->user3->getUID()); - $this->assertContains( - 'test.txt', - \OCP\Share::getItemSharedWith('test', 'test.txt', Backend::FORMAT_SOURCE), - 'Failed asserting that user 3 has access to test.txt after initial sharing.' - ); - } - /** * Test that unsharing from group will also delete all * child entries @@ -668,40 +298,6 @@ class ShareTest extends \Test\TestCase { } } - public function testShareWithGroupAndUserBothHaveTheSameId() { - - $this->shareUserTestFileWithUser($this->user1->getUID(), $this->groupAndUser_user->getUID()); - - \OC_User::setUserId($this->groupAndUser_user->getUID()); - - $this->assertEquals(array('test.txt'), \OCP\Share::getItemSharedWith('test', 'test.txt', Backend::FORMAT_SOURCE), - '"groupAndUser"-User does not see the file but it was shared with him'); - - \OC_User::setUserId($this->user2->getUID()); - $this->assertEquals(array(), \OCP\Share::getItemSharedWith('test', 'test.txt', Backend::FORMAT_SOURCE), - 'User2 sees test.txt but it was only shared with the user "groupAndUser" and not with group'); - - \OC_User::setUserId($this->user1->getUID()); - $this->assertTrue(\OCP\Share::unshareAll('test', 'test.txt')); - - $this->assertTrue( - \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_GROUP, $this->groupAndUser_group->getGID(), \OCP\Constants::PERMISSION_READ), - 'Failed asserting that user 1 successfully shared text.txt with group 1.' - ); - - \OC_User::setUserId($this->groupAndUser_user->getUID()); - $this->assertEquals(array(), \OCP\Share::getItemSharedWith('test', 'test.txt', Backend::FORMAT_SOURCE), - '"groupAndUser"-User sees test.txt but it was only shared with the group "groupAndUser" and not with the user'); - - \OC_User::setUserId($this->user2->getUID()); - $this->assertEquals(array('test.txt'), \OCP\Share::getItemSharedWith('test', 'test.txt', Backend::FORMAT_SOURCE), - 'User2 does not see test.txt but it was shared with the group "groupAndUser"'); - - \OC_User::setUserId($this->user1->getUID()); - $this->assertTrue(\OCP\Share::unshareAll('test', 'test.txt')); - - } - /** * @param boolean|string $token * @return array @@ -841,48 +437,6 @@ class ShareTest extends \Test\TestCase { $qb->delete('share')->execute(); } - public function testShareItemWithLink() { - \OC_User::setUserId($this->user1->getUID()); - $token = \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_LINK, null, \OCP\Constants::PERMISSION_READ); - $this->assertInternalType( - 'string', - $token, - 'Failed asserting that user 1 successfully shared text.txt as link with token.' - ); - - // testGetShareByTokenNoExpiration - $row = $this->getShareByValidToken($token); - $this->assertEmpty( - $row['expiration'], - 'Failed asserting that the returned row does not have an expiration date.' - ); - - // testGetShareByTokenExpirationValid - $this->assertTrue( - \OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInFuture, ''), - 'Failed asserting that user 1 successfully set a future expiration date for the test.txt share.' - ); - $row = $this->getShareByValidToken($token); - $this->assertNotEmpty( - $row['expiration'], - 'Failed asserting that the returned row has an expiration date.' - ); - - // manipulate share table and set expire date to the past - $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `item_type` = ? AND `item_source` = ? AND `uid_owner` = ? AND `share_type` = ?'); - $query->bindValue(1, new \DateTime($this->dateInPast), 'datetime'); - $query->bindValue(2, 'test'); - $query->bindValue(3, 'test.txt'); - $query->bindValue(4, $this->user1->getUID()); - $query->bindValue(5, \OCP\Share::SHARE_TYPE_LINK); - $query->execute(); - - $this->assertFalse( - \OCP\Share::getShareByToken($token), - 'Failed asserting that an expired share could not be found.' - ); - } - public function testShareItemWithLinkAndDefaultExpireDate() { \OC_User::setUserId($this->user1->getUID()); @@ -940,59 +494,6 @@ class ShareTest extends \Test\TestCase { \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_REMOTE, $remoteId, \OCP\Constants::PERMISSION_ALL); } - public function testUnshareAll() { - $this->shareUserTestFileWithUser($this->user1->getUID(), $this->user2->getUID()); - $this->shareUserTestFileWithUser($this->user2->getUID(), $this->user3->getUID()); - $this->shareUserTestFileWithUser($this->user3->getUID(), $this->user4->getUID()); - $this->shareUserOneTestFileWithGroupOne(); - - \OC_User::setUserId($this->user1->getUID()); - $this->assertEquals( - array('test.txt', 'test.txt'), - \OCP\Share::getItemsShared('test', Backend::FORMAT_SOURCE), - 'Failed asserting that the test.txt file is shared exactly two times by user1.' - ); - - \OC_User::setUserId($this->user2->getUID()); - $this->assertEquals( - array('test.txt'), - \OCP\Share::getItemsShared('test', Backend::FORMAT_SOURCE), - 'Failed asserting that the test.txt file is shared exactly once by user2.' - ); - - \OC_User::setUserId($this->user3->getUID()); - $this->assertEquals( - array('test.txt'), - \OCP\Share::getItemsShared('test', Backend::FORMAT_SOURCE), - 'Failed asserting that the test.txt file is shared exactly once by user3.' - ); - - $this->assertTrue( - \OCP\Share::unshareAll('test', 'test.txt'), - 'Failed asserting that user 3 successfully unshared all shares of the test.txt share.' - ); - - $this->assertEquals( - array(), - \OCP\Share::getItemsShared('test'), - 'Failed asserting that the share of the test.txt file by user 3 has been removed.' - ); - - \OC_User::setUserId($this->user1->getUID()); - $this->assertEquals( - array(), - \OCP\Share::getItemsShared('test'), - 'Failed asserting that both shares of the test.txt file by user 1 have been removed.' - ); - - \OC_User::setUserId($this->user2->getUID()); - $this->assertEquals( - array(), - \OCP\Share::getItemsShared('test'), - 'Failed asserting that the share of the test.txt file by user 2 has been removed.' - ); - } - /** * @dataProvider checkPasswordProtectedShareDataProvider * @param $expected @@ -1166,324 +667,6 @@ class ShareTest extends \Test\TestCase { } /** - * Ensure that we do not allow removing a an expiration date from a link share if this - * is enforced by the settings. - */ - public function testClearExpireDateWhileEnforced() { - \OC_User::setUserId($this->user1->getUID()); - - \OC::$server->getAppConfig()->setValue('core', 'shareapi_default_expire_date', 'yes'); - \OC::$server->getAppConfig()->setValue('core', 'shareapi_expire_after_n_days', '2'); - \OC::$server->getAppConfig()->setValue('core', 'shareapi_enforce_expire_date', 'yes'); - - $token = \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_LINK, null, \OCP\Constants::PERMISSION_READ); - $this->assertInternalType( - 'string', - $token, - 'Failed asserting that user 1 successfully shared text.txt as link with token.' - ); - - $setExpireDateFailed = false; - try { - $this->assertTrue( - \OCP\Share::setExpirationDate('test', 'test.txt', '', ''), - 'Failed asserting that user 1 successfully set an expiration date for the test.txt share.' - ); - } catch (\Exception $e) { - $setExpireDateFailed = true; - } - - $this->assertTrue($setExpireDateFailed); - - \OC::$server->getAppConfig()->deleteKey('core', 'shareapi_default_expire_date'); - \OC::$server->getAppConfig()->deleteKey('core', 'shareapi_expire_after_n_days'); - \OC::$server->getAppConfig()->deleteKey('core', 'shareapi_enforce_expire_date'); - } - - /** - * Cannot set password is there is no user - * - * @expectedException \Exception - * @expectedExceptionMessage User not logged in - */ - public function testSetPasswordNoUser() { - $userSession = $this->getMockBuilder('\OCP\IUserSession') - ->disableOriginalConstructor() - ->getMock(); - - $connection = $this->getMockBuilder('\OC\DB\Connection') - ->disableOriginalConstructor() - ->getMock(); - - $config = $this->getMockBuilder('\OCP\IConfig') - ->disableOriginalConstructor() - ->getMock(); - - \OC\Share\Share::setPassword($userSession, $connection, $config, 1, 'pass'); - } - - public function testPasswords() { - $pass = 'secret'; - - $this->shareUserTestFileAsLink(); - - $userSession = \OC::$server->getUserSession(); - $connection = \OC::$server->getDatabaseConnection(); - $config = $this->getMockBuilder('\OCP\IConfig') - ->disableOriginalConstructor() - ->getMock(); - - // Find the share ID in the db - $qb = $connection->getQueryBuilder(); - $qb->select('id') - ->from('share') - ->where($qb->expr()->eq('item_type', $qb->createParameter('type'))) - ->andWhere($qb->expr()->eq('item_source', $qb->createParameter('source'))) - ->andWhere($qb->expr()->eq('uid_owner', $qb->createParameter('owner'))) - ->andWhere($qb->expr()->eq('share_type', $qb->createParameter('share_type'))) - ->setParameter('type', 'test') - ->setParameter('source', 'test.txt') - ->setParameter('owner', $this->user1->getUID()) - ->setParameter('share_type', \OCP\Share::SHARE_TYPE_LINK); - - $result = $qb->execute(); - $res = $result->fetchAll(); - $result->closeCursor(); - $this->assertCount(1, $res); - $id = $res[0]['id']; - - // Set password on share - $res = \OC\Share\Share::setPassword($userSession, $connection, $config, $id, $pass); - $this->assertTrue($res); - - // Fetch the hash from the database - $qb = $connection->getQueryBuilder(); - $qb->select('share_with') - ->from('share') - ->where($qb->expr()->eq('id', $qb->createParameter('id'))) - ->setParameter('id', $id); - $result = $qb->execute(); - $hash = $result->fetch()['share_with']; - $result->closeCursor(); - - $hasher = \OC::$server->getHasher(); - - // Verify hash - $this->assertTrue($hasher->verify($pass, $hash)); - } - - /** - * Test setting a password when everything is fine - */ - public function testSetPassword() { - $user = $this->getMockBuilder('\OCP\IUser') - ->disableOriginalConstructor() - ->getMock(); - $user->method('getUID')->willReturn('user'); - - $userSession = $this->getMockBuilder('\OCP\IUserSession') - ->disableOriginalConstructor() - ->getMock(); - $userSession->method('getUser')->willReturn($user); - - - $ex = $this->getMockBuilder('\OC\DB\QueryBuilder\ExpressionBuilder\ExpressionBuilder') - ->disableOriginalConstructor() - ->getMock(); - $qb = $this->getMockBuilder('\OC\DB\QueryBuilder\QueryBuilder') - ->disableOriginalConstructor() - ->getMock(); - $qb->method('update')->will($this->returnSelf()); - $qb->method('set')->will($this->returnSelf()); - $qb->method('where')->will($this->returnSelf()); - $qb->method('andWhere')->will($this->returnSelf()); - $qb->method('select')->will($this->returnSelf()); - $qb->method('from')->will($this->returnSelf()); - $qb->method('setParameter')->will($this->returnSelf()); - $qb->method('expr')->willReturn($ex); - - $ret = $this->getMockBuilder('\Doctrine\DBAL\Driver\ResultStatement') - ->disableOriginalConstructor() - ->getMock(); - $ret->method('fetch')->willReturn(['uid_owner' => 'user']); - $qb->method('execute')->willReturn($ret); - - - $connection = $this->getMockBuilder('\OC\DB\Connection') - ->disableOriginalConstructor() - ->getMock(); - $connection->method('getQueryBuilder')->willReturn($qb); - - $config = $this->getMockBuilder('\OCP\IConfig') - ->disableOriginalConstructor() - ->getMock(); - - - $res = \OC\Share\Share::setPassword($userSession, $connection, $config, 1, 'pass'); - - $this->assertTrue($res); - } - - /** - * @expectedException \Exception - * @expectedExceptionMessage Cannot remove password - * - * Test removing a password when password is enforced - */ - public function testSetPasswordRemove() { - $user = $this->getMockBuilder('\OCP\IUser') - ->disableOriginalConstructor() - ->getMock(); - $user->method('getUID')->willReturn('user'); - - $userSession = $this->getMockBuilder('\OCP\IUserSession') - ->disableOriginalConstructor() - ->getMock(); - $userSession->method('getUser')->willReturn($user); - - - $ex = $this->getMockBuilder('\OC\DB\QueryBuilder\ExpressionBuilder\ExpressionBuilder') - ->disableOriginalConstructor() - ->getMock(); - $qb = $this->getMockBuilder('\OC\DB\QueryBuilder\QueryBuilder') - ->disableOriginalConstructor() - ->getMock(); - $qb->method('update')->will($this->returnSelf()); - $qb->method('select')->will($this->returnSelf()); - $qb->method('from')->will($this->returnSelf()); - $qb->method('set')->will($this->returnSelf()); - $qb->method('where')->will($this->returnSelf()); - $qb->method('andWhere')->will($this->returnSelf()); - $qb->method('setParameter')->will($this->returnSelf()); - $qb->method('expr')->willReturn($ex); - - $ret = $this->getMockBuilder('\Doctrine\DBAL\Driver\ResultStatement') - ->disableOriginalConstructor() - ->getMock(); - $ret->method('fetch')->willReturn(['uid_owner' => 'user']); - $qb->method('execute')->willReturn($ret); - - - $connection = $this->getMockBuilder('\OC\DB\Connection') - ->disableOriginalConstructor() - ->getMock(); - $connection->method('getQueryBuilder')->willReturn($qb); - - $config = $this->getMockBuilder('\OCP\IConfig') - ->disableOriginalConstructor() - ->getMock(); - $config->method('getAppValue')->willReturn('yes'); - - \OC\Share\Share::setPassword($userSession, $connection, $config, 1, ''); - } - - /** - * @expectedException \Exception - * @expectedExceptionMessage Share not found - * - * Test modification of invaid share - */ - public function testSetPasswordInvalidShare() { - $user = $this->getMockBuilder('\OCP\IUser') - ->disableOriginalConstructor() - ->getMock(); - $user->method('getUID')->willReturn('user'); - - $userSession = $this->getMockBuilder('\OCP\IUserSession') - ->disableOriginalConstructor() - ->getMock(); - $userSession->method('getUser')->willReturn($user); - - - $ex = $this->getMockBuilder('\OC\DB\QueryBuilder\ExpressionBuilder\ExpressionBuilder') - ->disableOriginalConstructor() - ->getMock(); - $qb = $this->getMockBuilder('\OC\DB\QueryBuilder\QueryBuilder') - ->disableOriginalConstructor() - ->getMock(); - $qb->method('update')->will($this->returnSelf()); - $qb->method('set')->will($this->returnSelf()); - $qb->method('where')->will($this->returnSelf()); - $qb->method('andWhere')->will($this->returnSelf()); - $qb->method('select')->will($this->returnSelf()); - $qb->method('from')->will($this->returnSelf()); - $qb->method('setParameter')->will($this->returnSelf()); - $qb->method('expr')->willReturn($ex); - - $ret = $this->getMockBuilder('\Doctrine\DBAL\Driver\ResultStatement') - ->disableOriginalConstructor() - ->getMock(); - $ret->method('fetch')->willReturn([]); - $qb->method('execute')->willReturn($ret); - - - $connection = $this->getMockBuilder('\OC\DB\Connection') - ->disableOriginalConstructor() - ->getMock(); - $connection->method('getQueryBuilder')->willReturn($qb); - - $config = $this->getMockBuilder('\OCP\IConfig') - ->disableOriginalConstructor() - ->getMock(); - - - \OC\Share\Share::setPassword($userSession, $connection, $config, 1, 'pass'); - } - - /** - * @expectedException \Exception - * @expectedExceptionMessage Cannot update share of a different user - * - * Test modification of share of another user - */ - public function testSetPasswordShareOtherUser() { - $user = $this->getMockBuilder('\OCP\IUser') - ->disableOriginalConstructor() - ->getMock(); - $user->method('getUID')->willReturn('user'); - - $userSession = $this->getMockBuilder('\OCP\IUserSession') - ->disableOriginalConstructor() - ->getMock(); - $userSession->method('getUser')->willReturn($user); - - - $ex = $this->getMockBuilder('\OC\DB\QueryBuilder\ExpressionBuilder\ExpressionBuilder') - ->disableOriginalConstructor() - ->getMock(); - $qb = $this->getMockBuilder('\OC\DB\QueryBuilder\QueryBuilder') - ->disableOriginalConstructor() - ->getMock(); - $qb->method('update')->will($this->returnSelf()); - $qb->method('set')->will($this->returnSelf()); - $qb->method('where')->will($this->returnSelf()); - $qb->method('andWhere')->will($this->returnSelf()); - $qb->method('select')->will($this->returnSelf()); - $qb->method('from')->will($this->returnSelf()); - $qb->method('setParameter')->will($this->returnSelf()); - $qb->method('expr')->willReturn($ex); - - $ret = $this->getMockBuilder('\Doctrine\DBAL\Driver\ResultStatement') - ->disableOriginalConstructor() - ->getMock(); - $ret->method('fetch')->willReturn(['uid_owner' => 'user2']); - $qb->method('execute')->willReturn($ret); - - - $connection = $this->getMockBuilder('\OC\DB\Connection') - ->disableOriginalConstructor() - ->getMock(); - $connection->method('getQueryBuilder')->willReturn($qb); - - $config = $this->getMockBuilder('\OCP\IConfig') - ->disableOriginalConstructor() - ->getMock(); - - - \OC\Share\Share::setPassword($userSession, $connection, $config, 1, 'pass'); - } - - /** * Make sure that a user cannot have multiple identical shares to remote users */ public function testOnlyOneRemoteShare() { @@ -1519,44 +702,6 @@ class ShareTest extends \Test\TestCase { } /** - * Test case for #19119 - */ - public function testReshareWithLinkDefaultExpirationDate() { - $config = \OC::$server->getConfig(); - $config->setAppValue('core', 'shareapi_default_expire_date', 'yes'); - $config->setAppValue('core', 'shareapi_expire_after_n_days', '2'); - - // Expiration date - $expireAt = time() + 2 * 24*60*60; - $date = new \DateTime(); - $date->setTimestamp($expireAt); - $date->setTime(0, 0, 0); - - //Share a file from user 1 to user 2 - $this->shareUserTestFileWithUser($this->user1->getUID(), $this->user2->getUID()); - - //User 2 shares as link - \OC_User::setUserId($this->user2->getUID()); - $result = \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_LINK, null, \OCP\Constants::PERMISSION_READ); - $this->assertTrue(is_string($result)); - - //Check if expire date is correct - $result = \OCP\Share::getItemShared('test', 'test.txt'); - $this->assertCount(1, $result); - $result = reset($result); - $this->assertNotEmpty($result['expiration']); - $expireDate = new \DateTime($result['expiration']); - $this->assertEquals($date, $expireDate); - - //Unshare - $this->assertTrue(\OCP\Share::unshareAll('test', 'test.txt')); - - //Reset config - $config->deleteAppValue('core', 'shareapi_default_expire_date'); - $config->deleteAppValue('core', 'shareapi_expire_after_n_days'); - } - - /** * Test case for #17560 */ public function testAccesToSharedSubFolder() { @@ -1652,31 +797,6 @@ class ShareTest extends \Test\TestCase { $this->assertEquals('Sharing failed, because the user ' . $this->user1->getUID() . ' is the original sharer', $e->getMessage()); } } - - /** - * @expectedException \OC\User\NoUserException - * @expectedExceptionMessage Backends provided no user object - */ - public function testGetUsersSharingFileWithException() { - $userManager = $this->createMock(IUserManager::class); - $logger = $this->createMock(ILogger::class); - $userManager - ->expects($this->once()) - ->method('get') - ->with('test') - ->willReturn(null); - $logger - ->expects($this->once()) - ->method('error') - ->with( - 'Backends provided no user object for test', - [ - 'app' => 'files', - ] - ); - - Share::getUsersSharingFile('/my/file/path', 'test', $userManager, $logger); - } } class DummyShareClass extends \OC\Share\Share { |