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 6ba885f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 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
Empty file added lib/auth/webauthn.js
Empty file.
5 changes: 1 addition & 4 deletions lib/commands/adduser.js
@@ -1,9 +1,8 @@
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'),
webauthn: require('../auth/legacy.js'),
webauthn: require('../auth/webauthn.js'),
oauth: require('../auth/oauth.js'),
saml: require('../auth/saml.js'),
sso: require('../auth/sso.js'),
Expand All @@ -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
11 changes: 8 additions & 3 deletions 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,7 +87,7 @@ t.test('simple login', async (t) => {

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

Expand Down Expand Up @@ -220,7 +225,7 @@ t.test('scoped login', async (t) => {

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

Expand Down

0 comments on commit 6ba885f

Please sign in to comment.