From 2ff3c981a55860783c3918e84ede5861005f4581 Mon Sep 17 00:00:00 2001 From: Mathieu Parent Date: Thu, 17 Jun 2021 14:35:44 +0200 Subject: [PATCH] Fix URL with encoded path support for ChartDownloader Signed-off-by: Mathieu Parent --- pkg/downloader/chart_downloader.go | 1 + pkg/downloader/chart_downloader_test.go | 1 + pkg/downloader/testdata/repositories.yaml | 4 +++- .../testdata/repository/encoded-url-index.yaml | 15 +++++++++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 pkg/downloader/testdata/repository/encoded-url-index.yaml diff --git a/pkg/downloader/chart_downloader.go b/pkg/downloader/chart_downloader.go index 93afb1461..db66c63c5 100644 --- a/pkg/downloader/chart_downloader.go +++ b/pkg/downloader/chart_downloader.go @@ -267,6 +267,7 @@ func (c *ChartDownloader) ResolveChartVersion(ref, version string) (*url.URL, er } q := repoURL.Query() // We need a trailing slash for ResolveReference to work, but make sure there isn't already one + repoURL.RawPath = strings.TrimSuffix(repoURL.RawPath, "/") + "/" repoURL.Path = strings.TrimSuffix(repoURL.Path, "/") + "/" u = repoURL.ResolveReference(u) u.RawQuery = q.Encode() diff --git a/pkg/downloader/chart_downloader_test.go b/pkg/downloader/chart_downloader_test.go index f70a56422..8ff780daf 100644 --- a/pkg/downloader/chart_downloader_test.go +++ b/pkg/downloader/chart_downloader_test.go @@ -48,6 +48,7 @@ func TestResolveChartRef(t *testing.T) { {name: "reference, testing-relative repo", ref: "testing-relative/bar", expect: "http://example.com/helm/bar-1.2.3.tgz"}, {name: "reference, testing-relative-trailing-slash repo", ref: "testing-relative-trailing-slash/foo", expect: "http://example.com/helm/charts/foo-1.2.3.tgz"}, {name: "reference, testing-relative-trailing-slash repo", ref: "testing-relative-trailing-slash/bar", expect: "http://example.com/helm/bar-1.2.3.tgz"}, + {name: "encoded URL", ref: "encoded-url/foobar", expect: "http://example.com/with%2Fslash/charts/foobar-4.2.1.tgz"}, {name: "full URL, HTTPS, irrelevant version", ref: "https://example.com/foo-1.2.3.tgz", version: "0.1.0", expect: "https://example.com/foo-1.2.3.tgz", fail: true}, {name: "full URL, file", ref: "file:///foo-1.2.3.tgz", fail: true}, {name: "invalid", ref: "invalid-1.2.3", fail: true}, diff --git a/pkg/downloader/testdata/repositories.yaml b/pkg/downloader/testdata/repositories.yaml index 32bc395a0..db7a57687 100644 --- a/pkg/downloader/testdata/repositories.yaml +++ b/pkg/downloader/testdata/repositories.yaml @@ -23,4 +23,6 @@ repositories: caFile: "ca" - name: testing-https-insecureskip-tls-verify url: "https://example-https-insecureskiptlsverify.com" - insecure_skip_tls_verify: true + insecure_skip_tls_verify: true + - name: encoded-url + url: "http://example.com/with%2Fslash" diff --git a/pkg/downloader/testdata/repository/encoded-url-index.yaml b/pkg/downloader/testdata/repository/encoded-url-index.yaml new file mode 100644 index 000000000..f9ec867a5 --- /dev/null +++ b/pkg/downloader/testdata/repository/encoded-url-index.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +entries: + foobar: + - name: foobar + description: Foo Chart With Encoded URL + home: https://helm.sh/helm + keywords: [] + maintainers: [] + sources: + - https://github.com/helm/charts + urls: + - charts/foobar-4.2.1.tgz + version: 4.2.1 + checksum: 0e6661f193211d7a5206918d42f5c2a9470b737d + apiVersion: v2