Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions pkg/chart/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,17 +350,21 @@ 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
// 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 entry %d: expected format 'name=args'", i+1)
}
repoArgs[name] = strings.Fields(extraArgs)
}

for _, repo := range t.config.ChartRepos {
repoSlice := strings.SplitN(repo, "=", 2)
name := repoSlice[0]
url := repoSlice[1]
for i, repo := range t.config.ChartRepos {
name, url, found := strings.Cut(repo, "=")
if !found {
return nil, fmt.Errorf("invalid --chart-repos entry %d: expected format 'name=url'", i+1)
}

repoExtraArgs := repoArgs[name]
if err := t.helm.AddRepo(name, url, repoExtraArgs); err != nil {
Expand Down
50 changes: 50 additions & 0 deletions pkg/chart/chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,56 @@ func TestLintDependencyExtraArgs(t *testing.T) {
})
}

func TestLintChartsInvalidRepoConfig(t *testing.T) {
testCases := []struct {
name string
chartRepos []string
helmRepoExtraArgs []string
expectedError string
secret string
}{
{
name: "chart repo without name",
chartRepos: []string{"https://charts.bitnami.com/bitnami"},
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 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",
},
}

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)
if tc.secret != "" {
assert.NotContains(t, err.Error(), tc.secret)
}
})
}
}

func TestGenerateInstallConfig(t *testing.T) {
type testData struct {
name string
Expand Down