From 358076a5ec5a081d3ce29c358282b87402beb9b8 Mon Sep 17 00:00:00 2001 From: Owen Rumney Date: Sun, 17 Jul 2022 12:40:16 +0100 Subject: [PATCH] Fix: handle integers for Chart name in Helm parsing (#730) --- pkg/scanners/helm/parser/parser.go | 2 +- pkg/scanners/helm/test/parser_test.go | 23 +++++++++++++++++++ .../helm/test/testdata/numberName/Chart.yaml | 3 +++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 pkg/scanners/helm/test/testdata/numberName/Chart.yaml diff --git a/pkg/scanners/helm/parser/parser.go b/pkg/scanners/helm/parser/parser.go index 422159851..a7d1abc2a 100644 --- a/pkg/scanners/helm/parser/parser.go +++ b/pkg/scanners/helm/parser/parser.go @@ -149,7 +149,7 @@ func (p *Parser) extractChartName(chartPath string) error { if name, ok := chartContent["name"]; !ok { return fmt.Errorf("could not extract the chart name from %s", chartPath) } else { - p.helmClient.ReleaseName = name.(string) + p.helmClient.ReleaseName = fmt.Sprintf("%v", name) } return nil } diff --git a/pkg/scanners/helm/test/parser_test.go b/pkg/scanners/helm/test/parser_test.go index 5f307edc6..b75b57ea3 100644 --- a/pkg/scanners/helm/test/parser_test.go +++ b/pkg/scanners/helm/test/parser_test.go @@ -50,6 +50,29 @@ func Test_helm_parser(t *testing.T) { } } +func Test_helm_parser_where_name_non_string(t *testing.T) { + + tests := []struct { + testName string + chartName string + }{ + { + testName: "Scanning chart with integer for name", + chartName: "numberName", + }, + } + + for _, test := range tests { + chartName := test.chartName + + t.Logf("Running test: %s", test.testName) + + helmParser := parser.New(chartName) + err := helmParser.ParseFS(context.TODO(), os.DirFS(filepath.Join("testdata", chartName)), ".") + require.NoError(t, err) + } +} + func Test_tar_is_chart(t *testing.T) { tests := []struct { diff --git a/pkg/scanners/helm/test/testdata/numberName/Chart.yaml b/pkg/scanners/helm/test/testdata/numberName/Chart.yaml new file mode 100644 index 000000000..e840fbabf --- /dev/null +++ b/pkg/scanners/helm/test/testdata/numberName/Chart.yaml @@ -0,0 +1,3 @@ +apiVersion: v2 +name: 1001 +version: 1.0.0 \ No newline at end of file