@@ -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	public  function  setUp () {
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	}
@@ -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 '  => 'user@example.com ' ]));
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+ 		$ user2method ('getUID ' )->will ($ this returnValue ('user2 ' ));
570+ 		$ user2method ('getDisplayName ' )->will ($ this returnValue ('User 2 ' ));
571+ 		$ user2method ('getEMailAddress ' )->will ($ this returnValue ('user2@foo.bar ' ));
572+ 		$ user3$ this createMock (IUser::class);
573+ 		$ user3method ('getUID ' )->will ($ this returnValue ('user3 ' ));
574+ 		$ user2method ('getDisplayName ' )->will ($ this returnValue ('User 22 ' ));
575+ 		$ user2method ('getEMailAddress ' )->will ($ this returnValue ('user2@foo.bar123 ' ));
576+ 		$ user4$ this createMock (IUser::class);
577+ 		$ user4method ('getUID ' )->will ($ this returnValue ('user4 ' ));
578+ 		$ user2method ('getDisplayName ' )->will ($ this returnValue ('User 222 ' ));
579+ 		$ user2method ('getEMailAddress ' )->will ($ this returnValue ('user2@foo.bar456 ' ));
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+ 		$ user2method ('getUID ' )->will ($ this returnValue ('user2 ' ));
606+ 		$ user2method ('getDisplayName ' )->will ($ this returnValue ('User 2 ' ));
607+ 		$ user2method ('getEMailAddress ' )->will ($ this returnValue ('user2@foo.bar ' ));
608+ 		$ user3$ this createMock (IUser::class);
609+ 		$ user3method ('getUID ' )->will ($ this returnValue ('user3 ' ));
610+ 		$ user2method ('getDisplayName ' )->will ($ this returnValue ('User 22 ' ));
611+ 		$ user2method ('getEMailAddress ' )->will ($ this returnValue ('user2@foo.bar123 ' ));
612+ 		$ user4$ this createMock (IUser::class);
613+ 		$ user4method ('getUID ' )->will ($ this returnValue ('user4 ' ));
614+ 		$ user2method ('getDisplayName ' )->will ($ this returnValue ('User 222 ' ));
615+ 		$ user2method ('getEMailAddress ' )->will ($ this returnValue ('user2@foo.bar456 ' ));
616+ 
617+ 		$ this userManager ->expects ($ this at (0 ))
618+ 			->method ('getByEmail ' )
619+ 			->with ('user2@foo.bar ' )
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 '  => 'user2@foo.bar ' ]));
624+ 	}
625+ 
542626	public  function  testFindByUriSharingApiDisabled () {
543627		$ this shareManager ->expects ($ this once ())
544628			->method ('shareApiEnabled ' )
0 commit comments