@@ -3227,21 +3227,29 @@ public function testGetShareByTokenWithPublicLinksDisabled() {
32273227
32283228 public function testGetShareByTokenPublicUploadDisabled () {
32293229 $ this ->config
3230- ->expects ($ this ->exactly (3 ))
3230+ ->expects ($ this ->exactly (5 ))
32313231 ->method ('getAppValue ' )
32323232 ->willReturnMap ([
32333233 ['core ' , 'shareapi_allow_links ' , 'yes ' , 'yes ' ],
32343234 ['core ' , 'shareapi_allow_public_upload ' , 'yes ' , 'no ' ],
32353235 ['files_sharing ' , 'hide_disabled_user_shares ' , 'no ' , 'no ' ],
3236+ ['core ' , 'shareapi_allow_links_exclude_groups ' , '[] ' , '[] ' ],
32363237 ]);
32373238
32383239 $ share = $ this ->manager ->newShare ();
32393240 $ share ->setShareType (IShare::TYPE_LINK )
32403241 ->setPermissions (\OCP \Constants::PERMISSION_READ | \OCP \Constants::PERMISSION_CREATE | \OCP \Constants::PERMISSION_UPDATE );
32413242 $ share ->setSharedWith ('sharedWith ' );
3243+ $ share ->setShareOwner ('shareOwner ' );
32423244 $ folder = $ this ->createMock (\OC \Files \Node \Folder::class);
32433245 $ share ->setNode ($ folder );
32443246
3247+ $ shareOwner = $ this ->createMock (IUser::class);
3248+ $ this ->userManager ->expects ($ this ->once ())
3249+ ->method ('get ' )
3250+ ->with ('shareOwner ' )
3251+ ->willReturn ($ shareOwner );
3252+
32453253 $ this ->defaultProvider ->expects ($ this ->once ())
32463254 ->method ('getShareByToken ' )
32473255 ->willReturn ('validToken ' )
@@ -3252,6 +3260,87 @@ public function testGetShareByTokenPublicUploadDisabled() {
32523260 $ this ->assertSame (\OCP \Constants::PERMISSION_READ , $ res ->getPermissions ());
32533261 }
32543262
3263+ public function testGetShareByTokenShareOwnerExcludedFromLinkShares (): void {
3264+ $ this ->expectException (ShareNotFound::class);
3265+ $ this ->expectExceptionMessage ('The requested share does not exist anymore ' );
3266+
3267+ $ this ->config
3268+ ->expects ($ this ->exactly (4 ))
3269+ ->method ('getAppValue ' )
3270+ ->willReturnMap ([
3271+ ['core ' , 'shareapi_allow_links ' , 'yes ' , 'yes ' ],
3272+ ['files_sharing ' , 'hide_disabled_user_shares ' , 'no ' , 'no ' ],
3273+ ['core ' , 'shareapi_allow_links_exclude_groups ' , '[] ' , '["excludedGroup"] ' ],
3274+ ]);
3275+
3276+ $ this ->l ->expects ($ this ->once ())
3277+ ->method ('t ' )
3278+ ->willReturnArgument (0 );
3279+
3280+ $ share = $ this ->manager ->newShare ();
3281+ $ share ->setShareType (IShare::TYPE_LINK )
3282+ ->setPermissions (\OCP \Constants::PERMISSION_READ );
3283+ $ share ->setShareOwner ('shareOwner ' );
3284+ $ file = $ this ->createMock (File::class);
3285+ $ share ->setNode ($ file );
3286+
3287+ $ shareOwner = $ this ->createMock (IUser::class);
3288+ $ this ->userManager ->expects ($ this ->once ())
3289+ ->method ('get ' )
3290+ ->with ('shareOwner ' )
3291+ ->willReturn ($ shareOwner );
3292+
3293+ $ this ->groupManager ->expects ($ this ->once ())
3294+ ->method ('getUserGroupIds ' )
3295+ ->with ($ shareOwner )
3296+ ->willReturn (['excludedGroup ' , 'otherGroup ' ]);
3297+
3298+ $ this ->defaultProvider ->expects ($ this ->once ())
3299+ ->method ('getShareByToken ' )
3300+ ->with ('token ' )
3301+ ->willReturn ($ share );
3302+
3303+ $ this ->manager ->getShareByToken ('token ' );
3304+ }
3305+
3306+ public function testGetShareByTokenShareOwnerNotExcludedFromLinkShares (): void {
3307+ $ this ->config
3308+ ->expects ($ this ->exactly (4 ))
3309+ ->method ('getAppValue ' )
3310+ ->willReturnMap ([
3311+ ['core ' , 'shareapi_allow_links ' , 'yes ' , 'yes ' ],
3312+ ['files_sharing ' , 'hide_disabled_user_shares ' , 'no ' , 'no ' ],
3313+ ['core ' , 'shareapi_allow_links_exclude_groups ' , '[] ' , '["excludedGroup"] ' ],
3314+ ]);
3315+
3316+ $ share = $ this ->manager ->newShare ();
3317+ $ share ->setShareType (IShare::TYPE_LINK )
3318+ ->setPermissions (\OCP \Constants::PERMISSION_READ );
3319+ $ share ->setShareOwner ('shareOwner ' );
3320+ $ file = $ this ->createMock (File::class);
3321+ $ share ->setNode ($ file );
3322+
3323+ $ shareOwner = $ this ->createMock (IUser::class);
3324+ $ this ->userManager ->expects ($ this ->once ())
3325+ ->method ('get ' )
3326+ ->with ('shareOwner ' )
3327+ ->willReturn ($ shareOwner );
3328+
3329+ $ this ->groupManager ->expects ($ this ->once ())
3330+ ->method ('getUserGroupIds ' )
3331+ ->with ($ shareOwner )
3332+ ->willReturn (['allowedGroup ' , 'otherGroup ' ]);
3333+
3334+ $ this ->defaultProvider ->expects ($ this ->once ())
3335+ ->method ('getShareByToken ' )
3336+ ->with ('token ' )
3337+ ->willReturn ($ share );
3338+
3339+ $ res = $ this ->manager ->getShareByToken ('token ' );
3340+
3341+ $ this ->assertSame ($ share , $ res );
3342+ }
3343+
32553344 public function testCheckPasswordNoLinkShare () {
32563345 $ share = $ this ->createMock (IShare::class);
32573346 $ share ->method ('getShareType ' )->willReturn (IShare::TYPE_USER );
0 commit comments