fix: Add binary plugin url support

Signed-off-by: Suleiman Dibirov <idsulik@gmail.com>
pull/13225/head
Suleiman Dibirov 1 year ago
parent 99c065789e
commit 1f3b4cfa04

@ -66,22 +66,27 @@ func TestStripName(t *testing.T) {
} }
} }
func mockArchiveServer() *httptest.Server { func mockArchiveServer(extensionToContentType map[string]string) *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if !strings.HasSuffix(r.URL.Path, ".tar.gz") { for ext, contentType := range extensionToContentType {
w.Header().Add("Content-Type", "text/html") if strings.HasSuffix(r.URL.Path, ext) {
fmt.Fprintln(w, "broken") w.Header().Add("Content-Type", contentType)
return fmt.Fprintln(w, "test")
return
}
} }
w.Header().Add("Content-Type", "application/gzip")
fmt.Fprintln(w, "test") w.Header().Add("Content-Type", "text/html")
fmt.Fprintln(w, "broken")
})) }))
} }
func TestHTTPInstaller(t *testing.T) { func TestHTTPInstaller(t *testing.T) {
ensure.HelmHome(t) ensure.HelmHome(t)
srv := mockArchiveServer() srv := mockArchiveServer(map[string]string{
".tar.gz": "application/gzip",
})
defer srv.Close() defer srv.Close()
source := srv.URL + "/plugins/fake-plugin-0.0.1.tar.gz" source := srv.URL + "/plugins/fake-plugin-0.0.1.tar.gz"
@ -129,7 +134,9 @@ func TestHTTPInstaller(t *testing.T) {
func TestHTTPInstallerNonExistentVersion(t *testing.T) { func TestHTTPInstallerNonExistentVersion(t *testing.T) {
ensure.HelmHome(t) ensure.HelmHome(t)
srv := mockArchiveServer() srv := mockArchiveServer(map[string]string{
".tar.gz": "application/gzip",
})
defer srv.Close() defer srv.Close()
source := srv.URL + "/plugins/fake-plugin-0.0.1.tar.gz" source := srv.URL + "/plugins/fake-plugin-0.0.1.tar.gz"
@ -161,7 +168,9 @@ func TestHTTPInstallerNonExistentVersion(t *testing.T) {
} }
func TestHTTPInstallerUpdate(t *testing.T) { func TestHTTPInstallerUpdate(t *testing.T) {
srv := mockArchiveServer() srv := mockArchiveServer(map[string]string{
".tar.gz": "application/gzip",
})
defer srv.Close() defer srv.Close()
source := srv.URL + "/plugins/fake-plugin-0.0.1.tar.gz" source := srv.URL + "/plugins/fake-plugin-0.0.1.tar.gz"
ensure.HelmHome(t) ensure.HelmHome(t)

@ -107,8 +107,12 @@ func isRemoteHTTPArchive(source string) bool {
contentType := res.Header.Get("content-type") contentType := res.Header.Get("content-type")
foundSuffix, ok := mediaTypeToExtension(contentType) foundSuffix, ok := mediaTypeToExtension(contentType)
if !ok { if !ok {
// Media type not recognized if strings.HasSuffix(source, ".tar.gz") && contentType == "application/octet-stream" {
return false foundSuffix = ".tar.gz"
} else {
// Media type not recognized
return false
}
} }
for suffix := range Extractors { for suffix := range Extractors {

@ -18,9 +18,13 @@ package installer
import "testing" import "testing"
func TestIsRemoteHTTPArchive(t *testing.T) { func TestIsRemoteHTTPArchive(t *testing.T) {
srv := mockArchiveServer() srv := mockArchiveServer(map[string]string{
".tar.gz": "application/gzip",
".binary.tar.gz": "application/octet-stream",
})
defer srv.Close() defer srv.Close()
source := srv.URL + "/plugins/fake-plugin-0.0.1.tar.gz" source := srv.URL + "/plugins/fake-plugin-0.0.1.tar.gz"
binarySource := srv.URL + "/plugins/fake-plugin-0.0.1.binary.tar.gz"
if isRemoteHTTPArchive("/not/a/URL") { if isRemoteHTTPArchive("/not/a/URL") {
t.Errorf("Expected non-URL to return false") t.Errorf("Expected non-URL to return false")
@ -37,4 +41,8 @@ func TestIsRemoteHTTPArchive(t *testing.T) {
if isRemoteHTTPArchive(source + "-not-an-extension") { if isRemoteHTTPArchive(source + "-not-an-extension") {
t.Error("Expected media type match to fail") t.Error("Expected media type match to fail")
} }
if !isRemoteHTTPArchive(binarySource) {
t.Errorf("Expected %q to be a valid archive URL", source)
}
} }

Loading…
Cancel
Save