Skip to content

Commit ff4ed65

Browse files
authored
feat: set 'npm-auth-type' header depending on config option (#123)
1 parent 0db6cf8 commit ff4ed65

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Diff for: lib/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ function getHeaders (uri, auth, opts) {
213213
'user-agent': opts.userAgent,
214214
}, opts.headers || {})
215215

216+
if (opts.authType) {
217+
headers['npm-auth-type'] = opts.authType
218+
}
219+
216220
if (opts.scope) {
217221
headers['npm-scope'] = opts.scope
218222
}

Diff for: test/index.js

+18
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,8 @@ t.test('miscellaneous headers', t => {
473473
t.strictSame(ua, ['agent of use'], 'UA set from options'))
474474
.matchHeader('npm-command', cmd =>
475475
t.strictSame(cmd, ['hello-world'], 'command set from options'))
476+
.matchHeader('npm-auth-type', authType =>
477+
t.strictSame(authType, ['auth'], 'auth-type set from options'))
476478
.get('/hello')
477479
.reply(200, { hello: 'world' })
478480

@@ -483,6 +485,22 @@ t.test('miscellaneous headers', t => {
483485
scope: '@foo',
484486
userAgent: 'agent of use',
485487
npmCommand: 'hello-world',
488+
authType: 'auth',
489+
}).then(res => {
490+
t.equal(res.status, 200, 'got successful response')
491+
})
492+
})
493+
494+
t.test('miscellaneous headers not being set if not present in options', t => {
495+
tnock(t, defaultOpts.registry)
496+
.matchHeader('npm-auth-type', authType =>
497+
t.strictSame(authType, undefined, 'auth-type not set from options'))
498+
.get('/hello')
499+
.reply(200, { hello: 'world' })
500+
501+
return fetch('/hello', {
502+
...OPTS,
503+
authType: undefined,
486504
}).then(res => {
487505
t.equal(res.status, 200, 'got successful response')
488506
})

0 commit comments

Comments
 (0)