mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-11 10:40:53 -04:00
fix: missing auth token in registries with paths included (#7337)
close #5970 close #2933 --------- Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
6
.changeset/three-penguins-trade.md
Normal file
6
.changeset/three-penguins-trade.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/network.auth-header": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Fix missing auth tokens in registries with paths specified (e.g. //npm.pkg.github.com/pnpm). #5970 #2933
|
||||
@@ -24,6 +24,9 @@ function getMaxParts (uris: string[]) {
|
||||
}
|
||||
|
||||
function getAuthHeaderByURI (authHeaders: Record<string, string>, maxParts: number, uri: string): string | undefined {
|
||||
if (!uri.endsWith('/')) {
|
||||
uri += '/'
|
||||
}
|
||||
const nerfed = nerfDart(uri)
|
||||
const parts = nerfed.split('/')
|
||||
for (let i = Math.min(parts.length, maxParts) - 1; i >= 3; i--) {
|
||||
@@ -35,4 +38,4 @@ function getAuthHeaderByURI (authHeaders: Record<string, string>, maxParts: numb
|
||||
return getAuthHeaderByURI(authHeaders, maxParts, urlWithoutPort)
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,3 +43,21 @@ test('getAuthHeaderByURI() when default ports are specified', () => {
|
||||
test('returns undefined when the auth header is not found', () => {
|
||||
expect(createGetAuthHeaderByURI({ allSettings: {}, userSettings: {} })('http://reg.com')).toBe(undefined)
|
||||
})
|
||||
|
||||
test('getAuthHeaderByURI() when the registry has pathnames', () => {
|
||||
const getAuthHeaderByURI = createGetAuthHeaderByURI({
|
||||
allSettings: {
|
||||
'//npm.pkg.github.com/pnpm/:_authToken': 'abc123',
|
||||
},
|
||||
userSettings: {},
|
||||
})
|
||||
expect(getAuthHeaderByURI('https://npm.pkg.github.com/pnpm')).toBe('Bearer abc123')
|
||||
expect(getAuthHeaderByURI('https://npm.pkg.github.com/pnpm/')).toBe('Bearer abc123')
|
||||
expect(getAuthHeaderByURI('https://npm.pkg.github.com/pnpm/foo')).toBe('Bearer abc123')
|
||||
expect(getAuthHeaderByURI('https://npm.pkg.github.com/pnpm/foo/')).toBe('Bearer abc123')
|
||||
expect(getAuthHeaderByURI('https://npm.pkg.github.com/pnpm/foo/-/foo-1.0.0.tgz')).toBe('Bearer abc123')
|
||||
expect(getAuthHeaderByURI('https://npm.pkg.github.com/pnpm/foo/-/foo-1.0.0.tgz')).toBe('Bearer abc123')
|
||||
expect(getAuthHeaderByURI('https://npm.pkg.github.com/pnpm/foo/-/foo-1.0.0.tgz')).toBe('Bearer abc123')
|
||||
expect(getAuthHeaderByURI('https://npm.pkg.github.com/pnpm/foo/-/foo-1.0.0.tgz')).toBe('Bearer abc123')
|
||||
expect(getAuthHeaderByURI('https://npm.pkg.github.com/pnpm/foo/-/foo-1.0.0.tgz')).toBe('Bearer abc123')
|
||||
})
|
||||
Reference in New Issue
Block a user