summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2016-01-27 17:09:02 +0100
committerRoeland Jago Douma <rullzer@owncloud.com>2016-01-27 20:36:31 +0100
commitf5c45dfe7b2aecbeb9b7193ce14bc28511006d18 (patch)
tree43727dd7c6f87488904e7f9519a83dec72b0c5fd /apps/files_sharing
parentb321ceef60d98f3c8224c6bacc402c1ec1d08920 (diff)
downloadnextcloud-server-f5c45dfe7b2aecbeb9b7193ce14bc28511006d18.tar.gz
nextcloud-server-f5c45dfe7b2aecbeb9b7193ce14bc28511006d18.zip
[Share 2.0] Still allow isolated updates
Still allow isolated updates of parameters
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/api/share20ocs.php8
-rw-r--r--apps/files_sharing/tests/api/share20ocstest.php128
2 files changed, 125 insertions, 11 deletions
diff --git a/apps/files_sharing/api/share20ocs.php b/apps/files_sharing/api/share20ocs.php
index d49ef7ad45f..48aca9b9c1b 100644
--- a/apps/files_sharing/api/share20ocs.php
+++ b/apps/files_sharing/api/share20ocs.php
@@ -456,9 +456,9 @@ class Share20OCS {
}
$permissions = $this->request->getParam('permissions', null);
- $password = $this->request->getParam('password', '');
+ $password = $this->request->getParam('password', null);
$publicUpload = $this->request->getParam('publicUpload', null);
- $expireDate = $this->request->getParam('expireDate', '');
+ $expireDate = $this->request->getParam('expireDate', null);
/*
* expirationdate, password and publicUpload only make sense for link shares
@@ -470,7 +470,7 @@ class Share20OCS {
if ($expireDate === '') {
$share->setExpirationDate(null);
- } else {
+ } else if ($expireDate !== null) {
try {
$expireDate = $this->parseDate($expireDate);
} catch (\Exception $e) {
@@ -481,7 +481,7 @@ class Share20OCS {
if ($password === '') {
$share->setPassword(null);
- } else {
+ } else if ($password !== null) {
$share->setPassword($password);
}
diff --git a/apps/files_sharing/tests/api/share20ocstest.php b/apps/files_sharing/tests/api/share20ocstest.php
index ce21e9675e2..b440ba96e04 100644
--- a/apps/files_sharing/tests/api/share20ocstest.php
+++ b/apps/files_sharing/tests/api/share20ocstest.php
@@ -990,8 +990,8 @@ class Share20OCSTest extends \Test\TestCase {
->method('getParam')
->will($this->returnValueMap([
['publicUpload', null, 'false'],
- ['expireDate', '', ''],
- ['password', '', ''],
+ ['expireDate', null, ''],
+ ['password', null, ''],
]));
$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
@@ -1026,8 +1026,8 @@ class Share20OCSTest extends \Test\TestCase {
->method('getParam')
->will($this->returnValueMap([
['publicUpload', null, 'true'],
- ['expireDate', '', '2000-01-01'],
- ['password', '', 'password'],
+ ['expireDate', null, '2000-01-01'],
+ ['password', null, 'password'],
]));
$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
@@ -1066,8 +1066,8 @@ class Share20OCSTest extends \Test\TestCase {
->method('getParam')
->will($this->returnValueMap([
['publicUpload', null, 'true'],
- ['expireDate', '', '2000-01-a'],
- ['password', '', 'password'],
+ ['expireDate', null, '2000-01-a'],
+ ['password', null, 'password'],
]));
$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
@@ -1095,7 +1095,7 @@ class Share20OCSTest extends \Test\TestCase {
->method('getParam')
->will($this->returnValueMap([
['publicUpload', null, 'true'],
- ['expireDate', '', ''],
+ ['expireDate', '', null],
['password', '', 'password'],
]));
@@ -1138,6 +1138,120 @@ class Share20OCSTest extends \Test\TestCase {
$this->assertEquals($expected->getData(), $result->getData());
}
+ public function testUpdateLinkSharePasswordDoesNotChangeOther() {
+ $ocs = $this->mockFormatShare();
+
+ $date = new \DateTime('2000-01-01');
+ $date->setTime(0,0,0);
+
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setPermissions(\OCP\Constants::PERMISSION_ALL)
+ ->setSharedBy($this->currentUser)
+ ->setShareType(\OCP\Share::SHARE_TYPE_LINK)
+ ->setPassword('password')
+ ->setExpirationDate($date)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+
+ $this->request
+ ->method('getParam')
+ ->will($this->returnValueMap([
+ ['password', null, 'newpassword'],
+ ]));
+
+ $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
+
+ $this->shareManager->expects($this->once())->method('updateShare')->with(
+ $this->callback(function (IShare $share) use ($date) {
+ return $share->getPermissions() === \OCP\Constants::PERMISSION_ALL &&
+ $share->getPassword() === 'newpassword' &&
+ $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 testUpdateLinkShareExpireDateDoesNotChangeOther() {
+ $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([
+ ['expireDate', null, '2010-12-23'],
+ ]));
+
+ $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
+
+ $this->shareManager->expects($this->once())->method('updateShare')->with(
+ $this->callback(function (IShare $share) {
+ $date = new \DateTime('2010-12-23');
+ $date->setTime(0,0,0);
+
+ return $share->getPermissions() === \OCP\Constants::PERMISSION_ALL &&
+ $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 testUpdateLinkSharePublicUploadDoesNotChangeOther() {
+ $ocs = $this->mockFormatShare();
+
+ $date = new \DateTime('2000-01-01');
+
+ $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)
+ ->setPassword('password')
+ ->setExpirationDate($date)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL)
+ ->setPath($folder);
+
+ $this->request
+ ->method('getParam')
+ ->will($this->returnValueMap([
+ ['publicUpload', null, 'true'],
+ ]));
+
+ $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) use ($date) {
+ 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 testUpdateOtherPermissions() {
$ocs = $this->mockFormatShare();