Skip to content

Commit

Permalink
fix: legacy auth tokens
Browse files Browse the repository at this point in the history
Add legacy `_auth` token to flatOptions in order to support it when
reaching out to registries.

Fixes: #2008

Credit: @ruyadorno
Close: #2153
Reviewed-by: @isaacs
  • Loading branch information
ruyadorno authored and darcyclarke committed Nov 13, 2020
1 parent 823f99d commit 71c5215
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const defaults = {
'always-auth': false,
audit: true,
'audit-level': null,
_auth: null,
'auth-type': 'legacy',
before: null,
'bin-links': true,
Expand Down Expand Up @@ -191,6 +192,7 @@ const types = {
all: Boolean,
'allow-same-version': Boolean,
also: [null, 'dev', 'development'],
_auth: [null, String],
'always-auth': Boolean,
audit: Boolean,
'audit-level': ['low', 'moderate', 'high', 'critical', 'none', null],
Expand Down
1 change: 1 addition & 0 deletions lib/utils/flat-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const flatten = obj => ({
alwaysAuth: obj['always-auth'],
audit: obj.audit,
auditLevel: obj['audit-level'],
_auth: obj._auth,
authType: obj['auth-type'],
ssoType: obj['sso-type'],
ssoPollFrequency: obj['sso-poll-frequency'],
Expand Down
15 changes: 15 additions & 0 deletions tap-snapshots/test-lib-utils-config.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
exports[`test/lib/utils/config.js TAP no process.umask() method > must match snapshot 1`] = `
Object {
"defaults": Object {
"_auth": null,
"access": null,
"all": false,
"allow-same-version": false,
Expand Down Expand Up @@ -267,6 +268,10 @@ Object {
],
},
"types": Object {
"_auth": Array [
null,
"{String TYPE}",
],
"access": Array [
null,
"restricted",
Expand Down Expand Up @@ -537,6 +542,7 @@ Object {
exports[`test/lib/utils/config.js TAP no working network interfaces, on windows > must match snapshot 1`] = `
Object {
"defaults": Object {
"_auth": null,
"access": null,
"all": false,
"allow-same-version": false,
Expand Down Expand Up @@ -796,6 +802,10 @@ Object {
],
},
"types": Object {
"_auth": Array [
null,
"{String TYPE}",
],
"access": Array [
null,
"restricted",
Expand Down Expand Up @@ -1066,6 +1076,7 @@ Object {
exports[`test/lib/utils/config.js TAP working network interfaces, not windows > must match snapshot 1`] = `
Object {
"defaults": Object {
"_auth": null,
"access": null,
"all": false,
"allow-same-version": false,
Expand Down Expand Up @@ -1325,6 +1336,10 @@ Object {
],
},
"types": Object {
"_auth": Array [
null,
"{String TYPE}",
],
"access": Array [
null,
"restricted",
Expand Down
1 change: 1 addition & 0 deletions tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'use strict'
exports[`test/lib/utils/flat-options.js TAP basic > flat options 1`] = `
Object {
"_auth": undefined,
"@scope:registry": "@scope:registry",
"//nerf.dart:_authToken": "//nerf.dart:_authToken",
"access": "access",
Expand Down
12 changes: 12 additions & 0 deletions test/lib/utils/flat-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,18 @@ t.test('various default values and falsey fallbacks', t => {
t.end()
})

t.test('legacy _auth token', t => {
const npm = new Mocknpm({
_auth: 'asdfasdf',
})
t.strictSame(
flatOptions(npm)._auth,
'asdfasdf',
'should set legacy _auth token',
)
t.end()
})

t.test('save-type', t => {
const base = {
'save-optional': false,
Expand Down

0 comments on commit 71c5215

Please sign in to comment.