@@ -179,7 +179,7 @@ vows.describe('BasicStrategy').addBatch({
179
179
} ,
180
180
} ,
181
181
182
- 'strategy handling a request with credentials lacking a password ' : {
182
+ 'strategy handling a request with credentials lacking the " " separator ' : {
183
183
topic : function ( ) {
184
184
return new BasicStrategy ( ( ( userid , password , done ) => {
185
185
done ( null , { username : userid , password : password } ) ;
@@ -197,7 +197,7 @@ vows.describe('BasicStrategy').addBatch({
197
197
} ;
198
198
199
199
req . headers = { } ;
200
- req . headers . authorization = 'Basic Ym9iOg== ' ;
200
+ req . headers . authorization = 'Basic' ;
201
201
process . nextTick ( ( ) => {
202
202
strategy . authenticate ( req ) ;
203
203
} ) ;
@@ -206,12 +206,12 @@ vows.describe('BasicStrategy').addBatch({
206
206
'should fail authentication with challenge' : function ( err , challenge ) {
207
207
// fail action was called, resulting in test callback
208
208
assert . isNull ( err ) ;
209
- assert . strictEqual ( challenge , 'Basic realm="Users"' ) ;
209
+ assert . strictEqual ( challenge , 400 ) ;
210
210
} ,
211
211
} ,
212
212
} ,
213
213
214
- 'strategy handling a request with credentials lacking a username ' : {
214
+ 'strategy handling a request with credentials containing an empty user-pass ' : {
215
215
topic : function ( ) {
216
216
return new BasicStrategy ( ( ( userid , password , done ) => {
217
217
done ( null , { username : userid , password : password } ) ;
@@ -229,7 +229,7 @@ vows.describe('BasicStrategy').addBatch({
229
229
} ;
230
230
231
231
req . headers = { } ;
232
- req . headers . authorization = 'Basic OnNlY3JldA== ' ;
232
+ req . headers . authorization = 'Basic ' ;
233
233
process . nextTick ( ( ) => {
234
234
strategy . authenticate ( req ) ;
235
235
} ) ;
@@ -238,7 +238,139 @@ vows.describe('BasicStrategy').addBatch({
238
238
'should fail authentication with challenge' : function ( err , challenge ) {
239
239
// fail action was called, resulting in test callback
240
240
assert . isNull ( err ) ;
241
- assert . strictEqual ( challenge , 'Basic realm="Users"' ) ;
241
+ assert . strictEqual ( challenge , 400 ) ;
242
+ } ,
243
+ } ,
244
+ } ,
245
+
246
+ 'strategy handling a request with credentials lacking the ":" separator' : {
247
+ topic : function ( ) {
248
+ return new BasicStrategy ( ( ( userid , password , done ) => {
249
+ done ( null , { username : userid , password : password } ) ;
250
+ } ) ) ;
251
+ } ,
252
+
253
+ 'after augmenting with actions' : {
254
+ topic : function ( strategy ) {
255
+ const req = { } ;
256
+ strategy . success = ( user ) => {
257
+ this . callback ( new Error ( 'should not be called' ) ) ;
258
+ } ;
259
+ strategy . fail = ( challenge ) => {
260
+ this . callback ( null , challenge ) ;
261
+ } ;
262
+
263
+ req . headers = { } ;
264
+ req . headers . authorization = 'Basic Ym9i' ; // bob
265
+ process . nextTick ( ( ) => {
266
+ strategy . authenticate ( req ) ;
267
+ } ) ;
268
+ } ,
269
+
270
+ 'should fail authentication with challenge' : function ( err , challenge ) {
271
+ // fail action was called, resulting in test callback
272
+ assert . isNull ( err ) ;
273
+ assert . strictEqual ( challenge , 400 ) ;
274
+ } ,
275
+ } ,
276
+ } ,
277
+
278
+ 'strategy handling a request with credentials containing an empty username' : {
279
+ topic : function ( ) {
280
+ return new BasicStrategy ( ( ( userid , password , done ) => {
281
+ done ( null , { username : userid , password : password } ) ;
282
+ } ) ) ;
283
+ } ,
284
+
285
+ 'after augmenting with actions' : {
286
+ topic : function ( strategy ) {
287
+ const req = { } ;
288
+ strategy . success = ( user ) => {
289
+ this . callback ( null , user ) ;
290
+ } ;
291
+ strategy . fail = ( challenge ) => {
292
+ this . callback ( new Error ( 'should not be called' ) ) ;
293
+ } ;
294
+
295
+ req . headers = { } ;
296
+ req . headers . authorization = 'Basic OnBhc3N3b3Jk' ; // :password
297
+ process . nextTick ( ( ) => {
298
+ strategy . authenticate ( req ) ;
299
+ } ) ;
300
+ } ,
301
+
302
+ 'should not generate an error' : ( err , user ) => {
303
+ assert . isNull ( err ) ;
304
+ } ,
305
+ 'should authenticate' : ( err , user ) => {
306
+ assert . strictEqual ( user . username , '' ) ;
307
+ assert . strictEqual ( user . password , 'password' ) ;
308
+ } ,
309
+ } ,
310
+ } ,
311
+
312
+ 'strategy handling a request with credentials containing an empty password' : {
313
+ topic : function ( ) {
314
+ return new BasicStrategy ( ( ( userid , password , done ) => {
315
+ done ( null , { username : userid , password : password } ) ;
316
+ } ) ) ;
317
+ } ,
318
+
319
+ 'after augmenting with actions' : {
320
+ topic : function ( strategy ) {
321
+ const req = { } ;
322
+ strategy . success = ( user ) => {
323
+ this . callback ( null , user ) ;
324
+ } ;
325
+ strategy . fail = ( challenge ) => {
326
+ this . callback ( new Error ( 'should not be called' ) ) ;
327
+ } ;
328
+
329
+ req . headers = { } ;
330
+ req . headers . authorization = 'Basic Ym9iOg==' ; // bob:
331
+ process . nextTick ( ( ) => {
332
+ strategy . authenticate ( req ) ;
333
+ } ) ;
334
+ } ,
335
+
336
+ 'should not generate an error' : ( err , user ) => {
337
+ assert . isNull ( err ) ;
338
+ } ,
339
+ 'should authenticate' : ( err , user ) => {
340
+ assert . strictEqual ( user . username , 'bob' ) ;
341
+ assert . strictEqual ( user . password , '' ) ;
342
+ } ,
343
+ } ,
344
+ } ,
345
+
346
+ 'strategy handling a request containing a colon in the password' : {
347
+ topic : function ( ) {
348
+ return new BasicStrategy ( ( userid , password , done ) => {
349
+ done ( null , { username : userid , password : password } ) ;
350
+ } ) ;
351
+ } ,
352
+ 'after augmenting with actions' : {
353
+ topic : function ( strategy ) {
354
+ const req = { } ;
355
+ strategy . success = user => {
356
+ this . callback ( null , user ) ;
357
+ } ;
358
+ strategy . fail = ( ) => {
359
+ this . callback ( new Error ( 'should not be called' ) ) ;
360
+ } ;
361
+
362
+ req . headers = { } ;
363
+ req . headers . authorization = 'Basic Ym9iOnNlY3JldDpwdw==' ; // bob:secret:pw
364
+ process . nextTick ( ( ) => {
365
+ strategy . authenticate ( req ) ;
366
+ } ) ;
367
+ } ,
368
+ 'should not generate an error' : ( err , user ) => {
369
+ assert . isNull ( err ) ;
370
+ } ,
371
+ 'should authenticate' : ( err , user ) => {
372
+ assert . strictEqual ( user . username , 'bob' ) ;
373
+ assert . strictEqual ( user . password , 'secret:pw' ) ;
242
374
} ,
243
375
} ,
244
376
} ,
0 commit comments