2626namespace OCA \User_LDAP \Tests ;
2727
2828use OC \User \Manager ;
29+ use OCA \User_LDAP \Access ;
30+ use OCA \User_LDAP \Connection ;
2931use OCA \User_LDAP \IGroupLDAP ;
3032use OCP \IConfig ;
3133use OCP \IServerContainer ;
@@ -337,24 +339,49 @@ public function testGetLDAPBaseUsersUserIDNotFound() {
337339 }
338340
339341 public function testGetLDAPBaseUsers () {
342+ $ bases = [
343+ 'ou=users,ou=foobar,dc=example,dc=org ' ,
344+ 'ou=users,ou=barfoo,dc=example,dc=org ' ,
345+ ];
346+ $ dn = 'uid=malik, ' . $ bases [1 ];
347+
348+ $ connection = $ this ->createMock (Connection::class);
349+ $ connection ->expects ($ this ->any ())
350+ ->method ('__get ' )
351+ ->willReturnCallback (function ($ key ) use ($ bases ) {
352+ switch ($ key ) {
353+ case 'ldapBaseUsers ' :
354+ return $ bases ;
355+ }
356+ return null ;
357+ });
358+
359+ $ access = $ this ->createMock (Access::class);
360+ $ access ->expects ($ this ->any ())
361+ ->method ('getConnection ' )
362+ ->willReturn ($ connection );
363+ $ access ->expects ($ this ->exactly (2 ))
364+ ->method ('isDNPartOfBase ' )
365+ ->willReturnOnConsecutiveCalls (false , true );
366+ $ access ->expects ($ this ->atLeastOnce ())
367+ ->method ('username2dn ' )
368+ ->willReturn ($ dn );
369+
340370 $ userBackend = $ this ->getMockBuilder ('OCA\User_LDAP\User_LDAP ' )
341371 ->setMethods (['userExists ' , 'getLDAPAccess ' , 'getConnection ' , 'getConfiguration ' ])
342372 ->disableOriginalConstructor ()
343373 ->getMock ();
344- $ userBackend ->expects ($ this ->at ( 0 ))
374+ $ userBackend ->expects ($ this ->atLeastOnce ( ))
345375 ->method ('userExists ' )
346376 ->willReturn (true );
347- $ userBackend ->expects ($ this ->at (3 ))
348- ->method ('getConfiguration ' )
349- ->willReturn (array ('ldap_base_users ' =>'ou=users,dc=example,dc=org ' ));
350377 $ userBackend ->expects ($ this ->any ())
351- ->method ($ this -> anything () )
352- -> willReturnSelf ( );
353-
378+ ->method (' getLDAPAccess ' )
379+ -> willReturn ( $ access );
380+
354381 $ server = $ this ->getServerMock ($ userBackend , $ this ->getDefaultGroupBackendMock ());
355382
356383 $ ldapProvider = $ this ->getLDAPProvider ($ server );
357- $ this ->assertEquals (' ou=users,dc=example,dc=org ' , $ ldapProvider ->getLDAPBaseUsers ('existing_user ' ));
384+ $ this ->assertEquals ($ bases [ 1 ] , $ ldapProvider ->getLDAPBaseUsers ('existing_user ' ));
358385 }
359386
360387 /**
@@ -375,24 +402,42 @@ public function testGetLDAPBaseGroupsUserIDNotFound() {
375402 }
376403
377404 public function testGetLDAPBaseGroups () {
405+ $ bases = [
406+ 'ou=groupd,ou=foobar,dc=example,dc=org ' ,
407+ 'ou=groups,ou=barfoo,dc=example,dc=org ' ,
408+ ];
409+
410+ $ connection = $ this ->createMock (Connection::class);
411+ $ connection ->expects ($ this ->any ())
412+ ->method ('__get ' )
413+ ->willReturnCallback (function ($ key ) use ($ bases ) {
414+ switch ($ key ) {
415+ case 'ldapBaseGroups ' :
416+ return $ bases ;
417+ }
418+ return null ;
419+ });
420+
421+ $ access = $ this ->createMock (Access::class);
422+ $ access ->expects ($ this ->any ())
423+ ->method ('getConnection ' )
424+ ->willReturn ($ connection );
425+
378426 $ userBackend = $ this ->getMockBuilder ('OCA\User_LDAP\User_LDAP ' )
379427 ->setMethods (['userExists ' , 'getLDAPAccess ' , 'getConnection ' , 'getConfiguration ' ])
380428 ->disableOriginalConstructor ()
381429 ->getMock ();
382- $ userBackend ->expects ($ this ->at ( 0 ))
430+ $ userBackend ->expects ($ this ->any ( ))
383431 ->method ('userExists ' )
384432 ->willReturn (true );
385- $ userBackend ->expects ($ this ->at (3 ))
386- ->method ('getConfiguration ' )
387- ->willReturn (array ('ldap_base_groups ' =>'ou=groups,dc=example,dc=org ' ));
388433 $ userBackend ->expects ($ this ->any ())
389- ->method ($ this -> anything () )
390- -> willReturnSelf ( );
391-
434+ ->method (' getLDAPAccess ' )
435+ -> willReturn ( $ access );
436+
392437 $ server = $ this ->getServerMock ($ userBackend , $ this ->getDefaultGroupBackendMock ());
393438
394439 $ ldapProvider = $ this ->getLDAPProvider ($ server );
395- $ this ->assertEquals (' ou=groups,dc=example,dc=org ' , $ ldapProvider ->getLDAPBaseGroups ('existing_user ' ));
440+ $ this ->assertEquals ($ bases [ 0 ] , $ ldapProvider ->getLDAPBaseGroups ('existing_user ' ));
396441 }
397442
398443 /**
0 commit comments