Skip to content

Commit

Permalink
fix: remove unnecessary logging for webauthn auth
Browse files Browse the repository at this point in the history
  • Loading branch information
hfaulds committed Jun 24, 2022
1 parent 0ce09f1 commit 5c4116d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lib/auth/legacy.js
Expand Up @@ -2,6 +2,7 @@ const profile = require('npm-profile')
const log = require('../utils/log-shim')
const openUrlPrompt = require('../utils/open-url-prompt.js')
const read = require('../utils/read-user-info.js')
const replaceInfo = require('../utils/replace-info.js')

const loginPrompter = async (creds) => {
creds.username = await read.username('Username:', creds.username)
Expand All @@ -14,6 +15,10 @@ const loginPrompter = async (creds) => {
const login = async (npm, opts) => {
let res

if (opts.authType === 'legacy') {
log.notice('', `Log in on ${replaceInfo(opts.registry)}`)
}

const requestOTP = async () => {
const otp = await read.otp(
'Enter one-time password: '
Expand Down
3 changes: 3 additions & 0 deletions lib/auth/sso.js
Expand Up @@ -12,6 +12,7 @@ const npmFetch = require('npm-registry-fetch')
const log = require('../utils/log-shim')
const openUrl = require('../utils/open-url.js')
const otplease = require('../utils/otplease.js')
const replaceInfo = require('../utils/replace-info.js')

const pollForSession = ({ registry, token, opts }) => {
log.info('adduser', 'Polling for validated SSO session')
Expand Down Expand Up @@ -39,6 +40,8 @@ const login = async (npm, { creds, registry, scope }) => {
const opts = { ...npm.flatOptions, creds, registry, scope }
const { ssoType } = opts

log.notice('', `Log in on ${replaceInfo(registry)}`)

if (!ssoType) {
throw new Error('Missing option: sso-type')
}
Expand Down
3 changes: 0 additions & 3 deletions lib/commands/adduser.js
@@ -1,5 +1,4 @@
const log = require('../utils/log-shim.js')
const replaceInfo = require('../utils/replace-info.js')
const BaseCommand = require('../base-command.js')
const authTypes = {
legacy: require('../auth/legacy.js'),
Expand Down Expand Up @@ -28,8 +27,6 @@ class AddUser extends BaseCommand {

log.disableProgress()

log.notice('', `Log in on ${replaceInfo(registry)}`)

const { message, newCreds } = await auth(this.npm, {
...this.npm.flatOptions,
creds,
Expand Down
9 changes: 8 additions & 1 deletion test/lib/auth/sso.js
Expand Up @@ -8,12 +8,17 @@ const _flatOptions = {
const token = '24528a24f240'
const SSO_URL = 'https://registry.npmjs.org/{SSO_URL}'
const profile = {}
const npmFetch = {}
const npmFetch = {
cleanUrl: (s) => s,
}
const sso = t.mock('../../../lib/auth/sso.js', {
'proc-log': {
info: (...msgs) => {
log += msgs.join(' ') + '\n'
},
notice: (...msgs) => {
log += msgs.join(' ') + '\n'
},
},
'npm-profile': profile,
'npm-registry-fetch': npmFetch,
Expand Down Expand Up @@ -82,6 +87,7 @@ t.test('simple login', async (t) => {

t.equal(
log,
' Log in on https://registry.npmjs.org/\n' +
'adduser Polling for validated SSO session\nadduser Authorized user foo\n',
'should have correct logged info msg'
)
Expand Down Expand Up @@ -220,6 +226,7 @@ t.test('scoped login', async (t) => {

t.equal(
log,
' Log in on https://diff-registry.npmjs.org/\n' +
'adduser Polling for validated SSO session\nadduser Authorized user foo\n',
'should have correct logged info msg'
)
Expand Down

0 comments on commit 5c4116d

Please sign in to comment.