fix: prevent panic when ChartDownloader is called

Return an error instead of panicing if OCI registry client is not provided

Signed-off-by: Evans Mungai <mbuevans@gmail.com>
pull/13436/head
Evans Mungai 6 months ago
parent b304ee495d
commit cf7f27ce56
No known key found for this signature in database
GPG Key ID: BBEB812143DD14E1

@ -164,6 +164,10 @@ func (c *ChartDownloader) ResolveChartVersion(ref, version string) (*url.URL, er
} }
if registry.IsOCI(u.String()) { if registry.IsOCI(u.String()) {
if c.RegistryClient == nil {
return nil, fmt.Errorf("unable to resolve chart version for %s, missing registry client", ref)
}
return c.RegistryClient.ValidateReference(ref, version, u) return c.RegistryClient.ValidateReference(ref, version, u)
} }

@ -20,6 +20,8 @@ import (
"path/filepath" "path/filepath"
"testing" "testing"
"github.com/stretchr/testify/assert"
"helm.sh/helm/v4/internal/test/ensure" "helm.sh/helm/v4/internal/test/ensure"
"helm.sh/helm/v4/pkg/cli" "helm.sh/helm/v4/pkg/cli"
"helm.sh/helm/v4/pkg/getter" "helm.sh/helm/v4/pkg/getter"
@ -324,6 +326,22 @@ func TestDownloadTo_VerifyLater(t *testing.T) {
} }
} }
func TestDownloadTo_MissingRegistryClient(t *testing.T) {
c := ChartDownloader{
Getters: getter.Providers{
getter.Provider{
Schemes: []string{"oci"},
New: getter.NewOCIGetter,
},
},
}
ref := "oci://someurl"
version := "latest"
_, _, err := c.DownloadTo(ref, version, t.TempDir())
assert.Error(t, err)
}
func TestScanReposForURL(t *testing.T) { func TestScanReposForURL(t *testing.T) {
c := ChartDownloader{ c := ChartDownloader{
Out: os.Stderr, Out: os.Stderr,

Loading…
Cancel
Save