From 71c52151c9958d42dc904754c78eda24b72aa043 Mon Sep 17 00:00:00 2001 From: Ruy Adorno Date: Tue, 10 Nov 2020 15:27:59 -0500 Subject: [PATCH] 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 --- lib/utils/config.js | 2 ++ lib/utils/flat-options.js | 1 + .../test-lib-utils-config.js-TAP.test.js | 15 +++++++++++++++ .../test-lib-utils-flat-options.js-TAP.test.js | 1 + test/lib/utils/flat-options.js | 12 ++++++++++++ 5 files changed, 31 insertions(+) diff --git a/lib/utils/config.js b/lib/utils/config.js index f9de6e9a79220..6abb502e20572 100644 --- a/lib/utils/config.js +++ b/lib/utils/config.js @@ -52,6 +52,7 @@ const defaults = { 'always-auth': false, audit: true, 'audit-level': null, + _auth: null, 'auth-type': 'legacy', before: null, 'bin-links': true, @@ -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], diff --git a/lib/utils/flat-options.js b/lib/utils/flat-options.js index be62c5a4cdb58..8b6864aa823ff 100644 --- a/lib/utils/flat-options.js +++ b/lib/utils/flat-options.js @@ -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'], diff --git a/tap-snapshots/test-lib-utils-config.js-TAP.test.js b/tap-snapshots/test-lib-utils-config.js-TAP.test.js index 5190a5604a240..3bdf905d869e6 100644 --- a/tap-snapshots/test-lib-utils-config.js-TAP.test.js +++ b/tap-snapshots/test-lib-utils-config.js-TAP.test.js @@ -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, @@ -267,6 +268,10 @@ Object { ], }, "types": Object { + "_auth": Array [ + null, + "{String TYPE}", + ], "access": Array [ null, "restricted", @@ -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, @@ -796,6 +802,10 @@ Object { ], }, "types": Object { + "_auth": Array [ + null, + "{String TYPE}", + ], "access": Array [ null, "restricted", @@ -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, @@ -1325,6 +1336,10 @@ Object { ], }, "types": Object { + "_auth": Array [ + null, + "{String TYPE}", + ], "access": Array [ null, "restricted", diff --git a/tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js b/tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js index 0e6c053b2f452..6890338a13111 100644 --- a/tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js +++ b/tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js @@ -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", diff --git a/test/lib/utils/flat-options.js b/test/lib/utils/flat-options.js index d3b8b89bc865a..7601c78d27a28 100644 --- a/test/lib/utils/flat-options.js +++ b/test/lib/utils/flat-options.js @@ -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,