From aa20818a0e5a8ff9b6cd82eaf4addcc1ea280bec Mon Sep 17 00:00:00 2001 From: Frederick Engelhardt <31741411+FrederickEngelhardt@users.noreply.github.com> Date: Thu, 27 Jul 2023 07:18:29 -0700 Subject: [PATCH] feat(always-auth): add https port parsing on registry matching for artifactory compatibility (#6864) Co-authored-by: Frederick Engelhardt Co-authored-by: Zoltan Kochan --- .changeset/yellow-nails-divide.md | 6 ++++++ network/auth-header/src/index.ts | 2 +- network/auth-header/test/getAuthHeaderByURI.ts | 11 +++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 .changeset/yellow-nails-divide.md diff --git a/.changeset/yellow-nails-divide.md b/.changeset/yellow-nails-divide.md new file mode 100644 index 0000000000..8c254ba5d6 --- /dev/null +++ b/.changeset/yellow-nails-divide.md @@ -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). diff --git a/network/auth-header/src/index.ts b/network/auth-header/src/index.ts index 8315dcd188..480bf538d6 100644 --- a/network/auth-header/src/index.ts +++ b/network/auth-header/src/index.ts @@ -39,7 +39,7 @@ function getAuthHeaderByURI (authHeaders: Record, 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() } diff --git a/network/auth-header/test/getAuthHeaderByURI.ts b/network/auth-header/test/getAuthHeaderByURI.ts index af891b0905..252e262a0f 100644 --- a/network/auth-header/test/getAuthHeaderByURI.ts +++ b/network/auth-header/test/getAuthHeaderByURI.ts @@ -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) })