@@ -65,21 +65,26 @@ class PrincipalTest extends TestCase {
6565 /** @var ProxyMapper | \PHPUnit_Framework_MockObject_MockObject */
6666 private $ proxyMapper ;
6767
68+ /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
69+ private $ config ;
70+
6871 protected function setUp (): void {
6972 $ this ->userManager = $ this ->createMock (IUserManager::class);
7073 $ this ->groupManager = $ this ->createMock (IGroupManager::class);
7174 $ this ->shareManager = $ this ->createMock (IManager::class);
7275 $ this ->userSession = $ this ->createMock (IUserSession::class);
7376 $ this ->appManager = $ this ->createMock (IAppManager::class);
7477 $ this ->proxyMapper = $ this ->createMock (ProxyMapper::class);
78+ $ this ->config = $ this ->createMock (IConfig::class);
7579
7680 $ this ->connector = new \OCA \DAV \Connector \Sabre \Principal (
7781 $ this ->userManager ,
7882 $ this ->groupManager ,
7983 $ this ->shareManager ,
8084 $ this ->userSession ,
8185 $ this ->appManager ,
82- $ this ->proxyMapper
86+ $ this ->proxyMapper ,
87+ $ this ->config
8388 );
8489 parent ::setUp ();
8590 }
@@ -209,7 +214,7 @@ public function testGetGroupMemberSet() {
209214 $ this ->assertSame ([], $ response );
210215 }
211216
212-
217+
213218 public function testGetGroupMemberSetEmpty () {
214219 $ this ->expectException (\Sabre \DAV \Exception::class);
215220 $ this ->expectExceptionMessage ('Principal not found ' );
@@ -334,7 +339,7 @@ public function testGetGroupMembership() {
334339 $ this ->assertSame ($ expectedResponse , $ response );
335340 }
336341
337-
342+
338343 public function testGetGroupMembershipEmpty () {
339344 $ this ->expectException (\Sabre \DAV \Exception::class);
340345 $ this ->expectExceptionMessage ('Principal not found ' );
@@ -348,7 +353,7 @@ public function testGetGroupMembershipEmpty() {
348353 $ this ->connector ->getGroupMembership ('principals/users/foo ' );
349354 }
350355
351-
356+
352357 public function testSetGroupMembership () {
353358 $ this ->expectException (\Sabre \DAV \Exception::class);
354359 $ this ->expectExceptionMessage ('Setting members of the group is not supported yet ' );
@@ -403,11 +408,6 @@ public function testSetGroupMembershipProxy() {
403408 $ this ->connector ->setGroupMemberSet ('principals/users/foo/calendar-proxy-write ' , ['principals/users/bar ' ]);
404409 }
405410
406-
407-
408-
409-
410-
411411 public function testUpdatePrincipal () {
412412 $ this ->assertSame (0 , $ this ->connector ->updatePrincipal ('foo ' , new PropPatch (array ())));
413413 }
@@ -430,6 +430,11 @@ public function testSearchPrincipals($sharingEnabled, $groupsOnly, $test, $resul
430430 ->will ($ this ->returnValue ($ sharingEnabled ));
431431
432432 if ($ sharingEnabled ) {
433+ $ this ->config ->expects ($ this ->once ())
434+ ->method ('getAppValue ' )
435+ ->with ('core ' , 'shareapi_allow_share_dialog_user_enumeration ' , 'yes ' )
436+ ->willReturn ('yes ' );
437+
433438 $ this ->shareManager ->expects ($ this ->once ())
434439 ->method ('shareWithGroupMembersOnly ' )
435440 ->will ($ this ->returnValue ($ groupsOnly ));
@@ -446,6 +451,8 @@ public function testSearchPrincipals($sharingEnabled, $groupsOnly, $test, $resul
446451 ->will ($ this ->returnValue (['group1 ' , 'group2 ' , 'group5 ' ]));
447452 }
448453 } else {
454+ $ this ->config ->expects ($ this ->never ())
455+ ->method ('getAppValue ' );
449456 $ this ->shareManager ->expects ($ this ->never ())
450457 ->method ('shareWithGroupMembersOnly ' );
451458 $ this ->groupManager ->expects ($ this ->never ())
@@ -518,6 +525,11 @@ public function testSearchPrincipalByCalendarUserAddressSet() {
518525 ->method ('shareAPIEnabled ' )
519526 ->will ($ this ->returnValue (true ));
520527
528+ $ this ->config ->expects ($ this ->exactly (2 ))
529+ ->method ('getAppValue ' )
530+ ->with ('core ' , 'shareapi_allow_share_dialog_user_enumeration ' , 'yes ' )
531+ ->willReturn ('yes ' );
532+
521533 $ this ->shareManager ->expects ($ this ->exactly (2 ))
522534 ->method ('shareWithGroupMembersOnly ' )
523535 ->will ($ this ->returnValue (false ));
@@ -539,6 +551,78 @@ public function testSearchPrincipalByCalendarUserAddressSet() {
539551 [
'{urn:ietf:params:xml:ns:caldav}calendar-user-address-set ' =>
'[email protected] ' ]));
540552 }
541553
554+ public function testSearchPrincipalWithEnumerationDisabledDisplayname () {
555+ $ this ->shareManager ->expects ($ this ->once ())
556+ ->method ('shareAPIEnabled ' )
557+ ->will ($ this ->returnValue (true ));
558+
559+ $ this ->config ->expects ($ this ->once ())
560+ ->method ('getAppValue ' )
561+ ->with ('core ' , 'shareapi_allow_share_dialog_user_enumeration ' , 'yes ' )
562+ ->willReturn ('no ' );
563+
564+ $ this ->shareManager ->expects ($ this ->once ())
565+ ->method ('shareWithGroupMembersOnly ' )
566+ ->will ($ this ->returnValue (false ));
567+
568+ $ user2 = $ this ->createMock (IUser::class);
569+ $ user2 ->method ('getUID ' )->will ($ this ->returnValue ('user2 ' ));
570+ $ user2 ->method ('getDisplayName ' )->will ($ this ->returnValue ('User 2 ' ));
571+ $ user2->
method (
'getEMailAddress ' )->
will (
$ this ->
returnValue (
'[email protected] ' ));
572+ $ user3 = $ this ->createMock (IUser::class);
573+ $ user3 ->method ('getUID ' )->will ($ this ->returnValue ('user3 ' ));
574+ $ user2 ->method ('getDisplayName ' )->will ($ this ->returnValue ('User 22 ' ));
575+ $ user2->
method (
'getEMailAddress ' )->
will (
$ this ->
returnValue (
'[email protected] ' ));
576+ $ user4 = $ this ->createMock (IUser::class);
577+ $ user4 ->method ('getUID ' )->will ($ this ->returnValue ('user4 ' ));
578+ $ user2 ->method ('getDisplayName ' )->will ($ this ->returnValue ('User 222 ' ));
579+ $ user2->
method (
'getEMailAddress ' )->
will (
$ this ->
returnValue (
'[email protected] ' ));
580+
581+ $ this ->userManager ->expects ($ this ->at (0 ))
582+ ->method ('searchDisplayName ' )
583+ ->with ('User 2 ' )
584+ ->will ($ this ->returnValue ([$ user2 , $ user3 , $ user4 ]));
585+
586+ $ this ->assertEquals (['principals/users/user2 ' ], $ this ->connector ->searchPrincipals ('principals/users ' ,
587+ ['{DAV:}displayname ' => 'User 2 ' ]));
588+ }
589+
590+ public function testSearchPrincipalWithEnumerationDisabledEmail () {
591+ $ this ->shareManager ->expects ($ this ->once ())
592+ ->method ('shareAPIEnabled ' )
593+ ->will ($ this ->returnValue (true ));
594+
595+ $ this ->config ->expects ($ this ->once ())
596+ ->method ('getAppValue ' )
597+ ->with ('core ' , 'shareapi_allow_share_dialog_user_enumeration ' , 'yes ' )
598+ ->willReturn ('no ' );
599+
600+ $ this ->shareManager ->expects ($ this ->once ())
601+ ->method ('shareWithGroupMembersOnly ' )
602+ ->will ($ this ->returnValue (false ));
603+
604+ $ user2 = $ this ->createMock (IUser::class);
605+ $ user2 ->method ('getUID ' )->will ($ this ->returnValue ('user2 ' ));
606+ $ user2 ->method ('getDisplayName ' )->will ($ this ->returnValue ('User 2 ' ));
607+ $ user2->
method (
'getEMailAddress ' )->
will (
$ this ->
returnValue (
'[email protected] ' ));
608+ $ user3 = $ this ->createMock (IUser::class);
609+ $ user3 ->method ('getUID ' )->will ($ this ->returnValue ('user3 ' ));
610+ $ user2 ->method ('getDisplayName ' )->will ($ this ->returnValue ('User 22 ' ));
611+ $ user2->
method (
'getEMailAddress ' )->
will (
$ this ->
returnValue (
'[email protected] ' ));
612+ $ user4 = $ this ->createMock (IUser::class);
613+ $ user4 ->method ('getUID ' )->will ($ this ->returnValue ('user4 ' ));
614+ $ user2 ->method ('getDisplayName ' )->will ($ this ->returnValue ('User 222 ' ));
615+ $ user2->
method (
'getEMailAddress ' )->
will (
$ this ->
returnValue (
'[email protected] ' ));
616+
617+ $ this ->userManager ->expects ($ this ->at (0 ))
618+ ->method ('getByEmail ' )
619+ 620+ ->will ($ this ->returnValue ([$ user2 , $ user3 , $ user4 ]));
621+
622+ $ this ->assertEquals (['principals/users/user2 ' ], $ this ->connector ->searchPrincipals ('principals/users ' ,
623+ [
'{http://sabredav.org/ns}email-address ' =>
'[email protected] ' ]));
624+ }
625+
542626 public function testFindByUriSharingApiDisabled () {
543627 $ this ->shareManager ->expects ($ this ->once ())
544628 ->method ('shareApiEnabled ' )
0 commit comments