@@ -12,7 +12,37 @@ const valids = [
12
12
{ userInfo : [ ] } ,
13
13
{ userInfo : [ 'string' ] } ,
14
14
{ minTimeBetweenJwksRequests : 0 } ,
15
- { minTimeBetweenJwksRequests : 42 }
15
+ { minTimeBetweenJwksRequests : 42 } ,
16
+ { apiKey : {
17
+ url : 'http://foobar.com/foo/bar'
18
+ } } ,
19
+ { apiKey : {
20
+ url : 'http://foobar.com/foo/bar' ,
21
+ in : 'headers'
22
+ } } ,
23
+ { apiKey : {
24
+ url : 'http://foobar.com/foo/bar' ,
25
+ in : 'query'
26
+ } } ,
27
+ { apiKey : {
28
+ url : 'http://foobar.com/foo/bar' ,
29
+ name : 'foobar'
30
+ } } ,
31
+ { apiKey : {
32
+ url : 'http://foobar.com/foo/bar' ,
33
+ prefix : 'barfoo '
34
+ } } ,
35
+ { apiKey : {
36
+ url : 'http://foobar.com/foo/bar' ,
37
+ request : { }
38
+ } } ,
39
+ { apiKey : {
40
+ url : 'http://foobar.com/foo/bar' ,
41
+ tokenPath : 'foo.bar'
42
+ } } ,
43
+ { apiKey : {
44
+ url : 'http://foobar.com/{client}/bar'
45
+ } }
16
46
]
17
47
18
48
test ( 'throw error if options are empty' , ( t ) => {
@@ -219,6 +249,178 @@ test('throw error if options are invalid – entitlement', (t) => {
219
249
} )
220
250
} )
221
251
252
+ test ( 'throw error if options are invalid – apiKey' , ( t ) => {
253
+ const invalids = [
254
+ null ,
255
+ NaN ,
256
+ '' ,
257
+ 'foobar' ,
258
+ fixtures . common . baseUrl ,
259
+ 42 ,
260
+ [ ] ,
261
+ true ,
262
+ false ,
263
+ { }
264
+ ]
265
+
266
+ t . plan ( invalids . length )
267
+
268
+ invalids . forEach ( ( invalid ) => {
269
+ t . throws ( ( ) => utils . verify ( helpers . getOptions ( {
270
+ apiKey : invalid
271
+ } ) ) , Error , helpers . log ( 'apiKey' , invalid ) )
272
+ } )
273
+ } )
274
+
275
+ test ( 'throw error if options are invalid – apiKey.url' , ( t ) => {
276
+ const invalids = [
277
+ null ,
278
+ NaN ,
279
+ '' ,
280
+ 42 ,
281
+ true ,
282
+ false ,
283
+ [ ] ,
284
+ new RegExp ( ) ,
285
+ { }
286
+ ]
287
+
288
+ t . plan ( invalids . length )
289
+
290
+ invalids . forEach ( ( invalid ) => {
291
+ t . throws ( ( ) => utils . verify ( helpers . getOptions ( {
292
+ apiKey : {
293
+ url : invalid
294
+ }
295
+ } ) ) , Error , helpers . log ( 'apiKey.url' , invalid ) )
296
+ } )
297
+ } )
298
+
299
+ test ( 'throw error if options are invalid – apiKey.name' , ( t ) => {
300
+ const invalids = [
301
+ null ,
302
+ NaN ,
303
+ '' ,
304
+ 42 ,
305
+ true ,
306
+ false ,
307
+ [ ] ,
308
+ new RegExp ( ) ,
309
+ { }
310
+ ]
311
+
312
+ t . plan ( invalids . length )
313
+
314
+ invalids . forEach ( ( invalid ) => {
315
+ t . throws ( ( ) => utils . verify ( helpers . getOptions ( {
316
+ apiKey : {
317
+ url : 'http://foobar.com/foo/bar' ,
318
+ name : invalid
319
+ }
320
+ } ) ) , Error , helpers . log ( 'apiKey.name' , invalid ) )
321
+ } )
322
+ } )
323
+
324
+ test ( 'throw error if options are invalid – apiKey.prefix' , ( t ) => {
325
+ const invalids = [
326
+ null ,
327
+ NaN ,
328
+ '' ,
329
+ 42 ,
330
+ true ,
331
+ false ,
332
+ [ ] ,
333
+ new RegExp ( ) ,
334
+ { }
335
+ ]
336
+
337
+ t . plan ( invalids . length )
338
+
339
+ invalids . forEach ( ( invalid ) => {
340
+ t . throws ( ( ) => utils . verify ( helpers . getOptions ( {
341
+ apiKey : {
342
+ url : 'http://foobar.com/foo/bar' ,
343
+ prefix : invalid
344
+ }
345
+ } ) ) , Error , helpers . log ( 'apiKey.prefix' , invalid ) )
346
+ } )
347
+ } )
348
+
349
+ test ( 'throw error if options are invalid – apiKey.tokenPath' , ( t ) => {
350
+ const invalids = [
351
+ null ,
352
+ NaN ,
353
+ '' ,
354
+ 42 ,
355
+ true ,
356
+ false ,
357
+ [ ] ,
358
+ new RegExp ( ) ,
359
+ { }
360
+ ]
361
+
362
+ t . plan ( invalids . length )
363
+
364
+ invalids . forEach ( ( invalid ) => {
365
+ t . throws ( ( ) => utils . verify ( helpers . getOptions ( {
366
+ apiKey : {
367
+ url : 'http://foobar.com/foo/bar' ,
368
+ tokenPath : invalid
369
+ }
370
+ } ) ) , Error , helpers . log ( 'apiKey.tokenPath' , invalid ) )
371
+ } )
372
+ } )
373
+
374
+ test ( 'throw error if options are invalid – apiKey.in' , ( t ) => {
375
+ const invalids = [
376
+ null ,
377
+ NaN ,
378
+ '' ,
379
+ 42 ,
380
+ true ,
381
+ false ,
382
+ [ ] ,
383
+ new RegExp ( ) ,
384
+ { } ,
385
+ 'foo'
386
+ ]
387
+
388
+ t . plan ( invalids . length )
389
+
390
+ invalids . forEach ( ( invalid ) => {
391
+ t . throws ( ( ) => utils . verify ( helpers . getOptions ( {
392
+ apiKey : {
393
+ url : 'http://foobar.com/foo/bar' ,
394
+ in : invalid
395
+ }
396
+ } ) ) , Error , helpers . log ( 'apiKey.in' , invalid ) )
397
+ } )
398
+ } )
399
+
400
+ test ( 'throw error if options are invalid – apiKey.options' , ( t ) => {
401
+ const invalids = [
402
+ null ,
403
+ NaN ,
404
+ '' ,
405
+ 'foobar' ,
406
+ fixtures . common . baseUrl ,
407
+ 42 ,
408
+ [ ] ,
409
+ { }
410
+ ]
411
+
412
+ t . plan ( invalids . length )
413
+
414
+ invalids . forEach ( ( invalid ) => {
415
+ t . throws ( ( ) => utils . verify ( helpers . getOptions ( {
416
+ apiKey : {
417
+ url : 'http://foobar.com/foo/bar' ,
418
+ options : invalid
419
+ }
420
+ } ) ) , Error , helpers . log ( 'apiKey.options' , invalid ) )
421
+ } )
422
+ } )
423
+
222
424
test ( 'throw error if options are invalid – publicKey/secret/entitlement conflict' , ( t ) => {
223
425
t . throws ( ( ) => utils . verify ( helpers . getOptions ( {
224
426
publicKey : fixtures . common . publicKeyRsa ,
0 commit comments