feat(always-auth): add https port parsing on registry matching for artifactory compatibility (#6864)

Co-authored-by: Frederick Engelhardt <frederick.engelhardt@bestbuy.com>
Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
Frederick Engelhardt
2023-07-27 07:18:29 -07:00
committed by GitHub
parent 09e08a9ae3
commit aa20818a0e
3 changed files with 18 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/network.auth-header": patch
"pnpm": patch
---
Authorization token should be found in the configuration, when the requested URL is explicitly specified with a default port (443 on HTTPS or 80 on HTTP) [#6863](https://github.com/pnpm/pnpm/pull/6864).

View File

@@ -39,7 +39,7 @@ function getAuthHeaderByURI (authHeaders: Record<string, string>, maxParts: numb
function removePort (originalUrl: string) {
const urlObj = new URL(originalUrl)
if (urlObj.port === '') return originalUrl
if (urlObj.port === '') return urlObj.href
urlObj.port = ''
return urlObj.toString()
}

View File

@@ -17,6 +17,17 @@ test('getAuthHeaderByURI()', () => {
expect(getAuthHeaderByURI('https://reg.gg:8888/foo/-/foo-1.0.0.tgz')).toBe('Bearer 0000')
})
test('getAuthHeaderByURI() when default ports are specified', () => {
const getAuthHeaderByURI = createGetAuthHeaderByURI({
allSettings: {
'//reg.com/:_authToken': 'abc123',
},
userSettings: {},
})
expect(getAuthHeaderByURI('https://reg.com:443/')).toBe('Bearer abc123')
expect(getAuthHeaderByURI('http://reg.com:80/')).toBe('Bearer abc123')
})
test('returns undefined when the auth header is not found', () => {
expect(createGetAuthHeaderByURI({ allSettings: {}, userSettings: {} })('http://reg.com')).toBe(undefined)
})