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/13105/head
Evans Mungai 6 months ago committed by Carlos Sanchez
parent 2e6437beb5
commit 28e9e34755

@ -164,6 +164,10 @@ func (c *ChartDownloader) ResolveChartVersion(ref, version string) (*url.URL, er
}
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)
}

@ -20,6 +20,8 @@ import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"helm.sh/helm/v4/internal/test/ensure"
"helm.sh/helm/v4/pkg/cli"
"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) {
c := ChartDownloader{
Out: os.Stderr,

Loading…
Cancel
Save