@@ -76,6 +76,40 @@ test('token auth', t => {
76
76
. then ( res => t . equal ( res , 'success' , 'token auth succeeded' ) )
77
77
} )
78
78
79
+ test ( 'forceAuth' , t => {
80
+ const config = {
81
+ 'registry' : 'https://my.custom.registry/here/' ,
82
+ 'token' : 'deadbeef' ,
83
+ 'always-auth' : false ,
84
+ '//my.custom.registry/here/:_authToken' : 'c0ffee' ,
85
+ '//my.custom.registry/here/:token' : 'nope' ,
86
+ 'forceAuth' : {
87
+ 'username' : 'user' ,
88
+ 'password' : Buffer . from ( 'pass' , 'utf8' ) . toString ( 'base64' ) ,
89
+ 'email' : 'e@ma.il' ,
90
+ 'always-auth' : true
91
+ }
92
+ }
93
+ t . deepEqual ( getAuth ( config . registry , config ) , {
94
+ alwaysAuth : true ,
95
+ username : 'user' ,
96
+ password : 'pass' ,
97
+ email : 'e@ma.il'
98
+ } , 'only forceAuth details included' )
99
+
100
+ const opts = Object . assign ( { } , OPTS , config )
101
+ const encoded = Buffer . from ( `user:pass` , 'utf8' ) . toString ( 'base64' )
102
+ tnock ( t , opts . registry )
103
+ . matchHeader ( 'authorization' , auth => {
104
+ t . equal ( auth [ 0 ] , `Basic ${ encoded } ` , 'got encoded basic auth' )
105
+ return auth [ 0 ] === `Basic ${ encoded } `
106
+ } )
107
+ . get ( '/hello' )
108
+ . reply ( 200 , '"success"' )
109
+ return fetch . json ( '/hello' , opts )
110
+ . then ( res => t . equal ( res , 'success' , 'used forced auth details' ) )
111
+ } )
112
+
79
113
test ( '_auth auth' , t => {
80
114
const config = {
81
115
'registry' : 'https://my.custom.registry/here/' ,
0 commit comments