@@ -3325,21 +3325,29 @@ public function testGetShareByTokenWithPublicLinksDisabled(): void {
33253325
33263326 public function testGetShareByTokenPublicUploadDisabled (): void {
33273327 $ this ->config
3328- ->expects ($ this ->exactly (3 ))
3328+ ->expects ($ this ->exactly (5 ))
33293329 ->method ('getAppValue ' )
33303330 ->willReturnMap ([
33313331 ['core ' , 'shareapi_allow_links ' , 'yes ' , 'yes ' ],
33323332 ['core ' , 'shareapi_allow_public_upload ' , 'yes ' , 'no ' ],
33333333 ['files_sharing ' , 'hide_disabled_user_shares ' , 'no ' , 'no ' ],
3334+ ['core ' , 'shareapi_allow_links_exclude_groups ' , '[] ' , '[] ' ],
33343335 ]);
33353336
33363337 $ share = $ this ->manager ->newShare ();
33373338 $ share ->setShareType (IShare::TYPE_LINK )
33383339 ->setPermissions (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE );
33393340 $ share ->setSharedWith ('sharedWith ' );
3341+ $ share ->setShareOwner ('shareOwner ' );
33403342 $ folder = $ this ->createMock (\OC \Files \Node \Folder::class);
33413343 $ share ->setNode ($ folder );
33423344
3345+ $ shareOwner = $ this ->createMock (IUser::class);
3346+ $ this ->userManager ->expects ($ this ->once ())
3347+ ->method ('get ' )
3348+ ->with ('shareOwner ' )
3349+ ->willReturn ($ shareOwner );
3350+
33433351 $ this ->defaultProvider ->expects ($ this ->once ())
33443352 ->method ('getShareByToken ' )
33453353 ->willReturn ('validToken ' )
@@ -3350,6 +3358,87 @@ public function testGetShareByTokenPublicUploadDisabled(): void {
33503358 $ this ->assertSame (Constants::PERMISSION_READ , $ res ->getPermissions ());
33513359 }
33523360
3361+ public function testGetShareByTokenShareOwnerExcludedFromLinkShares (): void {
3362+ $ this ->expectException (ShareNotFound::class);
3363+ $ this ->expectExceptionMessage ('The requested share does not exist anymore ' );
3364+
3365+ $ this ->config
3366+ ->expects ($ this ->exactly (4 ))
3367+ ->method ('getAppValue ' )
3368+ ->willReturnMap ([
3369+ ['core ' , 'shareapi_allow_links ' , 'yes ' , 'yes ' ],
3370+ ['files_sharing ' , 'hide_disabled_user_shares ' , 'no ' , 'no ' ],
3371+ ['core ' , 'shareapi_allow_links_exclude_groups ' , '[] ' , '["excludedGroup"] ' ],
3372+ ]);
3373+
3374+ $ this ->l ->expects ($ this ->once ())
3375+ ->method ('t ' )
3376+ ->willReturnArgument (0 );
3377+
3378+ $ share = $ this ->manager ->newShare ();
3379+ $ share ->setShareType (IShare::TYPE_LINK )
3380+ ->setPermissions (Constants::PERMISSION_READ );
3381+ $ share ->setShareOwner ('shareOwner ' );
3382+ $ file = $ this ->createMock (File::class);
3383+ $ share ->setNode ($ file );
3384+
3385+ $ shareOwner = $ this ->createMock (IUser::class);
3386+ $ this ->userManager ->expects ($ this ->once ())
3387+ ->method ('get ' )
3388+ ->with ('shareOwner ' )
3389+ ->willReturn ($ shareOwner );
3390+
3391+ $ this ->groupManager ->expects ($ this ->once ())
3392+ ->method ('getUserGroupIds ' )
3393+ ->with ($ shareOwner )
3394+ ->willReturn (['excludedGroup ' , 'otherGroup ' ]);
3395+
3396+ $ this ->defaultProvider ->expects ($ this ->once ())
3397+ ->method ('getShareByToken ' )
3398+ ->with ('token ' )
3399+ ->willReturn ($ share );
3400+
3401+ $ this ->manager ->getShareByToken ('token ' );
3402+ }
3403+
3404+ public function testGetShareByTokenShareOwnerNotExcludedFromLinkShares (): void {
3405+ $ this ->config
3406+ ->expects ($ this ->exactly (4 ))
3407+ ->method ('getAppValue ' )
3408+ ->willReturnMap ([
3409+ ['core ' , 'shareapi_allow_links ' , 'yes ' , 'yes ' ],
3410+ ['files_sharing ' , 'hide_disabled_user_shares ' , 'no ' , 'no ' ],
3411+ ['core ' , 'shareapi_allow_links_exclude_groups ' , '[] ' , '["excludedGroup"] ' ],
3412+ ]);
3413+
3414+ $ share = $ this ->manager ->newShare ();
3415+ $ share ->setShareType (IShare::TYPE_LINK )
3416+ ->setPermissions (Constants::PERMISSION_READ );
3417+ $ share ->setShareOwner ('shareOwner ' );
3418+ $ file = $ this ->createMock (File::class);
3419+ $ share ->setNode ($ file );
3420+
3421+ $ shareOwner = $ this ->createMock (IUser::class);
3422+ $ this ->userManager ->expects ($ this ->once ())
3423+ ->method ('get ' )
3424+ ->with ('shareOwner ' )
3425+ ->willReturn ($ shareOwner );
3426+
3427+ $ this ->groupManager ->expects ($ this ->once ())
3428+ ->method ('getUserGroupIds ' )
3429+ ->with ($ shareOwner )
3430+ ->willReturn (['allowedGroup ' , 'otherGroup ' ]);
3431+
3432+ $ this ->defaultProvider ->expects ($ this ->once ())
3433+ ->method ('getShareByToken ' )
3434+ ->with ('token ' )
3435+ ->willReturn ($ share );
3436+
3437+ $ res = $ this ->manager ->getShareByToken ('token ' );
3438+
3439+ $ this ->assertSame ($ share , $ res );
3440+ }
3441+
33533442 public function testCheckPasswordNoLinkShare (): void {
33543443 $ share = $ this ->createMock (IShare::class);
33553444 $ share ->method ('getShareType ' )->willReturn (IShare::TYPE_USER );
0 commit comments