From 3340d917f09876215ac135cdba831af26de38101 Mon Sep 17 00:00:00 2001 From: vigneshwar Date: Wed, 4 Nov 2026 11:47:29 +0530 Subject: [PATCH 1/2] fix: report malformed --chart-repos and --helm-repo-extra-args instead of panicking processCharts split every --chart-repos and --helm-repo-extra-args value on "=" and read the second element without checking that it exists. A value without a repo name, such as --chart-repos https://charts.bitnami.com/bitnami or --helm-repo-extra-args --force-update, made lint, install and lint-and-install crash with "index out of range [1] with length 1". Use strings.Cut and return an error that names the bad value and the expected format. Signed-off-by: vigneshwar --- pkg/chart/chart.go | 16 +++++++++------- pkg/chart/chart_test.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/pkg/chart/chart.go b/pkg/chart/chart.go index 17aef5d3..dfe8c0ae 100644 --- a/pkg/chart/chart.go +++ b/pkg/chart/chart.go @@ -351,16 +351,18 @@ func (t *Testing) processCharts(action func(chart *Chart) TestResult) ([]TestRes repoArgs := map[string][]string{} for _, repo := range t.config.HelmRepoExtraArgs { - repoSlice := strings.SplitN(repo, "=", 2) - name := repoSlice[0] - repoExtraArgs := strings.Fields(repoSlice[1]) - repoArgs[name] = repoExtraArgs + name, extraArgs, found := strings.Cut(repo, "=") + if !found { + return nil, fmt.Errorf("invalid helm repo extra args %q: expected format 'name=args'", repo) + } + repoArgs[name] = strings.Fields(extraArgs) } for _, repo := range t.config.ChartRepos { - repoSlice := strings.SplitN(repo, "=", 2) - name := repoSlice[0] - url := repoSlice[1] + name, url, found := strings.Cut(repo, "=") + if !found { + return nil, fmt.Errorf("invalid chart repo %q: expected format 'name=url'", repo) + } repoExtraArgs := repoArgs[name] if err := t.helm.AddRepo(name, url, repoExtraArgs); err != nil { diff --git a/pkg/chart/chart_test.go b/pkg/chart/chart_test.go index f849cbd7..63b128cc 100644 --- a/pkg/chart/chart_test.go +++ b/pkg/chart/chart_test.go @@ -431,6 +431,40 @@ func TestLintDependencyExtraArgs(t *testing.T) { }) } +func TestLintChartsInvalidRepoConfig(t *testing.T) { + testCases := []struct { + name string + chartRepos []string + helmRepoExtraArgs []string + expectedError string + }{ + { + name: "chart repo without name", + chartRepos: []string{"https://charts.bitnami.com/bitnami"}, + expectedError: `invalid chart repo "https://charts.bitnami.com/bitnami": expected format 'name=url'`, + }, + { + name: "helm repo extra args without repo name", + helmRepoExtraArgs: []string{"--force-update"}, + expectedError: `invalid helm repo extra args "--force-update": expected format 'name=args'`, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + cfg := config.Configuration{ + Charts: []string{"testdata/test_lints"}, + ChartRepos: tc.chartRepos, + HelmRepoExtraArgs: tc.helmRepoExtraArgs, + } + ct := newTestingMock(cfg) + + _, err := ct.LintCharts() + assert.EqualError(t, err, tc.expectedError) + }) + } +} + func TestGenerateInstallConfig(t *testing.T) { type testData struct { name string From ad4c0eefd3cbe59b6e2d0276e3f2781d943b5cf0 Mon Sep 17 00:00:00 2001 From: vigneshwar Date: Tue, 10 Nov 2026 22:31:57 +0530 Subject: [PATCH 2/2] fix: do not print malformed repository arguments in the error The values of --chart-repos and --helm-repo-extra-args can carry credentials, so name the malformed entry by its position instead. Signed-off-by: vigneshwar --- pkg/chart/chart.go | 10 ++++++---- pkg/chart/chart_test.go | 20 ++++++++++++++++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/pkg/chart/chart.go b/pkg/chart/chart.go index dfe8c0ae..27807e6e 100644 --- a/pkg/chart/chart.go +++ b/pkg/chart/chart.go @@ -350,18 +350,20 @@ func (t *Testing) processCharts(action func(chart *Chart) TestResult) ([]TestRes repoArgs := map[string][]string{} - for _, repo := range t.config.HelmRepoExtraArgs { + // The values can hold credentials, so the errors below name the entry by + // position instead of printing it. + for i, repo := range t.config.HelmRepoExtraArgs { name, extraArgs, found := strings.Cut(repo, "=") if !found { - return nil, fmt.Errorf("invalid helm repo extra args %q: expected format 'name=args'", repo) + return nil, fmt.Errorf("invalid --helm-repo-extra-args entry %d: expected format 'name=args'", i+1) } repoArgs[name] = strings.Fields(extraArgs) } - for _, repo := range t.config.ChartRepos { + for i, repo := range t.config.ChartRepos { name, url, found := strings.Cut(repo, "=") if !found { - return nil, fmt.Errorf("invalid chart repo %q: expected format 'name=url'", repo) + return nil, fmt.Errorf("invalid --chart-repos entry %d: expected format 'name=url'", i+1) } repoExtraArgs := repoArgs[name] diff --git a/pkg/chart/chart_test.go b/pkg/chart/chart_test.go index 63b128cc..6b618609 100644 --- a/pkg/chart/chart_test.go +++ b/pkg/chart/chart_test.go @@ -437,16 +437,29 @@ func TestLintChartsInvalidRepoConfig(t *testing.T) { chartRepos []string helmRepoExtraArgs []string expectedError string + secret string }{ { name: "chart repo without name", chartRepos: []string{"https://charts.bitnami.com/bitnami"}, - expectedError: `invalid chart repo "https://charts.bitnami.com/bitnami": expected format 'name=url'`, + expectedError: "invalid --chart-repos entry 1: expected format 'name=url'", + }, + { + name: "chart repo with credentials in the url and no name", + chartRepos: []string{"stable=https://charts.helm.sh/stable", "https://demo:s3cr3t@charts.example.com"}, + expectedError: "invalid --chart-repos entry 2: expected format 'name=url'", + secret: "s3cr3t", }, { name: "helm repo extra args without repo name", helmRepoExtraArgs: []string{"--force-update"}, - expectedError: `invalid helm repo extra args "--force-update": expected format 'name=args'`, + expectedError: "invalid --helm-repo-extra-args entry 1: expected format 'name=args'", + }, + { + name: "helm repo extra args with a password and no repo name", + helmRepoExtraArgs: []string{"--username demo --password s3cr3t"}, + expectedError: "invalid --helm-repo-extra-args entry 1: expected format 'name=args'", + secret: "s3cr3t", }, } @@ -461,6 +474,9 @@ func TestLintChartsInvalidRepoConfig(t *testing.T) { _, err := ct.LintCharts() assert.EqualError(t, err, tc.expectedError) + if tc.secret != "" { + assert.NotContains(t, err.Error(), tc.secret) + } }) } }