Skip to content

Commit

Permalink
fix: send proper otp token on web auth (#7545)
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed May 20, 2024
1 parent b1db070 commit 9e6686b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/utils/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const otplease = async (npm, opts, fn) => {

// web otp
if (err.code === 'EOTP' && err.body?.authUrl && err.body?.doneUrl) {
const otp = await webAuthOpener(
const { token: otp } = await webAuthOpener(
createOpener(npm, 'Authenticate your account at'),
err.body.authUrl,
err.body.doneUrl,
Expand Down
21 changes: 11 additions & 10 deletions test/lib/utils/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const t = require('tap')
const setupMockNpm = require('../../fixtures/mock-npm')
const tmock = require('../../fixtures/tmock')

// TODO make this real and not a mock
const setupOtplease = async (t, { otp = {}, ...rest }, fn) => {
const { otplease } = tmock(t, '{LIB}/utils/auth.js', {
'{LIB}/utils/read-user-info.js': {
Expand All @@ -13,7 +14,7 @@ const setupOtplease = async (t, { otp = {}, ...rest }, fn) => {
'npm-profile': {
webAuthOpener: async (opener) => {
opener()
return '1234'
return { token: '1234' }
},
},
})
Expand Down Expand Up @@ -67,16 +68,16 @@ t.test('prompts for otp for EOTP', async (t) => {

t.test('returns function results on webauth success', async (t) => {
const fn = ({ otp }) => {
if (otp) {
return 'success'
if (!otp) {
throw Object.assign(new Error('nope'), {
code: 'EOTP',
body: {
authUrl: 'https://www.example.com/auth',
doneUrl: 'https://www.example.com/done',
},
})
}
throw Object.assign(new Error('nope'), {
code: 'EOTP',
body: {
authUrl: 'https://www.example.com/auth',
doneUrl: 'https://www.example.com/done',
},
})
return 'success'
}

const result = await setupOtplease(t, {
Expand Down

0 comments on commit 9e6686b

Please # to comment.