@@ -1189,13 +1189,17 @@ public function testUpdateNoParametersOther() {
11891189 public function testUpdateLinkShareClear () {
11901190 $ ocs = $ this ->mockFormatShare ();
11911191
1192+ $ node = $ this ->getMockBuilder ('OCP\Files\Folder ' )
1193+ ->getMock ();
1194+
11921195 $ share = \OC ::$ server ->getShareManager ()->newShare ();
11931196 $ share ->setPermissions (\OCP \Constants::PERMISSION_ALL )
11941197 ->setSharedBy ($ this ->currentUser ->getUID ())
11951198 ->setShareType (\OCP \Share::SHARE_TYPE_LINK )
11961199 ->setPassword ('password ' )
11971200 ->setExpirationDate (new \DateTime ())
1198- ->setPermissions (\OCP \Constants::PERMISSION_ALL );
1201+ ->setPermissions (\OCP \Constants::PERMISSION_ALL )
1202+ ->setNode ($ node );
11991203
12001204 $ this ->request
12011205 ->method ('getParam ' )
@@ -1207,6 +1211,9 @@ public function testUpdateLinkShareClear() {
12071211
12081212 $ this ->shareManager ->method ('getShareById ' )->with ('ocinternal:42 ' )->willReturn ($ share );
12091213
1214+ $ this ->shareManager ->method ('getSharedWith ' )
1215+ ->willReturn ([]);
1216+
12101217 $ this ->shareManager ->expects ($ this ->once ())->method ('updateShare ' )->with (
12111218 $ this ->callback (function (\OCP \Share \IShare $ share ) {
12121219 return $ share ->getPermissions () === \OCP \Constants::PERMISSION_READ &&
@@ -1244,6 +1251,9 @@ public function testUpdateLinkShareSet() {
12441251 $ this ->shareManager ->method ('getShareById ' )->with ('ocinternal:42 ' )->willReturn ($ share );
12451252 $ this ->shareManager ->method ('shareApiLinkAllowPublicUpload ' )->willReturn (true );
12461253
1254+ $ this ->shareManager ->method ('getSharedWith ' )
1255+ ->willReturn ([]);
1256+
12471257 $ this ->shareManager ->expects ($ this ->once ())->method ('updateShare ' )->with (
12481258 $ this ->callback (function (\OCP \Share \IShare $ share ) {
12491259 $ date = new \DateTime ('2000-01-01 ' );
@@ -1284,6 +1294,9 @@ public function testUpdateLinkShareInvalidDate() {
12841294 $ this ->shareManager ->method ('getShareById ' )->with ('ocinternal:42 ' )->willReturn ($ share );
12851295 $ this ->shareManager ->method ('shareApiLinkAllowPublicUpload ' )->willReturn (true );
12861296
1297+ $ this ->shareManager ->method ('getSharedWith ' )
1298+ ->willReturn ([]);
1299+
12871300 $ expected = new \OC_OCS_Result (null , 400 , 'Invalid date. Format must be YYYY-MM-DD ' );
12881301 $ result = $ ocs ->updateShare (42 );
12891302
@@ -1448,6 +1461,9 @@ public function testUpdateLinkSharePublicUploadDoesNotChangeOther() {
14481461 $ this ->shareManager ->method ('getShareById ' )->with ('ocinternal:42 ' )->willReturn ($ share );
14491462 $ this ->shareManager ->method ('shareApiLinkAllowPublicUpload ' )->willReturn (true );
14501463
1464+ $ this ->shareManager ->method ('getSharedWith ' )
1465+ ->willReturn ([]);
1466+
14511467 $ this ->shareManager ->expects ($ this ->once ())->method ('updateShare ' )->with (
14521468 $ this ->callback (function (\OCP \Share \IShare $ share ) use ($ date ) {
14531469 return $ share ->getPermissions () === \OCP \Constants::PERMISSION_READ | \OCP \Constants::PERMISSION_CREATE | \OCP \Constants::PERMISSION_DELETE &&
@@ -1625,6 +1641,48 @@ public function testUpdateShareCannotIncreasePermissions() {
16251641 $ this ->assertEquals ($ expected ->getData (), $ result ->getData ());
16261642 }
16271643
1644+ public function testUpdateShareCannotIncreasePermissionsLinkShare () {
1645+ $ ocs = $ this ->mockFormatShare ();
1646+ $ folder = $ this ->createMock ('OCP\Files\Folder ' );
1647+ $ share = \OC ::$ server ->getShareManager ()->newShare ();
1648+ $ share
1649+ ->setId (42 )
1650+ ->setSharedBy ($ this ->currentUser ->getUID ())
1651+ ->setShareOwner ('anotheruser ' )
1652+ ->setShareType (\OCP \Share::SHARE_TYPE_LINK )
1653+ ->setPermissions (\OCP \Constants::PERMISSION_READ )
1654+ ->setNode ($ folder );
1655+ // note: updateShare will modify the received instance but getSharedWith will reread from the database,
1656+ // so their values will be different
1657+ $ incomingShare = \OC ::$ server ->getShareManager ()->newShare ();
1658+ $ incomingShare
1659+ ->setId (42 )
1660+ ->setSharedBy ($ this ->currentUser ->getUID ())
1661+ ->setShareOwner ('anotheruser ' )
1662+ ->setShareType (\OCP \Share::SHARE_TYPE_USER )
1663+ ->setSharedWith ('currentUser ' )
1664+ ->setPermissions (\OCP \Constants::PERMISSION_READ )
1665+ ->setNode ($ folder );
1666+ $ this ->shareManager ->method ('getShareById ' )->with ('ocinternal:42 ' )->willReturn ($ share );
1667+ $ this ->shareManager ->expects ($ this ->any ())
1668+ ->method ('getSharedWith ' )
1669+ ->will ($ this ->returnValueMap ([
1670+ ['currentUser ' , \OCP \Share::SHARE_TYPE_USER , $ share ->getNode (), -1 , 0 , [$ incomingShare ]],
1671+ ['currentUser ' , \OCP \Share::SHARE_TYPE_GROUP , $ share ->getNode (), -1 , 0 , []]
1672+ ]));
1673+ $ this ->shareManager ->expects ($ this ->never ())->method ('updateShare ' );
1674+ $ this ->shareManager ->method ('shareApiLinkAllowPublicUpload ' )->willReturn (true );
1675+ $ this ->request
1676+ ->method ('getParam ' )
1677+ ->will ($ this ->returnValueMap ([
1678+ ['publicUpload ' , null , 'true ' ],
1679+ ]));
1680+ $ expected = new \OC_OCS_Result (null , 404 , 'Cannot increase permissions ' );
1681+ $ result = $ ocs ->updateShare (42 );
1682+ $ this ->assertEquals ($ expected ->getMeta (), $ result ->getMeta ());
1683+ $ this ->assertEquals ($ expected ->getData (), $ result ->getData ());
1684+ }
1685+
16281686 public function testUpdateShareCanIncreasePermissionsIfOwner () {
16291687 $ ocs = $ this ->mockFormatShare ();
16301688
0 commit comments