1
0
mirror of https://github.com/Azure/setup-helm.git synced 2026-07-16 13:18:05 +00:00

fix: preserve subpath base URLs in getHelmDownloadURL (#292)

Ensure downloadBaseURL ends with '/' before URL resolution so a subpath
mirror (e.g. https://example/kubernetes/helm) is preserved instead of having
its last path segment replaced. Fixes downloads for all subpath mirrors.
This commit is contained in:
Ogheneobukome Ejaife
2026-07-15 12:45:05 -07:00
committed by GitHub
parent 017211e1b1
commit eb399fcd4f
2 changed files with 33 additions and 1 deletions
+28
View File
@@ -140,6 +140,34 @@ describe('run.ts', () => {
expect(os.platform).toHaveBeenCalled()
})
test('getHelmDownloadURL() - preserve a subpath base URL without a trailing slash', () => {
vi.mocked(os.platform).mockReturnValue('linux')
vi.mocked(os.arch).mockReturnValue('x64')
const expected =
'https://mirror.example/kubernetes/helm/helm-v3.8.0-linux-amd64.tar.gz'
expect(
run.getHelmDownloadURL(
'https://mirror.example/kubernetes/helm',
'v3.8.0'
)
).toBe(expected)
})
test('getHelmDownloadURL() - preserve a subpath base URL with a trailing slash', () => {
vi.mocked(os.platform).mockReturnValue('linux')
vi.mocked(os.arch).mockReturnValue('x64')
const expected =
'https://mirror.example/kubernetes/helm/helm-v3.8.0-linux-amd64.tar.gz'
expect(
run.getHelmDownloadURL(
'https://mirror.example/kubernetes/helm/',
'v3.8.0'
)
).toBe(expected)
})
test('getLatestHelmVersion() - return the latest version of HELM', async () => {
const res = {
status: 200,
+5 -1
View File
@@ -139,7 +139,11 @@ export function getExecutableExtension(): string {
export function getHelmDownloadURL(baseURL: string, version: string): string {
const urlPath = `helm-${version}-${getPlatform()}-${getArch()}.${getArchiveExtension()}`
const url = new URL(urlPath, baseURL)
// Ensure the base ends with '/' so a subpath mirror (e.g.
// 'https://example/kubernetes/helm') is preserved; otherwise URL resolution
// replaces the last path segment and points at the wrong location.
const base = baseURL.endsWith('/') ? baseURL : `${baseURL}/`
const url = new URL(urlPath, base)
return url.toString()
}