From f60ca8b8c1397c885b0c66a0bb91c8531fa3a051 Mon Sep 17 00:00:00 2001 From: Adam Korczynski Date: Thu, 14 May 2020 11:06:51 +0100 Subject: [PATCH] move more fuzzers over from cncf-fuzzing Signed-off-by: Adam Korczynski --- pkg/chart/loader/fuzz_test.go | 37 +++++++++++++++++++++ pkg/engine/fuzz_test.go | 61 +++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 pkg/chart/loader/fuzz_test.go create mode 100644 pkg/engine/fuzz_test.go diff --git a/pkg/chart/loader/fuzz_test.go b/pkg/chart/loader/fuzz_test.go new file mode 100644 index 000000000..d99783ce6 --- /dev/null +++ b/pkg/chart/loader/fuzz_test.go @@ -0,0 +1,37 @@ +/* +Copyright The Helm Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package loader + +import ( + "testing" + + fuzz "github.com/AdaLogics/go-fuzz-headers" +) + +// FuzzLoadDir creates a directory with a lot +// of random files and then loads it. +func FuzzLoadDir(f *testing.F) { + f.Fuzz(func(t *testing.T, filesData []byte) { + tmpDir := t.TempDir() + fdp := fuzz.NewConsumer(filesData) + err := fdp.CreateFiles(tmpDir) + if err != nil { + return + } + _, _ = LoadDir(tmpDir) + }) +} diff --git a/pkg/engine/fuzz_test.go b/pkg/engine/fuzz_test.go new file mode 100644 index 000000000..9bf4034a6 --- /dev/null +++ b/pkg/engine/fuzz_test.go @@ -0,0 +1,61 @@ +/* +Copyright The Helm Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package engine + +import ( + "testing" + + "helm.sh/helm/v3/pkg/chart" + "helm.sh/helm/v3/pkg/chartutil" + + fuzz "github.com/AdaLogics/go-fuzz-headers" +) + +func FuzzEngineRender(f *testing.F) { + f.Fuzz(func(_ *testing.T, chartData, valuesBytes []byte) { + fdp := fuzz.NewConsumer(chartData) + chrt := &chart.Chart{} + err := fdp.GenerateStruct(chrt) + if err != nil { + return + } + values, err := chartutil.ReadValues(valuesBytes) + if err != nil { + return + } + _, _ = Render(chrt, values) + }) +} + +func FuzzEngineFiles(f *testing.F) { + f.Fuzz(func(_ *testing.T, path, pattern, name, str1, str2, str3, str4, str5 string, + b1, b2, b3, b4, b5 []byte) { + files := make(files) + files[str1] = b1 + files[str2] = b2 + files[str3] = b3 + files[str4] = b4 + files[str5] = b5 + + // Test various methods of files + _ = files.Get(name) + _ = files.Glob(pattern) + _ = files.AsConfig() + _ = files.AsSecrets() + _ = files.Lines(path) + }) +}