@@ -33,6 +33,8 @@ t.test('basic auth', t => {
33
33
token : null ,
34
34
isBasicAuth : true ,
35
35
auth : Buffer . from ( 'user:pass' ) . toString ( 'base64' ) ,
36
+ cert : null ,
37
+ key : null ,
36
38
} , 'basic auth details generated' )
37
39
38
40
const opts = Object . assign ( { } , OPTS , config )
@@ -62,6 +64,8 @@ t.test('token auth', t => {
62
64
isBasicAuth : false ,
63
65
token : 'c0ffee' ,
64
66
auth : null ,
67
+ cert : null ,
68
+ key : null ,
65
69
} , 'correct auth token picked out' )
66
70
67
71
const opts = Object . assign ( { } , OPTS , config )
@@ -77,24 +81,37 @@ t.test('token auth', t => {
77
81
} )
78
82
79
83
t . test ( 'forceAuth' , t => {
84
+ const dir = t . testdir ( {
85
+ 'my.cert' : 'my cert' ,
86
+ 'my.key' : 'my key' ,
87
+ 'other.cert' : 'other cert' ,
88
+ 'other.key' : 'other key' ,
89
+ } )
90
+
80
91
const config = {
81
92
registry : 'https://my.custom.registry/here/' ,
82
93
token : 'deadbeef' ,
83
94
'always-auth' : false ,
84
95
'//my.custom.registry/here/:_authToken' : 'c0ffee' ,
85
96
'//my.custom.registry/here/:token' : 'nope' ,
97
+ '//my.custom.registry/here/:certfile' : `${ dir } /my.cert` ,
98
+ '//my.custom.registry/here/:keyfile' : `${ dir } /my.key` ,
86
99
forceAuth : {
87
100
username : 'user' ,
88
101
password : Buffer . from ( 'pass' , 'utf8' ) . toString ( 'base64' ) ,
89
102
90
103
'always-auth' : true ,
104
+ certfile : `${ dir } /other.cert` ,
105
+ keyfile : `${ dir } /other.key` ,
91
106
} ,
92
107
}
93
108
t . same ( getAuth ( config . registry , config ) , {
94
109
scopeAuthKey : null ,
95
110
token : null ,
96
111
isBasicAuth : true ,
97
112
auth : Buffer . from ( 'user:pass' ) . toString ( 'base64' ) ,
113
+ cert : 'other cert' ,
114
+ key : 'other key' ,
98
115
} , 'only forceAuth details included' )
99
116
100
117
const opts = Object . assign ( { } , OPTS , config )
@@ -126,6 +143,8 @@ t.test('forceAuth token', t => {
126
143
isBasicAuth : false ,
127
144
token : 'cafebad' ,
128
145
auth : null ,
146
+ cert : null ,
147
+ key : null ,
129
148
} , 'correct forceAuth token picked out' )
130
149
131
150
const opts = Object . assign ( { } , OPTS , config )
@@ -152,6 +171,8 @@ t.test('_auth auth', t => {
152
171
token : null ,
153
172
isBasicAuth : false ,
154
173
auth : 'c0ffee' ,
174
+ cert : null ,
175
+ key : null ,
155
176
} , 'correct _auth picked out' )
156
177
157
178
const opts = Object . assign ( { } , OPTS , config )
@@ -177,6 +198,8 @@ t.test('_auth username:pass auth', t => {
177
198
token : null ,
178
199
isBasicAuth : false ,
179
200
auth : auth ,
201
+ cert : null ,
202
+ key : null ,
180
203
} , 'correct _auth picked out' )
181
204
182
205
const opts = Object . assign ( { } , OPTS , config )
@@ -226,6 +249,8 @@ t.test('globally-configured auth', t => {
226
249
token : null ,
227
250
isBasicAuth : true ,
228
251
auth : Buffer . from ( 'globaluser:globalpass' ) . toString ( 'base64' ) ,
252
+ cert : null ,
253
+ key : null ,
229
254
} , 'basic auth details generated from global settings' )
230
255
231
256
const tokenConfig = {
@@ -239,6 +264,8 @@ t.test('globally-configured auth', t => {
239
264
token : 'deadbeef' ,
240
265
isBasicAuth : false ,
241
266
auth : null ,
267
+ cert : null ,
268
+ key : null ,
242
269
} , 'correct global auth token picked out' )
243
270
244
271
const _authConfig = {
@@ -252,6 +279,8 @@ t.test('globally-configured auth', t => {
252
279
token : null ,
253
280
isBasicAuth : false ,
254
281
auth : 'deadbeef' ,
282
+ cert : null ,
283
+ key : null ,
255
284
} , 'correct _auth picked out' )
256
285
257
286
t . end ( )
@@ -270,6 +299,8 @@ t.test('otp token passed through', t => {
270
299
token : 'c0ffee' ,
271
300
isBasicAuth : false ,
272
301
auth : null ,
302
+ cert : null ,
303
+ key : null ,
273
304
} , 'correct auth token picked out' )
274
305
275
306
const opts = Object . assign ( { } , OPTS , config )
@@ -337,6 +368,8 @@ t.test('always-auth', t => {
337
368
token : 'c0ffee' ,
338
369
isBasicAuth : false ,
339
370
auth : null ,
371
+ cert : null ,
372
+ key : null ,
340
373
} , 'correct auth token picked out' )
341
374
342
375
const opts = Object . assign ( { } , OPTS , config )
@@ -349,25 +382,36 @@ t.test('always-auth', t => {
349
382
} )
350
383
351
384
t . test ( 'scope-based auth' , t => {
385
+ const dir = t . testdir ( {
386
+ 'my.cert' : 'my cert' ,
387
+ 'my.key' : 'my key' ,
388
+ } )
389
+
352
390
const config = {
353
391
registry : 'https://my.custom.registry/here/' ,
354
392
scope : '@myscope' ,
355
393
'@myscope:registry' : 'https://my.custom.registry/here/' ,
356
394
token : 'deadbeef' ,
357
395
'//my.custom.registry/here/:_authToken' : 'c0ffee' ,
358
396
'//my.custom.registry/here/:token' : 'nope' ,
397
+ '//my.custom.registry/here/:certfile' : `${ dir } /my.cert` ,
398
+ '//my.custom.registry/here/:keyfile' : `${ dir } /my.key` ,
359
399
}
360
400
t . same ( getAuth ( config [ '@myscope:registry' ] , config ) , {
361
401
scopeAuthKey : null ,
362
402
auth : null ,
363
403
isBasicAuth : false ,
364
404
token : 'c0ffee' ,
405
+ cert : 'my cert' ,
406
+ key : 'my key' ,
365
407
} , 'correct auth token picked out' )
366
408
t . same ( getAuth ( config [ '@myscope:registry' ] , config ) , {
367
409
scopeAuthKey : null ,
368
410
auth : null ,
369
411
isBasicAuth : false ,
370
412
token : 'c0ffee' ,
413
+ cert : 'my cert' ,
414
+ key : 'my key' ,
371
415
} , 'correct auth token picked out without scope config having an @' )
372
416
373
417
const opts = Object . assign ( { } , OPTS , config )
@@ -412,6 +456,8 @@ t.test('do not be thrown by other weird configs', t => {
412
456
token : 'correct bearer token' ,
413
457
isBasicAuth : false ,
414
458
auth : null ,
459
+ cert : null ,
460
+ key : null ,
415
461
} )
416
462
t . end ( )
417
463
} )
@@ -430,27 +476,35 @@ t.test('scopeAuthKey tests', t => {
430
476
auth : null ,
431
477
isBasicAuth : false ,
432
478
token : null ,
479
+ cert : null ,
480
+ key : null ,
433
481
} , 'regular scoped spec' )
434
482
435
483
t . same ( getAuth ( uri , { ...opts , spec : 'foo@npm:@scope/foo@latest' } ) , {
436
484
scopeAuthKey : '//scope-host.com/' ,
437
485
auth : null ,
438
486
isBasicAuth : false ,
439
487
token : null ,
488
+ cert : null ,
489
+ key : null ,
440
490
} , 'scoped pkg aliased to unscoped name' )
441
491
442
492
t . same ( getAuth ( uri , { ...opts , spec : '@other-scope/foo@npm:@scope/foo@latest' } ) , {
443
493
scopeAuthKey : '//scope-host.com/' ,
444
494
auth : null ,
445
495
isBasicAuth : false ,
446
496
token : null ,
497
+ cert : null ,
498
+ key : null ,
447
499
} , 'scoped name aliased to other scope with auth' )
448
500
449
501
t . same ( getAuth ( uri , { ...opts , spec : '@scope/foo@npm:foo@latest' } ) , {
450
502
scopeAuthKey : null ,
451
503
auth : null ,
452
504
isBasicAuth : false ,
453
505
token : null ,
506
+ cert : null ,
507
+ key : null ,
454
508
} , 'unscoped aliased to scoped name' )
455
509
456
510
t . end ( )
@@ -470,18 +524,24 @@ t.test('registry host matches, path does not, send auth', t => {
470
524
token : 'c0ffee' ,
471
525
auth : null ,
472
526
isBasicAuth : false ,
527
+ cert : null ,
528
+ key : null ,
473
529
} )
474
530
t . same ( getAuth ( uri , { ...opts , spec : '@other-scope/foo' } ) , {
475
531
scopeAuthKey : '//other-scope-registry.com/other/scope/' ,
476
532
token : null ,
477
533
auth : null ,
478
534
isBasicAuth : false ,
535
+ cert : null ,
536
+ key : null ,
479
537
} )
480
538
t . same ( getAuth ( uri , { ...opts , registry : 'https://scope-host.com/scope/host/' } ) , {
481
539
scopeAuthKey : null ,
482
540
token : 'c0ffee' ,
483
541
auth : null ,
484
542
isBasicAuth : false ,
543
+ cert : null ,
544
+ key : null ,
485
545
} )
486
546
t . end ( )
487
547
} )
0 commit comments