fix: skip redacting urls meant for opening by the user (#8614) · npm/cli@f6028e6 · GitHub
Skip to content

Commit f6028e6

Browse files
fix: skip redacting urls meant for opening by the user (#8614)
Login urls have tokens in them and need to be shown to the user on stdout, especially if they have no browser and need to copy/paste. This builds off of #8587 and changes things to use proc-log's META notation, which is how this kind of info is sent. --------- Co-authored-by: Jolyn <jolyndenning@gmail.com>
1 parent 54fd27f commit f6028e6

5 files changed

Lines changed: 13 additions & 8 deletions

File tree

lib/utils/display.js

Lines changed: 2 additions & 2 deletions

lib/utils/format.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ function STRIP_C01 (str) {
4141
return result
4242
}
4343

44-
const formatWithOptions = ({ prefix: prefixes = [], eol = '\n', ...options }, ...args) => {
44+
const formatWithOptions = ({ prefix: prefixes = [], eol = '\n', redact = true, ...options }, ...args) => {
4545
const prefix = prefixes.filter(p => p != null).join(' ')
46-
const formatted = redactLog(STRIP_C01(baseFormatWithOptions(options, ...args)))
46+
let formatted = STRIP_C01(baseFormatWithOptions(options, ...args))
47+
if (redact) {
48+
formatted = redactLog(formatted)
49+
}
4750
// Splitting could be changed to only `\n` once we are sure we only emit unix newlines.
4851
// The eol param to this function will put the correct newlines in place for the returned string.
4952
const lines = formatted.split(/\r?\n/)

lib/utils/open-url.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { open } = require('@npmcli/promise-spawn')
2-
const { output, input } = require('proc-log')
2+
const { output, input, META } = require('proc-log')
33
const { URL } = require('node:url')
44
const readline = require('node:readline/promises')
55
const { once } = require('node:events')
@@ -18,7 +18,8 @@ const outputMsg = (json, title, url) => {
1818
if (json) {
1919
output.buffer({ title, url })
2020
} else {
21-
output.standard(`${title}:\n${url}`)
21+
// These urls are sometimes specifically login urls so we have to turn off redaction to standard output
22+
output.standard(`${title}:\n${url}`, { [META]: true, redact: false })
2223
}
2324
}
2425

mock-registry/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ class MockRegistry {
284284

285285
weblogin ({ token = 'npm_default-test-token' }) {
286286
const doneUrl = new URL('/npm-cli-test/done', this.origin).href
287-
const loginUrl = new URL('/npm-cli-test/login', this.origin).href
287+
const loginUrl = new URL('/npm-cli-test/login/cli/00000000-0000-0000-0000-000000000000', this.origin).href
288288
this.nock = this.nock
289289
.post(this.fullPath('/-/v1/login'), () => {
290290
return true

test/lib/commands/login.js

Lines changed: 2 additions & 1 deletion

0 commit comments

Comments
 (0)