Skip to content

Commit

Permalink
fix(logout): use isBasicAuth attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
ruyadorno authored and wraithgar committed Apr 22, 2021
1 parent 83166eb commit cb2ed46
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Logout extends BaseCommand {
method: 'DELETE',
ignoreBody: true,
})
} else if (auth.username || auth.password)
} else if (auth.isBasicAuth)
log.verbose('logout', `clearing user credentials for ${reg}`)
else {
const msg = `not logged in to ${reg}, so can't log out!`
Expand Down
31 changes: 17 additions & 14 deletions test/lib/logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const logout = new Logout(npm)
t.test('token logout', async (t) => {
t.plan(6)

flatOptions.token = '@foo/'
flatOptions['//registry.npmjs.org/:_authToken'] = '@foo/'

npmlog.verbose = (title, msg) => {
t.equal(title, 'logout', 'should have correcct log prefix')
Expand Down Expand Up @@ -63,7 +63,7 @@ t.test('token logout', async (t) => {
opts: {
registry: 'https://registry.npmjs.org/',
scope: '',
token: '@foo/',
'//registry.npmjs.org/:_authToken': '@foo/',
method: 'DELETE',
ignoreBody: true,
},
Expand All @@ -87,7 +87,8 @@ t.test('token logout', async (t) => {
t.test('token scoped logout', async (t) => {
t.plan(8)

flatOptions.token = '@foo/'
flatOptions['//diff-registry.npmjs.com/:_authToken'] = '@bar/'
flatOptions['//registry.npmjs.org/:_authToken'] = '@foo/'
config.scope = '@myscope'
config['@myscope:registry'] = 'https://diff-registry.npmjs.com/'
flatOptions.scope = '@myscope'
Expand Down Expand Up @@ -130,12 +131,13 @@ t.test('token scoped logout', async (t) => {
t.same(
result,
{
url: '/-/user/token/%40foo%2F',
url: '/-/user/token/%40bar%2F',
opts: {
registry: 'https://registry.npmjs.org/',
'@myscope:registry': 'https://diff-registry.npmjs.com/',
scope: '@myscope',
token: '@foo/',
'//registry.npmjs.org/:_authToken': '@foo/', // <- removed by npm-registry-fetch
'//diff-registry.npmjs.com/:_authToken': '@bar/',
method: 'DELETE',
ignoreBody: true,
},
Expand All @@ -144,8 +146,10 @@ t.test('token scoped logout', async (t) => {
)

config.scope = ''
delete flatOptions['//diff-registry.npmjs.com/:_authToken']
delete flatOptions['//registry.npmjs.org/:_authToken']
delete config['@myscope:registry']
delete flatOptions.token
delete flatOptions.scope
result = null
mocks['npm-registry-fetch'] = null
config.clearCredentialsByURI = null
Expand All @@ -161,11 +165,11 @@ t.test('token scoped logout', async (t) => {
t.test('user/pass logout', async (t) => {
t.plan(3)

flatOptions.username = 'foo'
flatOptions.password = 'bar'
flatOptions['//registry.npmjs.org/:username'] = 'foo'
flatOptions['//registry.npmjs.org/:_password'] = 'bar'

npmlog.verbose = (title, msg) => {
t.equal(title, 'logout', 'should have correcct log prefix')
t.equal(title, 'logout', 'should have correct log prefix')
t.equal(
msg,
'clearing user credentials for https://registry.npmjs.org/',
Expand All @@ -180,8 +184,8 @@ t.test('user/pass logout', async (t) => {
logout.exec([], (err) => {
t.error(err, 'should not error out')

delete flatOptions.username
delete flatOptions.password
delete flatOptions['//registry.npmjs.org/:username']
delete flatOptions['//registry.npmjs.org/:_password']
npm.config.clearCredentialsByURI = null
npm.config.save = null
npmlog.verbose = null
Expand All @@ -206,7 +210,7 @@ t.test('missing credentials', (t) => {
t.test('ignore invalid scoped registry config', async (t) => {
t.plan(5)

flatOptions.token = '@foo/'
flatOptions['//registry.npmjs.org/:_authToken'] = '@foo/'
config.scope = '@myscope'
flatOptions['@myscope:registry'] = ''

Expand Down Expand Up @@ -239,10 +243,9 @@ t.test('ignore invalid scoped registry config', async (t) => {
{
url: '/-/user/token/%40foo%2F',
opts: {
'//registry.npmjs.org/:_authToken': '@foo/',
registry: 'https://registry.npmjs.org/',
scope: '@myscope',
'@myscope:registry': '',
token: '@foo/',
method: 'DELETE',
ignoreBody: true,
},
Expand Down

0 comments on commit cb2ed46

Please sign in to comment.