Skip to content

Commit 71c5215

Browse files
ruyadornodarcyclarke
authored andcommitted
fix: legacy auth tokens
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
1 parent 823f99d commit 71c5215

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

lib/utils/config.js

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const defaults = {
5252
'always-auth': false,
5353
audit: true,
5454
'audit-level': null,
55+
_auth: null,
5556
'auth-type': 'legacy',
5657
before: null,
5758
'bin-links': true,
@@ -191,6 +192,7 @@ const types = {
191192
all: Boolean,
192193
'allow-same-version': Boolean,
193194
also: [null, 'dev', 'development'],
195+
_auth: [null, String],
194196
'always-auth': Boolean,
195197
audit: Boolean,
196198
'audit-level': ['low', 'moderate', 'high', 'critical', 'none', null],

lib/utils/flat-options.js

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const flatten = obj => ({
5050
alwaysAuth: obj['always-auth'],
5151
audit: obj.audit,
5252
auditLevel: obj['audit-level'],
53+
_auth: obj._auth,
5354
authType: obj['auth-type'],
5455
ssoType: obj['sso-type'],
5556
ssoPollFrequency: obj['sso-poll-frequency'],

tap-snapshots/test-lib-utils-config.js-TAP.test.js

+15
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
exports[`test/lib/utils/config.js TAP no process.umask() method > must match snapshot 1`] = `
99
Object {
1010
"defaults": Object {
11+
"_auth": null,
1112
"access": null,
1213
"all": false,
1314
"allow-same-version": false,
@@ -267,6 +268,10 @@ Object {
267268
],
268269
},
269270
"types": Object {
271+
"_auth": Array [
272+
null,
273+
"{String TYPE}",
274+
],
270275
"access": Array [
271276
null,
272277
"restricted",
@@ -537,6 +542,7 @@ Object {
537542
exports[`test/lib/utils/config.js TAP no working network interfaces, on windows > must match snapshot 1`] = `
538543
Object {
539544
"defaults": Object {
545+
"_auth": null,
540546
"access": null,
541547
"all": false,
542548
"allow-same-version": false,
@@ -796,6 +802,10 @@ Object {
796802
],
797803
},
798804
"types": Object {
805+
"_auth": Array [
806+
null,
807+
"{String TYPE}",
808+
],
799809
"access": Array [
800810
null,
801811
"restricted",
@@ -1066,6 +1076,7 @@ Object {
10661076
exports[`test/lib/utils/config.js TAP working network interfaces, not windows > must match snapshot 1`] = `
10671077
Object {
10681078
"defaults": Object {
1079+
"_auth": null,
10691080
"access": null,
10701081
"all": false,
10711082
"allow-same-version": false,
@@ -1325,6 +1336,10 @@ Object {
13251336
],
13261337
},
13271338
"types": Object {
1339+
"_auth": Array [
1340+
null,
1341+
"{String TYPE}",
1342+
],
13281343
"access": Array [
13291344
null,
13301345
"restricted",

tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
'use strict'
88
exports[`test/lib/utils/flat-options.js TAP basic > flat options 1`] = `
99
Object {
10+
"_auth": undefined,
1011
"@scope:registry": "@scope:registry",
1112
"//nerf.dart:_authToken": "//nerf.dart:_authToken",
1213
"access": "access",

test/lib/utils/flat-options.js

+12
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,18 @@ t.test('various default values and falsey fallbacks', t => {
291291
t.end()
292292
})
293293

294+
t.test('legacy _auth token', t => {
295+
const npm = new Mocknpm({
296+
_auth: 'asdfasdf',
297+
})
298+
t.strictSame(
299+
flatOptions(npm)._auth,
300+
'asdfasdf',
301+
'should set legacy _auth token',
302+
)
303+
t.end()
304+
})
305+
294306
t.test('save-type', t => {
295307
const base = {
296308
'save-optional': false,

0 commit comments

Comments
 (0)