Merge pull request #4438 from tomasr/sastoken-in-repo-url

Test+Fix for Query string in repo URL is discarded when downloading packages
pull/4345/merge
Taylor Thomas 6 years ago committed by GitHub
commit 99bfe7c5ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -270,5 +270,13 @@ func ResolveReferenceURL(baseURL, refURL string) (string, error) {
return "", fmt.Errorf("failed to parse %s as URL: %v", refURL, err)
}
return parsedBaseURL.ResolveReference(parsedRefURL).String(), nil
// if the base URL contains query string parameters,
// propagate them to the child URL but only if the
// refURL is relative to baseURL
resolvedURL := parsedBaseURL.ResolveReference(parsedRefURL)
if (resolvedURL.Hostname() == parsedBaseURL.Hostname()) && (resolvedURL.Port() == parsedBaseURL.Port()) {
resolvedURL.RawQuery = parsedBaseURL.RawQuery
}
return resolvedURL.String(), nil
}

@ -287,6 +287,14 @@ func TestResolveReferenceURL(t *testing.T) {
t.Errorf("%s", chartURL)
}
chartURL, err = ResolveReferenceURL("http://localhost:8123/charts/?st=2018-08-06T22%3A59%3A04Z&se=2018-08-07T22%3A59%3A04Z&sp=rl&sv=2018-03-28&sr=c&sig=cyqM4%2F5G7HNk%2F3faaHSDMaWxFxefCglvZlYSnmQBwiY%3D", "nginx-0.2.0.tgz")
if err != nil {
t.Errorf("%s", err)
}
if chartURL != "http://localhost:8123/charts/nginx-0.2.0.tgz?st=2018-08-06T22%3A59%3A04Z&se=2018-08-07T22%3A59%3A04Z&sp=rl&sv=2018-03-28&sr=c&sig=cyqM4%2F5G7HNk%2F3faaHSDMaWxFxefCglvZlYSnmQBwiY%3D" {
t.Errorf("%s does not contain the query string of the base URL", chartURL)
}
chartURL, err = ResolveReferenceURL("http://localhost:8123", "https://kubernetes-charts.storage.googleapis.com/nginx-0.2.0.tgz")
if err != nil {
t.Errorf("%s", err)
@ -294,4 +302,12 @@ func TestResolveReferenceURL(t *testing.T) {
if chartURL != "https://kubernetes-charts.storage.googleapis.com/nginx-0.2.0.tgz" {
t.Errorf("%s", chartURL)
}
chartURL, err = ResolveReferenceURL("http://localhost:8123/?querystring", "https://kubernetes-charts.storage.googleapis.com/nginx-0.2.0.tgz")
if err != nil {
t.Errorf("%s", err)
}
if chartURL != "https://kubernetes-charts.storage.googleapis.com/nginx-0.2.0.tgz" {
t.Errorf("%s contains query string from base URL when it shouldn't", chartURL)
}
}

Loading…
Cancel
Save