@@ -1334,6 +1334,9 @@ public function testUpdateLinkShareClear() {
13341334 })
13351335 )->will ($ this ->returnArgument (0 ));
13361336
1337+ $ this ->shareManager ->method ('getSharedWith ' )
1338+ ->willReturn ([]);
1339+
13371340 $ expected = new \OC_OCS_Result (null );
13381341 $ result = $ ocs ->updateShare (42 );
13391342
@@ -1374,6 +1377,9 @@ public function testUpdateLinkShareSet() {
13741377 })
13751378 )->will ($ this ->returnArgument (0 ));
13761379
1380+ $ this ->shareManager ->method ('getSharedWith ' )
1381+ ->willReturn ([]);
1382+
13771383 $ expected = new \OC_OCS_Result (null );
13781384 $ result = $ ocs ->updateShare (42 );
13791385
@@ -1650,6 +1656,9 @@ public function testUpdateLinkSharePublicUploadDoesNotChangeOther() {
16501656 })
16511657 )->will ($ this ->returnArgument (0 ));
16521658
1659+ $ this ->shareManager ->method ('getSharedWith ' )
1660+ ->willReturn ([]);
1661+
16531662 $ expected = new \OC_OCS_Result (null );
16541663 $ result = $ ocs ->updateShare (42 );
16551664
@@ -1819,6 +1828,51 @@ public function testUpdateShareCannotIncreasePermissions() {
18191828 $ this ->assertEquals ($ expected ->getData (), $ result ->getData ());
18201829 }
18211830
1831+ public function testUpdateShareCannotIncreasePermissionsLinkShare () {
1832+ $ ocs = $ this ->mockFormatShare ();
1833+ $ folder = $ this ->createMock ('OCP\Files\Folder ' );
1834+ $ share = \OC ::$ server ->getShareManager ()->newShare ();
1835+ $ share
1836+ ->setId (42 )
1837+ ->setSharedBy ($ this ->currentUser ->getUID ())
1838+ ->setShareOwner ('anotheruser ' )
1839+ ->setShareType (\OCP \Share::SHARE_TYPE_LINK )
1840+ ->setPermissions (\OCP \Constants::PERMISSION_READ )
1841+ ->setNode ($ folder );
1842+ // note: updateShare will modify the received instance but getSharedWith will reread from the database,
1843+ // so their values will be different
1844+ $ incomingShare = \OC ::$ server ->getShareManager ()->newShare ();
1845+ $ incomingShare
1846+ ->setId (42 )
1847+ ->setSharedBy ($ this ->currentUser ->getUID ())
1848+ ->setShareOwner ('anotheruser ' )
1849+ ->setShareType (\OCP \Share::SHARE_TYPE_USER )
1850+ ->setSharedWith ('currentUser ' )
1851+ ->setPermissions (\OCP \Constants::PERMISSION_READ )
1852+ ->setNode ($ folder );
1853+ $ this ->shareManager ->method ('getShareById ' )->with ('ocinternal:42 ' )->willReturn ($ share );
1854+ $ this ->shareManager ->expects ($ this ->any ())
1855+ ->method ('getSharedWith ' )
1856+ ->will ($ this ->returnValueMap ([
1857+ ['currentUser ' , \OCP \Share::SHARE_TYPE_USER , $ share ->getNode (), -1 , 0 , [$ incomingShare ]],
1858+ ['currentUser ' , \OCP \Share::SHARE_TYPE_GROUP , $ share ->getNode (), -1 , 0 , []]
1859+ ]));
1860+ $ this ->shareManager ->expects ($ this ->never ())->method ('updateShare ' );
1861+ $ this ->shareManager ->method ('shareApiLinkAllowPublicUpload ' )->willReturn (true );
1862+
1863+ $ this ->request
1864+ ->method ('getParam ' )
1865+ ->will ($ this ->returnValueMap ([
1866+ ['publicUpload ' , null , 'true ' ],
1867+ ]));
1868+
1869+ $ expected = new \OC_OCS_Result (null , 404 , 'Cannot increase permissions ' );
1870+ $ result = $ ocs ->updateShare (42 );
1871+
1872+ $ this ->assertEquals ($ expected ->getMeta (), $ result ->getMeta ());
1873+ $ this ->assertEquals ($ expected ->getData (), $ result ->getData ());
1874+ }
1875+
18221876 public function testUpdateShareCanIncreasePermissionsIfOwner () {
18231877 $ ocs = $ this ->mockFormatShare ();
18241878
0 commit comments