Skip to content

Commit

Permalink
feat: set 'npm-auth-type' header depending on config option (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
jumoel committed Jun 25, 2022
1 parent 0db6cf8 commit ff4ed65
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/index.js
Expand Up @@ -213,6 +213,10 @@ function getHeaders (uri, auth, opts) {
'user-agent': opts.userAgent,
}, opts.headers || {})

if (opts.authType) {
headers['npm-auth-type'] = opts.authType
}

if (opts.scope) {
headers['npm-scope'] = opts.scope
}
Expand Down
18 changes: 18 additions & 0 deletions test/index.js
Expand Up @@ -473,6 +473,8 @@ t.test('miscellaneous headers', t => {
t.strictSame(ua, ['agent of use'], 'UA set from options'))
.matchHeader('npm-command', cmd =>
t.strictSame(cmd, ['hello-world'], 'command set from options'))
.matchHeader('npm-auth-type', authType =>
t.strictSame(authType, ['auth'], 'auth-type set from options'))
.get('/hello')
.reply(200, { hello: 'world' })

Expand All @@ -483,6 +485,22 @@ t.test('miscellaneous headers', t => {
scope: '@foo',
userAgent: 'agent of use',
npmCommand: 'hello-world',
authType: 'auth',
}).then(res => {
t.equal(res.status, 200, 'got successful response')
})
})

t.test('miscellaneous headers not being set if not present in options', t => {
tnock(t, defaultOpts.registry)
.matchHeader('npm-auth-type', authType =>
t.strictSame(authType, undefined, 'auth-type not set from options'))
.get('/hello')
.reply(200, { hello: 'world' })

return fetch('/hello', {
...OPTS,
authType: undefined,
}).then(res => {
t.equal(res.status, 200, 'got successful response')
})
Expand Down

0 comments on commit ff4ed65

Please sign in to comment.