@@ -119,7 +119,7 @@ public function testLoadUserByUsernameFailsIfMoreThanOneLdapPasswordsInEntry()
119
119
;
120
120
$ ldap = $ this ->getMockBuilder (LdapInterface::class)->getMock ();
121
121
$ result
122
- ->expects ($ this ->exactly ( 2 ))
122
+ ->expects ($ this ->once ( ))
123
123
->method ('offsetGet ' )
124
124
->with (0 )
125
125
->will ($ this ->returnValue (new Entry ('foo ' , array (
@@ -151,6 +151,48 @@ public function testLoadUserByUsernameFailsIfMoreThanOneLdapPasswordsInEntry()
151
151
);
152
152
}
153
153
154
+ /**
155
+ * @expectedException \Symfony\Component\Security\Core\Exception\InvalidArgumentException
156
+ */
157
+ public function testLoadUserByUsernameFailsIfEntryHasNoUidKeyAttribute ()
158
+ {
159
+ $ result = $ this ->getMock (CollectionInterface::class);
160
+ $ query = $ this ->getMock (QueryInterface::class);
161
+ $ query
162
+ ->expects ($ this ->once ())
163
+ ->method ('execute ' )
164
+ ->will ($ this ->returnValue ($ result ))
165
+ ;
166
+ $ ldap = $ this ->getMock (LdapInterface::class);
167
+ $ result
168
+ ->expects ($ this ->once ())
169
+ ->method ('offsetGet ' )
170
+ ->with (0 )
171
+ ->will ($ this ->returnValue (new Entry ('foo ' , array ())))
172
+ ;
173
+ $ result
174
+ ->expects ($ this ->once ())
175
+ ->method ('count ' )
176
+ ->will ($ this ->returnValue (1 ))
177
+ ;
178
+ $ ldap
179
+ ->expects ($ this ->once ())
180
+ ->method ('escape ' )
181
+ ->will ($ this ->returnValue ('foo ' ))
182
+ ;
183
+ $ ldap
184
+ ->expects ($ this ->once ())
185
+ ->method ('query ' )
186
+ ->will ($ this ->returnValue ($ query ))
187
+ ;
188
+
189
+ $ provider = new LdapUserProvider ($ ldap , 'ou=MyBusiness,dc=symfony,dc=com ' , null , null , array (), 'sAMAccountName ' , '({uid_key}={username}) ' );
190
+ $ this ->assertInstanceOf (
191
+ 'Symfony\Component\Security\Core\User\User ' ,
192
+ $ provider ->loadUserByUsername ('foo ' )
193
+ );
194
+ }
195
+
154
196
/**
155
197
* @expectedException \Symfony\Component\Security\Core\Exception\InvalidArgumentException
156
198
*/
@@ -165,7 +207,7 @@ public function testLoadUserByUsernameFailsIfEntryHasNoPasswordAttribute()
165
207
;
166
208
$ ldap = $ this ->getMockBuilder (LdapInterface::class)->getMock ();
167
209
$ result
168
- ->expects ($ this ->exactly ( 2 ))
210
+ ->expects ($ this ->once ( ))
169
211
->method ('offsetGet ' )
170
212
->with (0 )
171
213
->will ($ this ->returnValue (new Entry ('foo ' , array (
@@ -207,7 +249,7 @@ public function testLoadUserByUsernameIsSuccessfulWithoutPasswordAttribute()
207
249
;
208
250
$ ldap = $ this ->getMockBuilder (LdapInterface::class)->getMock ();
209
251
$ result
210
- ->expects ($ this ->exactly ( 2 ))
252
+ ->expects ($ this ->once ( ))
211
253
->method ('offsetGet ' )
212
254
->with (0 )
213
255
->will ($ this ->returnValue (new Entry ('foo ' , array (
@@ -249,7 +291,7 @@ public function testLoadUserByUsernameIsSuccessfulWithoutPasswordAttributeAndWro
249
291
;
250
292
$ ldap = $ this ->getMockBuilder (LdapInterface::class)->getMock ();
251
293
$ result
252
- ->expects ($ this ->exactly ( 2 ))
294
+ ->expects ($ this ->once ( ))
253
295
->method ('offsetGet ' )
254
296
->with (0 )
255
297
->will ($ this ->returnValue (new Entry ('foo ' , array (
@@ -288,7 +330,7 @@ public function testLoadUserByUsernameIsSuccessfulWithPasswordAttribute()
288
330
;
289
331
$ ldap = $ this ->getMock (LdapInterface::class);
290
332
$ result
291
- ->expects ($ this ->exactly ( 2 ))
333
+ ->expects ($ this ->once ( ))
292
334
->method ('offsetGet ' )
293
335
->with (0 )
294
336
->will ($ this ->returnValue (new Entry ('foo ' , array (
0 commit comments