@@ -81,18 +81,22 @@ public function testFindAndBind()
8181 $ this ->settings ->enableLdap ();
8282
8383 $ ldap_connect = $ this ->getFunctionMock ("App \\Models " , "ldap_connect " );
84- $ ldap_connect ->expects ($ this ->once ( ))->willReturn ('hello ' );
84+ $ ldap_connect ->expects ($ this ->exactly ( 3 ))->willReturn ('hello ' );
8585
8686 $ ldap_set_option = $ this ->getFunctionMock ("App \\Models " , "ldap_set_option " );
87- $ ldap_set_option ->expects ($ this ->exactly (4 ));
87+ $ ldap_set_option ->expects ($ this ->exactly (12 ));
8888
89- $ this ->getFunctionMock ("App \\Models " , "ldap_bind " )->expects ($ this ->once ( ))->willReturn (true );
89+ $ this ->getFunctionMock ("App \\Models " , "ldap_bind " )->expects ($ this ->exactly ( 2 ))->willReturn (true );
9090
91- $ this ->getFunctionMock ("App \\Models " , "ldap_search " )->expects ($ this ->once ( ))->willReturn (true );
91+ $ this ->getFunctionMock ("App \\Models " , "ldap_search " )->expects ($ this ->exactly ( 1 ))->willReturn (true );
9292
93- $ this ->getFunctionMock ("App \\Models " , "ldap_first_entry " )->expects ($ this ->once ())->willReturn (true );
93+ $ this ->getFunctionMock ("App \\Models " , "ldap_first_entry " )->expects ($ this ->exactly (1 ))->willReturn (true );
94+ $ this ->getFunctionMock ("App \\Models " , "ldap_unbind " )->expects ($ this ->exactly (2 ));
95+ $ this ->getFunctionMock ("App \\Models " , "ldap_count_entries " )->expects ($ this ->once ())->willReturn (1 );
96+ $ this ->getFunctionMock ("App \\Models " , "ldap_get_dn " )->expects ($ this ->once ())->willReturn ('dn=FirstName Surname,ou=Org,dc=example,dc=com ' );
9497
95- $ this ->getFunctionMock ("App \\Models " , "ldap_get_attributes " )->expects ($ this ->once ())->willReturn (
98+
99+ $ this ->getFunctionMock ("App \\Models " , "ldap_get_attributes " )->expects ($ this ->exactly (1 ))->willReturn (
96100 [
97101 "count " => 1 ,
98102 0 => [
@@ -111,13 +115,25 @@ public function testFindAndBindBadPassword()
111115 $ this ->settings ->enableLdap ();
112116
113117 $ ldap_connect = $ this ->getFunctionMock ("App \\Models " , "ldap_connect " );
114- $ ldap_connect ->expects ($ this ->once ( ))->willReturn ('hello ' );
118+ $ ldap_connect ->expects ($ this ->exactly ( 3 ))->willReturn ('hello ' );
115119
116120 $ ldap_set_option = $ this ->getFunctionMock ("App \\Models " , "ldap_set_option " );
117- $ ldap_set_option ->expects ($ this ->exactly (4 ));
118-
119- // note - we return FALSE first, to simulate a bad-bind, then TRUE the second time to simulate a successful admin bind
120- $ this ->getFunctionMock ("App \\Models " , "ldap_bind " )->expects ($ this ->exactly (2 ))->willReturn (false , true );
121+ $ ldap_set_option ->expects ($ this ->exactly (12 ));
122+
123+ //
124+ $ this ->getFunctionMock ("App \\Models " , "ldap_bind " )->expects ($ this ->exactly (4 ))->willReturn (
125+ true , /* initial admin connection for 'fast path' */
126+ false , /* the actual login for the user */
127+ false , /* the direct login for the user binding-as-themselves in the legacy path */
128+ true /* the admin login afterwards (which is weird and doesn't make sense) */
129+ );
130+ $ this ->getFunctionMock ("App \\Models " , "ldap_unbind " )->expects ($ this ->exactly (2 ));
131+ $ this ->getFunctionMock ("App \\Models " , "ldap_error " )->expects ($ this ->never ())->willReturn ("exception " );
132+ $ this ->getFunctionMock ("App \\Models " , "ldap_search " )->expects ($ this ->exactly (1 ))->willReturn (false ); //uhm?
133+ $ this ->getFunctionMock ("App \\Models " , "ldap_count_entries " )->expects ($ this ->exactly (1 ))->willReturn (1 );
134+ $ this ->getFunctionMock ("App \\Models " , "ldap_first_entry " )->expects ($ this ->exactly (1 ))->willReturn (true );
135+ $ this ->getFunctionMock ("App \\Models " , "ldap_get_attributes " )->expects ($ this ->exactly (1 ))->willReturn (1 );
136+ $ this ->getFunctionMock ("App \\Models " , "ldap_get_dn " )->expects ($ this ->exactly (1 ))->willReturn ('dn=FirstName Surname,ou=Org,dc=example,dc=com ' );
121137
122138// $this->getFunctionMock("App\\Models","ldap_error")->expects($this->once())->willReturn("exception");
123139
@@ -132,14 +148,17 @@ public function testFindAndBindCannotFindSelf()
132148 $ this ->settings ->enableLdap ();
133149
134150 $ ldap_connect = $ this ->getFunctionMock ("App \\Models " , "ldap_connect " );
135- $ ldap_connect ->expects ($ this ->once ( ))->willReturn ('hello ' );
151+ $ ldap_connect ->expects ($ this ->exactly ( 2 ))->willReturn ('hello ' );
136152
137153 $ ldap_set_option = $ this ->getFunctionMock ("App \\Models " , "ldap_set_option " );
138- $ ldap_set_option ->expects ($ this ->exactly (4 ));
154+ $ ldap_set_option ->expects ($ this ->exactly (8 ));
139155
140- $ this ->getFunctionMock ("App \\Models " , "ldap_bind " )->expects ($ this ->once ())->willReturn (true );
156+ $ this ->getFunctionMock ("App \\Models " , "ldap_bind " )->expects ($ this ->exactly (2 ))->willReturn (true ); //I think this is OK
157+
158+ $ this ->getFunctionMock ("App \\Models " , "ldap_search " )->expects ($ this ->exactly (2 ))->willReturn (false ); //uhm?
159+ $ this ->getFunctionMock ("App \\Models " , "ldap_unbind " )->expects ($ this ->once ());
160+ $ this ->getFunctionMock ("App \\Models " , "ldap_count_entries " )->expects ($ this ->once ())->willReturn (0 );
141161
142- $ this ->getFunctionMock ("App \\Models " , "ldap_search " )->expects ($ this ->once ())->willReturn (false );
143162
144163 $ this ->expectExceptionMessage ("Could not search LDAP: " );
145164 $ results = Ldap::findAndBindUserLdap ("username " ,"password " );
0 commit comments