Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Commit

Permalink
remove registry-specific always-auth field
Browse files Browse the repository at this point in the history
We don't actually use always-auth anymore.  There is no reason to manage
it as part of the registry-specific auth keys.
  • Loading branch information
isaacs committed Apr 23, 2021
1 parent 9936718 commit 6a7871f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 77 deletions.
19 changes: 6 additions & 13 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ class Config {
this.delete(`${nerfed}:email`, 'user')
}

setCredentialsByURI (uri, { token, username, password, email, alwaysAuth }) {
setCredentialsByURI (uri, { token, username, password, email }) {
const nerfed = nerfDart(uri)
const def = nerfDart(this.get('registry'))

Expand All @@ -633,14 +633,18 @@ class Config {
this.set('email', email, 'user')
}

// field that hasn't been used as documented for a LONG time,
// and as of npm 7.10.0, isn't used at all. We just always
// send auth if we have it, only to the URIs under the nerf dart.
this.delete(`${nerfed}:always-auth`, 'user')

this.delete(`${nerfed}:-authtoken`, 'user')
this.delete(`${nerfed}:_authtoken`, 'user')
this.delete(`${nerfed}:email`, 'user')
if (token) {
this.set(`${nerfed}:_authToken`, token, 'user')
this.delete(`${nerfed}:_password`, 'user')
this.delete(`${nerfed}:username`, 'user')
this.delete(`${nerfed}:always-auth`, 'user')
} else if (username || password) {
if (!username)
throw new Error('must include username')
Expand All @@ -652,10 +656,6 @@ class Config {
// protects against shoulder-hacks if password is memorable, I guess?
const encoded = Buffer.from(password, 'utf8').toString('base64')
this.set(`${nerfed}:_password`, encoded, 'user')
if (alwaysAuth !== undefined)
this.set(`${nerfed}:always-auth`, alwaysAuth, 'user')
else
this.delete(`${nerfed}:always-auth`, 'user')
} else {
throw new Error('No credentials to set.')
}
Expand All @@ -666,13 +666,6 @@ class Config {
const nerfed = nerfDart(uri)
const creds = {}

// you can set always-auth for a single registry, or as a default
const alwaysAuthReg = this.get(`${nerfed}:always-auth`)
if (alwaysAuthReg !== undefined)
creds.alwaysAuth = !!alwaysAuthReg
else
creds.alwaysAuth = this.get('always-auth')

const email = this.get(`${nerfed}:email`) || this.get('email')
if (email)
creds.email = email
Expand Down
64 changes: 11 additions & 53 deletions tap-snapshots/test/index.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
'use strict'
exports[`test/index.js TAP credentials management def_auth > default registry 1`] = `
Object {
"alwaysAuth": true,
"auth": "aGVsbG86d29ybGQ=",
"password": "world",
"username": "hello",
Expand All @@ -16,50 +15,42 @@ Object {

exports[`test/index.js TAP credentials management def_auth > default registry after set 1`] = `
Object {
"alwaysAuth": true,
"auth": "aGVsbG86d29ybGQ=",
"password": "world",
"username": "hello",
}
`

exports[`test/index.js TAP credentials management def_auth > other registry 1`] = `
Object {
"alwaysAuth": true,
}
Object {}
`

exports[`test/index.js TAP credentials management def_passNoUser > default registry 1`] = `
Object {
"alwaysAuth": true,
"email": "i@izs.me",
}
`

exports[`test/index.js TAP credentials management def_passNoUser > other registry 1`] = `
Object {
"alwaysAuth": false,
"email": "i@izs.me",
}
`

exports[`test/index.js TAP credentials management def_userNoPass > default registry 1`] = `
Object {
"alwaysAuth": true,
"email": "i@izs.me",
}
`

exports[`test/index.js TAP credentials management def_userNoPass > other registry 1`] = `
Object {
"alwaysAuth": false,
"email": "i@izs.me",
}
`

exports[`test/index.js TAP credentials management def_userpass > default registry 1`] = `
Object {
"alwaysAuth": true,
"auth": "aGVsbG86d29ybGQ=",
"email": "i@izs.me",
"password": "world",
Expand All @@ -69,7 +60,6 @@ Object {

exports[`test/index.js TAP credentials management def_userpass > default registry after set 1`] = `
Object {
"alwaysAuth": true,
"auth": "aGVsbG86d29ybGQ=",
"email": "i@izs.me",
"password": "world",
Expand All @@ -79,14 +69,12 @@ Object {

exports[`test/index.js TAP credentials management def_userpass > other registry 1`] = `
Object {
"alwaysAuth": false,
"email": "i@izs.me",
}
`

exports[`test/index.js TAP credentials management nerfed_auth > default registry 1`] = `
Object {
"alwaysAuth": false,
"auth": "aGVsbG86d29ybGQ=",
"password": "world",
"username": "hello",
Expand All @@ -95,62 +83,50 @@ Object {

exports[`test/index.js TAP credentials management nerfed_auth > default registry after set 1`] = `
Object {
"alwaysAuth": false,
"auth": "aGVsbG86d29ybGQ=",
"password": "world",
"username": "hello",
}
`

exports[`test/index.js TAP credentials management nerfed_auth > other registry 1`] = `
Object {
"alwaysAuth": false,
}
Object {}
`

exports[`test/index.js TAP credentials management nerfed_authToken > default registry 1`] = `
Object {
"alwaysAuth": false,
"token": "0bad1de4",
}
`

exports[`test/index.js TAP credentials management nerfed_authToken > default registry after set 1`] = `
Object {
"alwaysAuth": false,
"token": "0bad1de4",
}
`

exports[`test/index.js TAP credentials management nerfed_authToken > other registry 1`] = `
Object {
"alwaysAuth": false,
}
Object {}
`

exports[`test/index.js TAP credentials management nerfed_lcAuthToken > default registry 1`] = `
Object {
"alwaysAuth": false,
"token": "0bad1de4",
}
`

exports[`test/index.js TAP credentials management nerfed_lcAuthToken > default registry after set 1`] = `
Object {
"alwaysAuth": false,
"token": "0bad1de4",
}
`

exports[`test/index.js TAP credentials management nerfed_lcAuthToken > other registry 1`] = `
Object {
"alwaysAuth": false,
}
Object {}
`

exports[`test/index.js TAP credentials management nerfed_userpass > default registry 1`] = `
Object {
"alwaysAuth": false,
"auth": "aGVsbG86d29ybGQ=",
"email": "i@izs.me",
"password": "world",
Expand All @@ -160,7 +136,6 @@ Object {

exports[`test/index.js TAP credentials management nerfed_userpass > default registry after set 1`] = `
Object {
"alwaysAuth": false,
"auth": "aGVsbG86d29ybGQ=",
"email": "i@izs.me",
"password": "world",
Expand All @@ -170,63 +145,46 @@ Object {

exports[`test/index.js TAP credentials management nerfed_userpass > other registry 1`] = `
Object {
"alwaysAuth": false,
"email": "i@izs.me",
}
`

exports[`test/index.js TAP credentials management none_authToken > default registry 1`] = `
Object {
"alwaysAuth": false,
"token": "0bad1de4",
}
`

exports[`test/index.js TAP credentials management none_authToken > default registry after set 1`] = `
Object {
"alwaysAuth": false,
"token": "0bad1de4",
}
`

exports[`test/index.js TAP credentials management none_authToken > other registry 1`] = `
Object {
"alwaysAuth": false,
}
Object {}
`

exports[`test/index.js TAP credentials management none_emptyConfig > default registry 1`] = `
Object {
"alwaysAuth": false,
}
Object {}
`

exports[`test/index.js TAP credentials management none_emptyConfig > other registry 1`] = `
Object {
"alwaysAuth": false,
}
Object {}
`

exports[`test/index.js TAP credentials management none_lcAuthToken > default registry 1`] = `
Object {
"alwaysAuth": false,
}
Object {}
`

exports[`test/index.js TAP credentials management none_lcAuthToken > other registry 1`] = `
Object {
"alwaysAuth": false,
}
Object {}
`

exports[`test/index.js TAP credentials management none_noConfig > default registry 1`] = `
Object {
"alwaysAuth": false,
}
Object {}
`

exports[`test/index.js TAP credentials management none_noConfig > other registry 1`] = `
Object {
"alwaysAuth": false,
}
Object {}
`
15 changes: 4 additions & 11 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,6 @@ always-auth = true`,
password: 'bar',
email: 'asdf@quux.com',
})
t.equal(c.getCredentialsByURI('http://x.com').alwaysAuth, false)
}

const d = c.getCredentialsByURI(defReg)
Expand All @@ -629,9 +628,8 @@ always-auth = true`,

c.clearCredentialsByURI(defReg)
const defAfterDelete = c.getCredentialsByURI(defReg)
// we keep alwaysAuth, and MAY have email there, but nothing else.
{
const expectKeys = ['alwaysAuth']
const expectKeys = []
if (defAfterDelete.email)
expectKeys.push('email')
t.strictSame(Object.keys(defAfterDelete), expectKeys)
Expand All @@ -640,7 +638,7 @@ always-auth = true`,
c.clearCredentialsByURI(otherReg)
const otherAfterDelete = c.getCredentialsByURI(otherReg)
{
const expectKeys = ['alwaysAuth']
const expectKeys = []
if (otherAfterDelete.email)
expectKeys.push('email')
t.strictSame(Object.keys(otherAfterDelete), expectKeys)
Expand Down Expand Up @@ -786,7 +784,6 @@ t.test('setting basic auth creds and email', async t => {
argv: ['node', __filename, `--userconfig=${path}/.npmrc`],
definitions: {
registry: { default: registry },
'always-auth': { default: false },
},
npmPath: process.cwd(),
}
Expand All @@ -796,10 +793,10 @@ t.test('setting basic auth creds and email', async t => {
t.equal(c.get('email', 'user'), 'name@example.com', 'email was set')
await c.save('user')
t.equal(c.get('email', 'user'), 'name@example.com', 'email still top level')
t.strictSame(c.getCredentialsByURI(registry), { email: 'name@example.com', alwaysAuth: false })
t.strictSame(c.getCredentialsByURI(registry), { email: 'name@example.com' })
const d = new Config(opts)
await d.load()
t.strictSame(d.getCredentialsByURI(registry), { email: 'name@example.com', alwaysAuth: false })
t.strictSame(d.getCredentialsByURI(registry), { email: 'name@example.com' })
d.set('_auth', _auth, 'user')
t.equal(d.get('_auth', 'user'), _auth, '_auth was set')
await d.save('user')
Expand All @@ -809,7 +806,6 @@ t.test('setting basic auth creds and email', async t => {
username: 'admin',
password: 'admin',
auth: _auth,
alwaysAuth: false,
}, 'credentials saved and nerfed')
})

Expand All @@ -822,7 +818,6 @@ t.test('setting username/password/email individually', async t => {
argv: ['node', __filename, `--userconfig=${path}/.npmrc`],
definitions: {
registry: { default: registry },
'always-auth': { default: false },
},
npmPath: process.cwd(),
}
Expand All @@ -841,7 +836,6 @@ t.test('setting username/password/email individually', async t => {
t.equal(c.get('_password'), undefined)
t.equal(c.get('_auth'), undefined)
t.strictSame(c.getCredentialsByURI(registry), {
alwaysAuth: false,
email: 'name@example.com',
username: 'admin',
password: 'admin',
Expand All @@ -854,7 +848,6 @@ t.test('setting username/password/email individually', async t => {
t.equal(d.get('_password'), undefined)
t.equal(d.get('_auth'), undefined)
t.strictSame(d.getCredentialsByURI(registry), {
alwaysAuth: false,
email: 'name@example.com',
username: 'admin',
password: 'admin',
Expand Down

0 comments on commit 6a7871f

Please sign in to comment.