summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/tests
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2016-01-27 16:46:48 +0100
committerRoeland Jago Douma <rullzer@owncloud.com>2016-01-27 20:34:06 +0100
commitb321ceef60d98f3c8224c6bacc402c1ec1d08920 (patch)
tree77eb788a455e7a7a2ef3562c2ef8ca3e9aea2d31 /apps/files_sharing/tests
parent35a3432793919303726a7ea03d6a714db4b40707 (diff)
downloadnextcloud-server-b321ceef60d98f3c8224c6bacc402c1ec1d08920.tar.gz
nextcloud-server-b321ceef60d98f3c8224c6bacc402c1ec1d08920.zip
[Share 2.0] Also handle empty parameter in updateShare
* More sanity checks * More unit tests
Diffstat (limited to 'apps/files_sharing/tests')
-rw-r--r--apps/files_sharing/tests/api/share20ocstest.php238
1 files changed, 238 insertions, 0 deletions
diff --git a/apps/files_sharing/tests/api/share20ocstest.php b/apps/files_sharing/tests/api/share20ocstest.php
index 4bbcfb5a600..ce21e9675e2 100644
--- a/apps/files_sharing/tests/api/share20ocstest.php
+++ b/apps/files_sharing/tests/api/share20ocstest.php
@@ -932,4 +932,242 @@ class Share20OCSTest extends \Test\TestCase {
$this->assertEquals($expected->getMeta(), $result->getMeta());
$this->assertEquals($expected->getData(), $result->getData());
}
+
+ public function testUpdateShareCantAccess() {
+ $share = \OC::$server->getShareManager()->newShare();
+
+ $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
+
+ $expected = new \OC_OCS_Result(null, 404, 'wrong share Id, share doesn\'t exist.');
+ $result = $this->ocs->updateShare(42);
+
+ $this->assertEquals($expected->getMeta(), $result->getMeta());
+ $this->assertEquals($expected->getData(), $result->getData());
+ }
+
+ public function testUpdateNoParametersLink() {
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setPermissions(\OCP\Constants::PERMISSION_ALL)
+ ->setSharedBy($this->currentUser)
+ ->setShareType(\OCP\Share::SHARE_TYPE_LINK);
+
+ $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
+
+ $expected = new \OC_OCS_Result(null, 400, 'Wrong or no update parameter given');
+ $result = $this->ocs->updateShare(42);
+
+ $this->assertEquals($expected->getMeta(), $result->getMeta());
+ $this->assertEquals($expected->getData(), $result->getData());
+ }
+
+ public function testUpdateNoParametersOther() {
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setPermissions(\OCP\Constants::PERMISSION_ALL)
+ ->setSharedBy($this->currentUser)
+ ->setShareType(\OCP\Share::SHARE_TYPE_GROUP);
+
+ $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
+
+ $expected = new \OC_OCS_Result(null, 400, 'Wrong or no update parameter given');
+ $result = $this->ocs->updateShare(42);
+
+ $this->assertEquals($expected->getMeta(), $result->getMeta());
+ $this->assertEquals($expected->getData(), $result->getData());
+ }
+
+ public function testUpdateLinkShareClear() {
+ $ocs = $this->mockFormatShare();
+
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setPermissions(\OCP\Constants::PERMISSION_ALL)
+ ->setSharedBy($this->currentUser)
+ ->setShareType(\OCP\Share::SHARE_TYPE_LINK)
+ ->setPassword('password')
+ ->setExpirationDate(new \DateTime())
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+
+ $this->request
+ ->method('getParam')
+ ->will($this->returnValueMap([
+ ['publicUpload', null, 'false'],
+ ['expireDate', '', ''],
+ ['password', '', ''],
+ ]));
+
+ $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
+
+ $this->shareManager->expects($this->once())->method('updateShare')->with(
+ $this->callback(function (IShare $share) {
+ return $share->getPermissions() === \OCP\Constants::PERMISSION_READ &&
+ $share->getPassword() === null &&
+ $share->getExpirationDate() === null;
+ })
+ );
+
+ $expected = new \OC_OCS_Result(null);
+ $result = $ocs->updateShare(42);
+
+ $this->assertEquals($expected->getMeta(), $result->getMeta());
+ $this->assertEquals($expected->getData(), $result->getData());
+ }
+
+ public function testUpdateLinkShareSet() {
+ $ocs = $this->mockFormatShare();
+
+ $folder = $this->getMock('\OCP\Files\Folder');
+
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setPermissions(\OCP\Constants::PERMISSION_ALL)
+ ->setSharedBy($this->currentUser)
+ ->setShareType(\OCP\Share::SHARE_TYPE_LINK)
+ ->setPath($folder);
+
+ $this->request
+ ->method('getParam')
+ ->will($this->returnValueMap([
+ ['publicUpload', null, 'true'],
+ ['expireDate', '', '2000-01-01'],
+ ['password', '', 'password'],
+ ]));
+
+ $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
+ $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
+
+ $this->shareManager->expects($this->once())->method('updateShare')->with(
+ $this->callback(function (IShare $share) {
+ $date = new \DateTime('2000-01-01');
+ $date->setTime(0,0,0);
+
+ return $share->getPermissions() === \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE && \OCP\Constants::PERMISSION_DELETE &&
+ $share->getPassword() === 'password' &&
+ $share->getExpirationDate() == $date;
+ })
+ );
+
+ $expected = new \OC_OCS_Result(null);
+ $result = $ocs->updateShare(42);
+
+ $this->assertEquals($expected->getMeta(), $result->getMeta());
+ $this->assertEquals($expected->getData(), $result->getData());
+ }
+
+ public function testUpdateLinkShareInvalidDate() {
+ $ocs = $this->mockFormatShare();
+
+ $folder = $this->getMock('\OCP\Files\Folder');
+
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setPermissions(\OCP\Constants::PERMISSION_ALL)
+ ->setSharedBy($this->currentUser)
+ ->setShareType(\OCP\Share::SHARE_TYPE_LINK)
+ ->setPath($folder);
+
+ $this->request
+ ->method('getParam')
+ ->will($this->returnValueMap([
+ ['publicUpload', null, 'true'],
+ ['expireDate', '', '2000-01-a'],
+ ['password', '', 'password'],
+ ]));
+
+ $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
+ $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
+
+ $expected = new \OC_OCS_Result(null, 400, 'Invalid date. Format must be YYYY-MM-DD');
+ $result = $ocs->updateShare(42);
+
+ $this->assertEquals($expected->getMeta(), $result->getMeta());
+ $this->assertEquals($expected->getData(), $result->getData());
+ }
+
+ public function testUpdateLinkSharePublicUploadNotAllowed() {
+ $ocs = $this->mockFormatShare();
+
+ $folder = $this->getMock('\OCP\Files\Folder');
+
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setPermissions(\OCP\Constants::PERMISSION_ALL)
+ ->setSharedBy($this->currentUser)
+ ->setShareType(\OCP\Share::SHARE_TYPE_LINK)
+ ->setPath($folder);
+
+ $this->request
+ ->method('getParam')
+ ->will($this->returnValueMap([
+ ['publicUpload', null, 'true'],
+ ['expireDate', '', ''],
+ ['password', '', 'password'],
+ ]));
+
+ $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
+ $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(false);
+
+ $expected = new \OC_OCS_Result(null, 403, 'public upload disabled by the administrator');
+ $result = $ocs->updateShare(42);
+
+ $this->assertEquals($expected->getMeta(), $result->getMeta());
+ $this->assertEquals($expected->getData(), $result->getData());
+ }
+
+ public function testUpdateLinkSharePublicUploadOnFile() {
+ $ocs = $this->mockFormatShare();
+
+ $file = $this->getMock('\OCP\Files\File');
+
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setPermissions(\OCP\Constants::PERMISSION_ALL)
+ ->setSharedBy($this->currentUser)
+ ->setShareType(\OCP\Share::SHARE_TYPE_LINK)
+ ->setPath($file);
+
+ $this->request
+ ->method('getParam')
+ ->will($this->returnValueMap([
+ ['publicUpload', null, 'true'],
+ ['expireDate', '', ''],
+ ['password', '', 'password'],
+ ]));
+
+ $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
+ $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
+
+ $expected = new \OC_OCS_Result(null, 400, 'public upload is only possible for public shared folders');
+ $result = $ocs->updateShare(42);
+
+ $this->assertEquals($expected->getMeta(), $result->getMeta());
+ $this->assertEquals($expected->getData(), $result->getData());
+ }
+
+ public function testUpdateOtherPermissions() {
+ $ocs = $this->mockFormatShare();
+
+ $file = $this->getMock('\OCP\Files\File');
+
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setPermissions(\OCP\Constants::PERMISSION_ALL)
+ ->setSharedBy($this->currentUser)
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setPath($file);
+
+ $this->request
+ ->method('getParam')
+ ->will($this->returnValueMap([
+ ['permissions', null, '31'],
+ ]));
+
+ $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
+ $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
+
+ $this->shareManager->expects($this->once())->method('updateShare')->with(
+ $this->callback(function (IShare $share) {
+ return $share->getPermissions() === \OCP\Constants::PERMISSION_ALL;
+ })
+ );
+
+ $expected = new \OC_OCS_Result(null);
+ $result = $ocs->updateShare(42);
+
+ $this->assertEquals($expected->getMeta(), $result->getMeta());
+ $this->assertEquals($expected->getData(), $result->getData());
+ }
}