Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHayden Faulds <fauldsh@gmail.com>2022-07-13 18:05:09 +0300
committerHayden Faulds <fauldsh@gmail.com>2022-07-13 18:05:09 +0300
commita0fd462b562d86da76bce8d8d79cdf5d93f6922a (patch)
treea4be8c1edd07309bd2d3f9b41057f783126ec9f4
parent648cb04c5e9bfb8c59a0418d60e2b9b511d48150 (diff)
test webauth in otplease
-rw-r--r--test/lib/utils/otplease.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/lib/utils/otplease.js b/test/lib/utils/otplease.js
index de85fc6c5..79eaa798e 100644
--- a/test/lib/utils/otplease.js
+++ b/test/lib/utils/otplease.js
@@ -1,12 +1,20 @@
const t = require('tap')
+
+const { fake: mockNpm } = require('../../fixtures/mock-npm')
const mockGlobals = require('../../fixtures/mock-globals')
const readUserInfo = {
otp: async () => '1234',
}
+const webAuth = async (opener) => {
+ opener()
+ return '1234'
+}
const otplease = t.mock('../../../lib/utils/otplease.js', {
'../../../lib/utils/read-user-info.js': readUserInfo,
+ '../../../lib/utils/open-url-prompt.js': () => {},
+ '../../../lib/utils/web-auth': webAuth,
})
t.test('returns function results on success', async (t) => {
@@ -54,6 +62,30 @@ t.test('prompts for otp for EOTP', async (t) => {
await otplease(null, { some: 'prop' }, fn)
})
+t.test('returns function results on webauth success', async (t) => {
+ mockGlobals(t, {
+ 'process.stdin': { isTTY: true },
+ 'process.stdout': { isTTY: true },
+ })
+
+ const npm = mockNpm({ config: { browser: 'firefox' } })
+ const fn = ({ otp }) => {
+ if (otp) {
+ return 'success'
+ }
+ throw Object.assign(new Error('nope'), {
+ code: 'EOTP',
+ body: {
+ authUrl: 'https://www.example.com/auth',
+ doneUrl: 'https://www.example.com/done',
+ },
+ })
+ }
+
+ const result = await otplease(npm, {}, fn)
+ t.equal('success', result)
+})
+
t.test('prompts for otp for 401', async (t) => {
const stdinTTY = process.stdin.isTTY
const stdoutTTY = process.stdout.isTTY