Skip to content

Commit 24f64a5

Browse files
committed
chore: add web-login proxy doneUrl regression for #8875
1 parent abf78b3 commit 24f64a5

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
@@ -261,15 +261,18 @@ class MockRegistry {
261261
.reply(200, { token })
262262
}
263263

264-
weblogin ({ token = 'npm_default-test-token' }) {
265-
const doneUrl = new URL('/npm-cli-test/done', this.origin).href
264+
weblogin ({ token = 'npm_default-test-token', doneRegistry } = {}) {
265+
const donePath = '/npm-cli-test/done'
266+
// doneRegistry emulates a proxy/mirror that advertises a doneUrl on a different origin than the configured registry.
267+
// The poll itself is always mocked on this registry, since that is where the session lives.
268+
const doneUrl = new URL(donePath, doneRegistry ?? this.origin).href
266269
const loginUrl = new URL('/npm-cli-test/login/cli/00000000-0000-0000-0000-000000000000', this.origin).href
267270
this.nock = this.nock
268271
.post(this.fullPath('/-/v1/login'), () => {
269272
return true
270273
})
271274
.reply(200, { doneUrl, loginUrl })
272-
.get('/npm-cli-test/done')
275+
.get(donePath)
273276
.reply(200, { token })
274277
}
275278

test/lib/commands/login.js

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

0 commit comments

Comments
 (0)