Skip to content

Commit 1c4eff7

Browse files
ruyadornowraithgar
authored andcommitted
fix(logout): use isBasicAuth attribute
PR-URL: #3126 Credit: @wraithgar Close: #3126 Reviewed-by: @darcyclarke
1 parent 83166eb commit 1c4eff7

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

lib/logout.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Logout extends BaseCommand {
4141
method: 'DELETE',
4242
ignoreBody: true,
4343
})
44-
} else if (auth.username || auth.password)
44+
} else if (auth.isBasicAuth)
4545
log.verbose('logout', `clearing user credentials for ${reg}`)
4646
else {
4747
const msg = `not logged in to ${reg}, so can't log out!`

test/lib/logout.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const logout = new Logout(npm)
2929
t.test('token logout', async (t) => {
3030
t.plan(6)
3131

32-
flatOptions.token = '@foo/'
32+
flatOptions['//registry.npmjs.org/:_authToken'] = '@foo/'
3333

3434
npmlog.verbose = (title, msg) => {
3535
t.equal(title, 'logout', 'should have correcct log prefix')
@@ -63,7 +63,7 @@ t.test('token logout', async (t) => {
6363
opts: {
6464
registry: 'https://registry.npmjs.org/',
6565
scope: '',
66-
token: '@foo/',
66+
'//registry.npmjs.org/:_authToken': '@foo/',
6767
method: 'DELETE',
6868
ignoreBody: true,
6969
},
@@ -87,7 +87,8 @@ t.test('token logout', async (t) => {
8787
t.test('token scoped logout', async (t) => {
8888
t.plan(8)
8989

90-
flatOptions.token = '@foo/'
90+
flatOptions['//diff-registry.npmjs.com/:_authToken'] = '@bar/'
91+
flatOptions['//registry.npmjs.org/:_authToken'] = '@foo/'
9192
config.scope = '@myscope'
9293
config['@myscope:registry'] = 'https://diff-registry.npmjs.com/'
9394
flatOptions.scope = '@myscope'
@@ -130,12 +131,13 @@ t.test('token scoped logout', async (t) => {
130131
t.same(
131132
result,
132133
{
133-
url: '/-/user/token/%40foo%2F',
134+
url: '/-/user/token/%40bar%2F',
134135
opts: {
135136
registry: 'https://registry.npmjs.org/',
136137
'@myscope:registry': 'https://diff-registry.npmjs.com/',
137138
scope: '@myscope',
138-
token: '@foo/',
139+
'//registry.npmjs.org/:_authToken': '@foo/', // <- removed by npm-registry-fetch
140+
'//diff-registry.npmjs.com/:_authToken': '@bar/',
139141
method: 'DELETE',
140142
ignoreBody: true,
141143
},
@@ -144,8 +146,10 @@ t.test('token scoped logout', async (t) => {
144146
)
145147

146148
config.scope = ''
149+
delete flatOptions['//diff-registry.npmjs.com/:_authToken']
150+
delete flatOptions['//registry.npmjs.org/:_authToken']
147151
delete config['@myscope:registry']
148-
delete flatOptions.token
152+
delete flatOptions.scope
149153
result = null
150154
mocks['npm-registry-fetch'] = null
151155
config.clearCredentialsByURI = null
@@ -161,11 +165,11 @@ t.test('token scoped logout', async (t) => {
161165
t.test('user/pass logout', async (t) => {
162166
t.plan(3)
163167

164-
flatOptions.username = 'foo'
165-
flatOptions.password = 'bar'
168+
flatOptions['//registry.npmjs.org/:username'] = 'foo'
169+
flatOptions['//registry.npmjs.org/:_password'] = 'bar'
166170

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

183-
delete flatOptions.username
184-
delete flatOptions.password
187+
delete flatOptions['//registry.npmjs.org/:username']
188+
delete flatOptions['//registry.npmjs.org/:_password']
185189
npm.config.clearCredentialsByURI = null
186190
npm.config.save = null
187191
npmlog.verbose = null
@@ -206,7 +210,7 @@ t.test('missing credentials', (t) => {
206210
t.test('ignore invalid scoped registry config', async (t) => {
207211
t.plan(5)
208212

209-
flatOptions.token = '@foo/'
213+
flatOptions['//registry.npmjs.org/:_authToken'] = '@foo/'
210214
config.scope = '@myscope'
211215
flatOptions['@myscope:registry'] = ''
212216

@@ -239,10 +243,9 @@ t.test('ignore invalid scoped registry config', async (t) => {
239243
{
240244
url: '/-/user/token/%40foo%2F',
241245
opts: {
246+
'//registry.npmjs.org/:_authToken': '@foo/',
242247
registry: 'https://registry.npmjs.org/',
243-
scope: '@myscope',
244248
'@myscope:registry': '',
245-
token: '@foo/',
246249
method: 'DELETE',
247250
ignoreBody: true,
248251
},

0 commit comments

Comments
 (0)