Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoeland Douma <rullzer@users.noreply.github.com>2015-07-28 14:06:25 +0300
committerRoeland Douma <rullzer@users.noreply.github.com>2015-07-28 14:06:25 +0300
commit73169b0edbc1086d2a287c26640e2a2428449971 (patch)
tree592282ffb1f48edbdacc6e4c18fc2124cfa315f4 /tests/lib/share
parent4076f84f888a16e00dc6978a47141b8d8cac8413 (diff)
parente35b97e4c5dd87dd03e409db0e20cd6c844d966b (diff)
Merge pull request #17195 from rullzer/no_multiple_remote_shares_of_same_file
Remote shares should be uique
Diffstat (limited to 'tests/lib/share')
-rw-r--r--tests/lib/share/share.php36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php
index 52511810efa..b6d3e16826d 100644
--- a/tests/lib/share/share.php
+++ b/tests/lib/share/share.php
@@ -1531,6 +1531,42 @@ class Test_Share extends \Test\TestCase {
\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() {
+ $oldHttpHelper = \OC::$server->query('HTTPHelper');
+ $httpHelperMock = $this->getMockBuilder('OC\HttpHelper')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->setHttpHelper($httpHelperMock);
+
+ $httpHelperMock->expects($this->at(0))
+ ->method('post')
+ ->with($this->stringStartsWith('https://localhost/ocs/v1.php/cloud/shares'), $this->anything())
+ ->willReturn(['success' => true, 'result' => json_encode(['ocs' => ['meta' => ['statuscode' => 100]]])]);
+
+ \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_REMOTE, 'foo@localhost', \OCP\Constants::PERMISSION_READ);
+ $shares = \OCP\Share::getItemShared('test', 'test.txt');
+ $share = array_shift($shares);
+
+ //Try share again
+ try {
+ \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_REMOTE, 'foo@localhost', \OCP\Constants::PERMISSION_READ);
+ $this->fail('Identical remote shares are not allowed');
+ } catch (\Exception $e) {
+ $this->assertEquals('Sharing test.txt failed, because this item is already shared with foo@localhost', $e->getMessage());
+ }
+
+ $httpHelperMock->expects($this->at(0))
+ ->method('post')
+ ->with($this->stringStartsWith('https://localhost/ocs/v1.php/cloud/shares/' . $share['id'] . '/unshare'), $this->anything())
+ ->willReturn(['success' => true, 'result' => json_encode(['ocs' => ['meta' => ['statuscode' => 100]]])]);
+
+ \OCP\Share::unshare('test', 'test.txt', \OCP\Share::SHARE_TYPE_REMOTE, 'foo@localhost');
+ $this->setHttpHelper($oldHttpHelper);
+ }
+
}
class DummyShareClass extends \OC\Share\Share {