From 24f64a56e1bc62a623e758da69e2cfefa5c61ba1 Mon Sep 17 00:00:00 2001 From: Manzoor Wani Date: Tue, 16 Jun 2026 23:28:39 +0530 Subject: [PATCH] chore: add web-login proxy doneUrl regression for #8875 --- mock-registry/lib/index.js | 9 ++++++--- test/lib/commands/login.js | 13 +++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/mock-registry/lib/index.js b/mock-registry/lib/index.js index 6f3b022467f35..a0efca8c697ca 100644 --- a/mock-registry/lib/index.js +++ b/mock-registry/lib/index.js @@ -261,15 +261,18 @@ class MockRegistry { .reply(200, { token }) } - weblogin ({ token = 'npm_default-test-token' }) { - const doneUrl = new URL('/npm-cli-test/done', this.origin).href + weblogin ({ token = 'npm_default-test-token', doneRegistry } = {}) { + const donePath = '/npm-cli-test/done' + // doneRegistry emulates a proxy/mirror that advertises a doneUrl on a different origin than the configured registry. + // The poll itself is always mocked on this registry, since that is where the session lives. + const doneUrl = new URL(donePath, doneRegistry ?? this.origin).href const loginUrl = new URL('/npm-cli-test/login/cli/00000000-0000-0000-0000-000000000000', this.origin).href this.nock = this.nock .post(this.fullPath('/-/v1/login'), () => { return true }) .reply(200, { doneUrl, loginUrl }) - .get('/npm-cli-test/done') + .get(donePath) .reply(200, { token }) } diff --git a/test/lib/commands/login.js b/test/lib/commands/login.js index f855fe683bd9f..623bc5845708f 100644 --- a/test/lib/commands/login.js +++ b/test/lib/commands/login.js @@ -129,6 +129,19 @@ t.test('web', t => { }) t.match(outputs[0], '/npm-cli-test/login/cli/00000000-0000-0000-0000-000000000000') }) + t.test('proxy registry whose doneUrl points at the canonical registry', async t => { + // Regression for npm/cli#8875: a proxy/mirror returns a doneUrl on registry.npmjs.org. + // npm must poll the configured proxy where the session lives, not the canonical registry. + const proxy = 'https://proxy.registry.example/' + const { npm, registry, login, rc } = await mockLogin(t, { + registry: proxy, + config: { 'auth-type': 'web', registry: proxy }, + }) + registry.weblogin({ token: 'npm_proxy-token', doneRegistry: 'https://registry.npmjs.org' }) + await login.exec([]) + t.same(npm.config.get('//proxy.registry.example/:_authToken'), 'npm_proxy-token') + t.match(rc(), { '//proxy.registry.example/:_authToken': 'npm_proxy-token' }) + }) t.test('server error', async t => { const { registry, login } = await mockLogin(t, { config: { 'auth-type': 'web' },