Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions mock-registry/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}

Expand Down
13 changes: 13 additions & 0 deletions test/lib/commands/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
t.end()
})

t.test('web', t => {

Check failure on line 119 in test/lib/commands/login.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 22.x

test unfinished

Check failure on line 119 in test/lib/commands/login.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 20.17.0

test unfinished

Check failure on line 119 in test/lib/commands/login.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 20.17.0

test unfinished

Check failure on line 119 in test/lib/commands/login.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 22.9.0

test unfinished

Check failure on line 119 in test/lib/commands/login.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 22.9.0

test unfinished

Check failure on line 119 in test/lib/commands/login.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 22.x

test unfinished

Check failure on line 119 in test/lib/commands/login.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 20.x

test unfinished

Check failure on line 119 in test/lib/commands/login.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 20.x

test unfinished
t.test('basic login', async t => {
const { outputs, npm, registry, login, rc } = await mockLogin(t, {
config: { 'auth-type': 'web' },
Expand All @@ -129,6 +129,19 @@
})
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' },
Expand Down
Loading