mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
PR-URL: https://github.com/nodejs/node/pull/46193 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
34 lines
941 B
JavaScript
34 lines
941 B
JavaScript
const t = require('tap')
|
|
const tmock = require('../../fixtures/tmock')
|
|
|
|
const webAuthCheckLogin = async () => {
|
|
return { token: 'otp-token' }
|
|
}
|
|
|
|
const webauth = tmock(t, '{LIB}/utils/web-auth.js', {
|
|
'npm-profile': { webAuthCheckLogin },
|
|
})
|
|
|
|
const initialUrl = 'https://example.com/auth'
|
|
const doneUrl = 'https://example.com/done'
|
|
const opts = {}
|
|
|
|
t.test('returns token on success', async (t) => {
|
|
const opener = async () => {}
|
|
const result = await webauth(opener, initialUrl, doneUrl, opts)
|
|
t.equal(result, 'otp-token')
|
|
})
|
|
|
|
t.test('closes opener when auth check finishes', async (t) => {
|
|
const opener = (_url, emitter) => {
|
|
return new Promise((resolve, reject) => {
|
|
// the only way to finish this promise is to emit aboter on the emitter
|
|
emitter.addListener('abort', () => {
|
|
resolve()
|
|
})
|
|
})
|
|
}
|
|
const result = await webauth(opener, initialUrl, doneUrl, opts)
|
|
t.equal(result, 'otp-token')
|
|
})
|