Skip to content

Commit

Permalink
fix: default auth-type to legacy if otp is configured (#6044)
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Jan 12, 2023
1 parent ca8ff00 commit cf175fb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/utils/config/definitions.js
Expand Up @@ -238,6 +238,7 @@ define('auth-type', {
type: ['legacy', 'web'],
description: `
What authentication strategy to use with \`login\`.
Note that if an \`otp\` config is given, this value will always be set to \`legacy\`.
`,
flatten,
})
Expand Down Expand Up @@ -1465,7 +1466,13 @@ define('otp', {
If not set, and a registry response fails with a challenge for a one-time
password, npm will prompt on the command line for one.
`,
flatten,
flatten (key, obj, flatOptions) {
flatten(key, obj, flatOptions)
if (obj.otp) {
obj['auth-type'] = 'legacy'
flatten('auth-type', obj, flatOptions)
}
},
})

define('package', {
Expand Down
3 changes: 2 additions & 1 deletion tap-snapshots/test/lib/docs.js.test.cjs
Expand Up @@ -654,7 +654,8 @@ exit code.
* Default: "web"
* Type: "legacy" or "web"
What authentication strategy to use with \`login\`.
What authentication strategy to use with \`login\`. Note that if an \`otp\`
config is given, this value will always be set to \`legacy\`.
#### \`before\`
Expand Down
9 changes: 9 additions & 0 deletions test/lib/utils/config/definitions.js
Expand Up @@ -931,3 +931,12 @@ t.test('remap global-style', t => {
t.strictSame(flat, { installStrategy: 'shallow' })
t.end()
})

t.test('otp changes auth-type', t => {
const obj = { 'auth-type': 'web', otp: 123456 }
const flat = {}
mockDefs().otp.flatten('otp', obj, flat)
t.strictSame(flat, { authType: 'legacy', otp: 123456 })
t.strictSame(obj, { 'auth-type': 'legacy', otp: 123456 })
t.end()
})

0 comments on commit cf175fb

Please sign in to comment.