@@ -105,7 +105,10 @@ public function testLoadUserByUsernameFailsIfMoreThanOneLdapEntry()
105
105
$ provider ->loadUserByUsername ('foo ' );
106
106
}
107
107
108
- public function testSuccessfulLoadUserByUsername ()
108
+ /**
109
+ * @expectedException \Symfony\Component\Security\Core\Exception\InvalidArgumentException
110
+ */
111
+ public function testLoadUserByUsernameFailsIfMoreThanOneLdapPasswordsInEntry ()
109
112
{
110
113
$ result = $ this ->getMock (CollectionInterface::class);
111
114
$ query = $ this ->getMock (QueryInterface::class);
@@ -120,8 +123,95 @@ public function testSuccessfulLoadUserByUsername()
120
123
->method ('offsetGet ' )
121
124
->with (0 )
122
125
->will ($ this ->returnValue (new Entry ('foo ' , array (
123
- 'sAMAccountName ' => 'foo ' ,
124
- 'userpassword ' => 'bar ' ,
126
+ 'sAMAccountName ' => array ('foo ' ),
127
+ 'userpassword ' => array ('bar ' , 'baz ' ),
128
+ )
129
+ )))
130
+ ;
131
+ $ result
132
+ ->expects ($ this ->once ())
133
+ ->method ('count ' )
134
+ ->will ($ this ->returnValue (1 ))
135
+ ;
136
+ $ ldap
137
+ ->expects ($ this ->once ())
138
+ ->method ('escape ' )
139
+ ->will ($ this ->returnValue ('foo ' ))
140
+ ;
141
+ $ ldap
142
+ ->expects ($ this ->once ())
143
+ ->method ('query ' )
144
+ ->will ($ this ->returnValue ($ query ))
145
+ ;
146
+
147
+ $ provider = new LdapUserProvider ($ ldap , 'ou=MyBusiness,dc=symfony,dc=com ' , null , null , array (), 'sAMAccountName ' , '({uid_key}={username}) ' , 'userpassword ' );
148
+ $ this ->assertInstanceOf (
149
+ 'Symfony\Component\Security\Core\User\User ' ,
150
+ $ provider ->loadUserByUsername ('foo ' )
151
+ );
152
+ }
153
+
154
+ /**
155
+ * @expectedException \Symfony\Component\Security\Core\Exception\InvalidArgumentException
156
+ */
157
+ public function testLoadUserByUsernameFailsIfEntryHasNoPasswordAttribute ()
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
+ 'sAMAccountName ' => array ('foo ' ),
173
+ )
174
+ )))
175
+ ;
176
+ $ result
177
+ ->expects ($ this ->once ())
178
+ ->method ('count ' )
179
+ ->will ($ this ->returnValue (1 ))
180
+ ;
181
+ $ ldap
182
+ ->expects ($ this ->once ())
183
+ ->method ('escape ' )
184
+ ->will ($ this ->returnValue ('foo ' ))
185
+ ;
186
+ $ ldap
187
+ ->expects ($ this ->once ())
188
+ ->method ('query ' )
189
+ ->will ($ this ->returnValue ($ query ))
190
+ ;
191
+
192
+ $ provider = new LdapUserProvider ($ ldap , 'ou=MyBusiness,dc=symfony,dc=com ' , null , null , array (), 'sAMAccountName ' , '({uid_key}={username}) ' , 'userpassword ' );
193
+ $ this ->assertInstanceOf (
194
+ 'Symfony\Component\Security\Core\User\User ' ,
195
+ $ provider ->loadUserByUsername ('foo ' )
196
+ );
197
+ }
198
+
199
+ public function testLoadUserByUsernameIsSuccessfulWithoutPasswordAttribute ()
200
+ {
201
+ $ result = $ this ->getMock (CollectionInterface::class);
202
+ $ query = $ this ->getMock (QueryInterface::class);
203
+ $ query
204
+ ->expects ($ this ->once ())
205
+ ->method ('execute ' )
206
+ ->will ($ this ->returnValue ($ result ))
207
+ ;
208
+ $ ldap = $ this ->getMock (LdapInterface::class);
209
+ $ result
210
+ ->expects ($ this ->once ())
211
+ ->method ('offsetGet ' )
212
+ ->with (0 )
213
+ ->will ($ this ->returnValue (new Entry ('foo ' , array (
214
+ 'sAMAccountName ' => array ('foo ' ),
125
215
)
126
216
)))
127
217
;
@@ -147,4 +237,47 @@ public function testSuccessfulLoadUserByUsername()
147
237
$ provider ->loadUserByUsername ('foo ' )
148
238
);
149
239
}
240
+
241
+ public function testLoadUserByUsernameIsSuccessfulWithPasswordAttribute ()
242
+ {
243
+ $ result = $ this ->getMock (CollectionInterface::class);
244
+ $ query = $ this ->getMock (QueryInterface::class);
245
+ $ query
246
+ ->expects ($ this ->once ())
247
+ ->method ('execute ' )
248
+ ->will ($ this ->returnValue ($ result ))
249
+ ;
250
+ $ ldap = $ this ->getMock (LdapInterface::class);
251
+ $ result
252
+ ->expects ($ this ->once ())
253
+ ->method ('offsetGet ' )
254
+ ->with (0 )
255
+ ->will ($ this ->returnValue (new Entry ('foo ' , array (
256
+ 'sAMAccountName ' => array ('foo ' ),
257
+ 'userpassword ' => array ('bar ' ),
258
+ )
259
+ )))
260
+ ;
261
+ $ result
262
+ ->expects ($ this ->once ())
263
+ ->method ('count ' )
264
+ ->will ($ this ->returnValue (1 ))
265
+ ;
266
+ $ ldap
267
+ ->expects ($ this ->once ())
268
+ ->method ('escape ' )
269
+ ->will ($ this ->returnValue ('foo ' ))
270
+ ;
271
+ $ ldap
272
+ ->expects ($ this ->once ())
273
+ ->method ('query ' )
274
+ ->will ($ this ->returnValue ($ query ))
275
+ ;
276
+
277
+ $ provider = new LdapUserProvider ($ ldap , 'ou=MyBusiness,dc=symfony,dc=com ' , null , null , array (), 'sAMAccountName ' , '({uid_key}={username}) ' , 'userpassword ' );
278
+ $ this ->assertInstanceOf (
279
+ 'Symfony\Component\Security\Core\User\User ' ,
280
+ $ provider ->loadUserByUsername ('foo ' )
281
+ );
282
+ }
150
283
}
0 commit comments