Skip to content

Commit a04cd84

Browse files
chore: add web-login proxy doneUrl regression for npm-profile fix (#9584)
Backport of #9560 to `release/v11`. Co-authored-by: Manzoor Wani <manzoorwani.jk@gmail.com>
1 parent 804f9ba commit a04cd84

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

‎mock-registry/lib/index.js‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,18 @@ class MockRegistry {
282282
.reply(200, { token })
283283
}
284284

285-
weblogin ({ token = 'npm_default-test-token' }) {
286-
const doneUrl = new URL('/npm-cli-test/done', this.origin).href
285+
weblogin ({ token = 'npm_default-test-token', doneRegistry } = {}) {
286+
const donePath = '/npm-cli-test/done'
287+
// doneRegistry emulates a proxy/mirror that advertises a doneUrl on a different origin than the configured registry.
288+
// The poll itself is always mocked on this registry, since that is where the session lives.
289+
const doneUrl = new URL(donePath, doneRegistry ?? this.origin).href
287290
const loginUrl = new URL('/npm-cli-test/login/cli/00000000-0000-0000-0000-000000000000', this.origin).href
288291
this.nock = this.nock
289292
.post(this.fullPath('/-/v1/login'), () => {
290293
return true
291294
})
292295
.reply(200, { doneUrl, loginUrl })
293-
.get('/npm-cli-test/done')
296+
.get(donePath)
294297
.reply(200, { token })
295298
}
296299

‎test/lib/commands/login.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,19 @@ t.test('web', t => {
130130
})
131131
t.match(outputs[0], '/npm-cli-test/login/cli/00000000-0000-0000-0000-000000000000')
132132
})
133+
t.test('proxy registry whose doneUrl points at the canonical registry', async t => {
134+
// Regression for npm/cli#8875: a proxy/mirror returns a doneUrl on registry.npmjs.org.
135+
// npm must poll the configured proxy where the session lives, not the canonical registry.
136+
const proxy = 'https://proxy.registry.example/'
137+
const { npm, registry, login, rc } = await mockLogin(t, {
138+
registry: proxy,
139+
config: { 'auth-type': 'web', registry: proxy },
140+
})
141+
registry.weblogin({ token: 'npm_proxy-token', doneRegistry: 'https://registry.npmjs.org' })
142+
await login.exec([])
143+
t.same(npm.config.get('//proxy.registry.example/:_authToken'), 'npm_proxy-token')
144+
t.match(rc(), { '//proxy.registry.example/:_authToken': 'npm_proxy-token' })
145+
})
133146
t.test('server error', async t => {
134147
const { registry, login } = await mockLogin(t, {
135148
config: { 'auth-type': 'web' },

0 commit comments

Comments
 (0)