|
1 | 1 | const t = require('tap')
|
| 2 | + |
| 3 | +const { fake: mockNpm } = require('../../fixtures/mock-npm') |
2 | 4 | const mockGlobals = require('../../fixtures/mock-globals')
|
3 | 5 |
|
4 | 6 | const readUserInfo = {
|
5 | 7 | otp: async () => '1234',
|
6 | 8 | }
|
| 9 | +const webAuth = async (opener) => { |
| 10 | + opener() |
| 11 | + return '1234' |
| 12 | +} |
7 | 13 |
|
8 | 14 | const otplease = t.mock('../../../lib/utils/otplease.js', {
|
9 | 15 | '../../../lib/utils/read-user-info.js': readUserInfo,
|
| 16 | + '../../../lib/utils/open-url-prompt.js': () => {}, |
| 17 | + '../../../lib/utils/web-auth': webAuth, |
10 | 18 | })
|
11 | 19 |
|
12 | 20 | t.test('returns function results on success', async (t) => {
|
@@ -54,6 +62,30 @@ t.test('prompts for otp for EOTP', async (t) => {
|
54 | 62 | await otplease(null, { some: 'prop' }, fn)
|
55 | 63 | })
|
56 | 64 |
|
| 65 | +t.test('returns function results on webauth success', async (t) => { |
| 66 | + mockGlobals(t, { |
| 67 | + 'process.stdin': { isTTY: true }, |
| 68 | + 'process.stdout': { isTTY: true }, |
| 69 | + }) |
| 70 | + |
| 71 | + const npm = mockNpm({ config: { browser: 'firefox' } }) |
| 72 | + const fn = ({ otp }) => { |
| 73 | + if (otp) { |
| 74 | + return 'success' |
| 75 | + } |
| 76 | + throw Object.assign(new Error('nope'), { |
| 77 | + code: 'EOTP', |
| 78 | + body: { |
| 79 | + authUrl: 'https://www.example.com/auth', |
| 80 | + doneUrl: 'https://www.example.com/done', |
| 81 | + }, |
| 82 | + }) |
| 83 | + } |
| 84 | + |
| 85 | + const result = await otplease(npm, {}, fn) |
| 86 | + t.equal('success', result) |
| 87 | +}) |
| 88 | + |
57 | 89 | t.test('prompts for otp for 401', async (t) => {
|
58 | 90 | const stdinTTY = process.stdin.isTTY
|
59 | 91 | const stdoutTTY = process.stdout.isTTY
|
|
0 commit comments