Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(error-message): clean urls from 404 error #3732

Merged
merged 1 commit into from Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/utils/error-message.js
Expand Up @@ -181,7 +181,7 @@ module.exports = (er, npm) => {
const pkg = er.pkgid.replace(/(?!^)@.*$/, '')

detail.push(['404', ''])
detail.push(['404', '', "'" + er.pkgid + "' is not in the npm registry."])
detail.push(['404', '', `'${replaceInfo(er.pkgid)}' is not in this registry.`])

const valResult = nameValidator(pkg)

Expand Down
48 changes: 45 additions & 3 deletions tap-snapshots/test/lib/utils/error-message.js.test.cjs
Expand Up @@ -5,6 +5,48 @@
* Make sure to inspect the output below. Do not ignore changes!
*/
'use strict'
exports[`test/lib/utils/error-message.js TAP 404 cleans sensitive info from package id > must match snapshot 1`] = `
Object {
"detail": Array [
Array [
"404",
"",
],
Array [
"404",
"",
"'http://evil:***@npmjs.org/not-found' is not in this registry.",
],
Array [
"404",
"This package name is not valid, because",
"",
],
Array [
"404",
" 1. name can only contain URL-friendly characters",
],
Array [
"404",
String(

Note that you can also install from a
),
],
Array [
"404",
"tarball, folder, http url, or git url.",
],
],
"summary": Array [
Array [
"404",
"not found",
],
],
}
`

exports[`test/lib/utils/error-message.js TAP 404 name with error > must match snapshot 1`] = `
Object {
"detail": Array [
Expand All @@ -15,7 +57,7 @@ Object {
Array [
"404",
"",
"'node_modules' is not in the npm registry.",
"'node_modules' is not in this registry.",
],
Array [
"404",
Expand Down Expand Up @@ -57,7 +99,7 @@ Object {
Array [
"404",
"",
"'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' is not in the npm registry.",
"'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' is not in this registry.",
],
Array [
"404",
Expand Down Expand Up @@ -111,7 +153,7 @@ Object {
Array [
"404",
"",
"'yolo' is not in the npm registry.",
"'yolo' is not in this registry.",
],
Array [
"404",
Expand Down
8 changes: 8 additions & 0 deletions test/lib/utils/error-message.js
Expand Up @@ -423,6 +423,14 @@ t.test('404', t => {
t.matchSnapshot(errorMessage(er, npm))
t.end()
})
t.test('cleans sensitive info from package id', t => {
const er = Object.assign(new Error('404 not found'), {
pkgid: 'http://evil:password@npmjs.org/not-found',
code: 'E404',
})
t.matchSnapshot(errorMessage(er, npm))
t.end()
})
t.end()
})

Expand Down