From d0cef407793e384548b738ceee629195776a80cd Mon Sep 17 00:00:00 2001 From: Nathan Fritz Date: Mon, 11 Jul 2022 16:47:40 -0700 Subject: [PATCH] feat: warn on config --auth-type=sso/saml/oauth, undeprecate --auth-type --- docs/content/commands/npm-adduser.md | 7 +++-- docs/content/using-npm/config.md | 29 ++++++++++--------- lib/utils/config/definitions.js | 15 +++++++++- .../test/lib/commands/adduser.js.test.cjs | 17 +++++++++++ .../lib/utils/config/definitions.js.test.cjs | 7 +++-- .../lib/utils/config/describe-all.js.test.cjs | 29 ++++++++++--------- test/lib/commands/adduser.js | 9 ++++++ 7 files changed, 78 insertions(+), 35 deletions(-) create mode 100644 tap-snapshots/test/lib/commands/adduser.js.test.cjs diff --git a/docs/content/commands/npm-adduser.md b/docs/content/commands/npm-adduser.md index 9f7caeb9cdc90..e039ca7b970ef 100644 --- a/docs/content/commands/npm-adduser.md +++ b/docs/content/commands/npm-adduser.md @@ -94,10 +94,11 @@ npm init --scope=@foo --yes * Default: "legacy" * Type: "legacy", "webauthn", "sso", "saml", or "oauth" -* DEPRECATED: The SSO/SAML/OAuth methods are deprecated and will be removed in - a future version of npm in favor of web-based login. -What authentication strategy to use with `adduser`/`login`. +DEPRECATED: values "sso", "saml", and "oauth" will be removed in a future +version. + +What authentication strategy to use with `login`. Pass `webauthn` to use a web-based login. diff --git a/docs/content/using-npm/config.md b/docs/content/using-npm/config.md index 3fb431402669f..06b49c01516c8 100644 --- a/docs/content/using-npm/config.md +++ b/docs/content/using-npm/config.md @@ -215,6 +215,21 @@ exit code. +#### `auth-type` + +* Default: "legacy" +* Type: "legacy", "webauthn", "sso", "saml", or "oauth" + +DEPRECATED: values "sso", "saml", and "oauth" will be removed in a future +version. + +What authentication strategy to use with `login`. + +Pass `webauthn` to use a web-based login. + + + + #### `before` * Default: null @@ -1905,20 +1920,6 @@ When set to `dev` or `development`, this is an alias for `--include=dev`. -#### `auth-type` - -* Default: "legacy" -* Type: "legacy", "webauthn", "sso", "saml", or "oauth" -* DEPRECATED: The SSO/SAML/OAuth methods are deprecated and will be removed in - a future version of npm in favor of web-based login. - -What authentication strategy to use with `adduser`/`login`. - -Pass `webauthn` to use a web-based login. - - - - #### `cache-max` * Default: Infinity diff --git a/lib/utils/config/definitions.js b/lib/utils/config/definitions.js index f58a26768f551..763fd7388e1a1 100644 --- a/lib/utils/config/definitions.js +++ b/lib/utils/config/definitions.js @@ -3,6 +3,7 @@ module.exports = definitions const Definition = require('./definition.js') +const log = require('../log-shim') const { version: npmVersion } = require('../../../package.json') const ciDetect = require('@npmcli/ci-detect') const ciName = ciDetect() @@ -239,12 +240,24 @@ define('audit-level', { define('auth-type', { default: 'legacy', type: ['legacy', 'webauthn', 'sso', 'saml', 'oauth'], + // deprecation in description rather than field, because not every value + // is deprecated description: ` + DEPRECATED: values "sso", "saml", and "oauth" will be removed in a future version. + What authentication strategy to use with \`login\`. Pass \`webauthn\` to use a web-based login. `, - flatten, + flatten (key, obj, flatOptions) { + flatOptions.authType = obj[key] + if (obj[key] === 'sso') { + // no need to deprecate saml/oauth here, as sso-type will be set by these in + // lib/auth/ and is deprecated already + log.warn('config', + `auth-type=sso is deprecated and will be removed in a future version.`) + } + }, }) define('before', { diff --git a/tap-snapshots/test/lib/commands/adduser.js.test.cjs b/tap-snapshots/test/lib/commands/adduser.js.test.cjs new file mode 100644 index 0000000000000..0938e8b3fb819 --- /dev/null +++ b/tap-snapshots/test/lib/commands/adduser.js.test.cjs @@ -0,0 +1,17 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/lib/commands/adduser.js TAP auth-type sso warning > warning 1`] = ` +Object { + "warn": Array [ + Array [ + "config", + "auth-type=sso is deprecated and will be removed in a future version.", + ], + ], +} +` diff --git a/tap-snapshots/test/lib/utils/config/definitions.js.test.cjs b/tap-snapshots/test/lib/utils/config/definitions.js.test.cjs index 19909d8c5b35d..81a2ba5b4d4bf 100644 --- a/tap-snapshots/test/lib/utils/config/definitions.js.test.cjs +++ b/tap-snapshots/test/lib/utils/config/definitions.js.test.cjs @@ -254,10 +254,11 @@ exports[`test/lib/utils/config/definitions.js TAP > config description for auth- * Default: "legacy" * Type: "legacy", "webauthn", "sso", "saml", or "oauth" -* DEPRECATED: The SSO/SAML/OAuth methods are deprecated and will be removed in - a future version of npm in favor of web-based login. -What authentication strategy to use with \`adduser\`/\`login\`. +DEPRECATED: values "sso", "saml", and "oauth" will be removed in a future +version. + +What authentication strategy to use with \`login\`. Pass \`webauthn\` to use a web-based login. ` diff --git a/tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs b/tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs index 9d95aa9528bd8..c535b76b4c401 100644 --- a/tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs +++ b/tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs @@ -88,6 +88,21 @@ exit code. +#### \`auth-type\` + +* Default: "legacy" +* Type: "legacy", "webauthn", "sso", "saml", or "oauth" + +DEPRECATED: values "sso", "saml", and "oauth" will be removed in a future +version. + +What authentication strategy to use with \`login\`. + +Pass \`webauthn\` to use a web-based login. + + + + #### \`before\` * Default: null @@ -1778,20 +1793,6 @@ When set to \`dev\` or \`development\`, this is an alias for \`--include=dev\`. -#### \`auth-type\` - -* Default: "legacy" -* Type: "legacy", "webauthn", "sso", "saml", or "oauth" -* DEPRECATED: The SSO/SAML/OAuth methods are deprecated and will be removed in - a future version of npm in favor of web-based login. - -What authentication strategy to use with \`adduser\`/\`login\`. - -Pass \`webauthn\` to use a web-based login. - - - - #### \`cache-max\` * Default: Infinity diff --git a/test/lib/commands/adduser.js b/test/lib/commands/adduser.js index ca07199b2c9fb..7c7079394f132 100644 --- a/test/lib/commands/adduser.js +++ b/test/lib/commands/adduser.js @@ -75,6 +75,15 @@ t.test('bad auth type', async t => { }) }) +t.test('auth-type sso warning', async t => { + const { logs } = await loadMockNpm(t, { + config: { + 'auth-type': 'sso', + }, + }) + t.matchSnapshot({ warn: logs.warn }, 'warning') +}) + t.test('scoped login', async t => { const stdin = new stream.PassThrough() stdin.write('test-user\n')