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

Warn adduser changes, undeprecate --auth-type, but warn for some values #5149

Merged
merged 2 commits into from Jul 12, 2022
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
7 changes: 4 additions & 3 deletions docs/content/commands/npm-adduser.md
Expand Up @@ -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`.
NOTE: auth-type 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.

Expand Down
29 changes: 15 additions & 14 deletions docs/content/using-npm/config.md
Expand Up @@ -215,6 +215,21 @@ exit code.
<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

#### `auth-type`

* Default: "legacy"
* Type: "legacy", "webauthn", "sso", "saml", or "oauth"

NOTE: auth-type 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.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

#### `before`

* Default: null
Expand Down Expand Up @@ -1905,20 +1920,6 @@ When set to `dev` or `development`, this is an alias for `--include=dev`.
<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

#### `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.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

#### `cache-max`

* Default: Infinity
Expand Down
4 changes: 4 additions & 0 deletions lib/commands/adduser.js
Expand Up @@ -28,6 +28,10 @@ class AddUser extends BaseCommand {

log.disableProgress()

log.warn('adduser',
'`adduser` will be split into `login` and `register in a future version.'
+ ' `adduser` will become an alias of `register`.'
+ ' `login` (currently an alias) will become its own command.')
log.notice('', `Log in on ${replaceInfo(registry)}`)

const { message, newCreds } = await auth(this.npm, {
Expand Down
21 changes: 15 additions & 6 deletions lib/utils/config/definitions.js
Expand Up @@ -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()
Expand Down Expand Up @@ -239,16 +240,24 @@ define('audit-level', {
define('auth-type', {
default: 'legacy',
type: ['legacy', 'webauthn', 'sso', 'saml', '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.
`,
// deprecation in description rather than field, because not every value
// is deprecated
description: `
What authentication strategy to use with \`adduser\`/\`login\`.
NOTE: auth-type 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 will be removed in a future version.')
}
},
})

define('before', {
Expand Down
17 changes: 17 additions & 0 deletions 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 will be removed in a future version.",
],
],
}
`
7 changes: 4 additions & 3 deletions tap-snapshots/test/lib/utils/config/definitions.js.test.cjs
Expand Up @@ -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\`.
NOTE: auth-type 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.
`
Expand Down
29 changes: 15 additions & 14 deletions tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs
Expand Up @@ -88,6 +88,21 @@ exit code.
<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

#### \`auth-type\`

* Default: "legacy"
* Type: "legacy", "webauthn", "sso", "saml", or "oauth"

NOTE: auth-type 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.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

#### \`before\`

* Default: null
Expand Down Expand Up @@ -1778,20 +1793,6 @@ When set to \`dev\` or \`development\`, this is an alias for \`--include=dev\`.
<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

#### \`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.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

#### \`cache-max\`

* Default: Infinity
Expand Down
9 changes: 9 additions & 0 deletions test/lib/commands/adduser.js
Expand Up @@ -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')
Expand Down