diff --git a/internal/apis/config/BUILD.bazel b/internal/apis/config/BUILD.bazel index 4839c0dfa..0059bb914 100644 --- a/internal/apis/config/BUILD.bazel +++ b/internal/apis/config/BUILD.bazel @@ -29,6 +29,7 @@ filegroup( name = "all-srcs", srcs = [ ":package-srcs", + "//internal/apis/config/fuzzer:all-srcs", "//internal/apis/config/install:all-srcs", "//internal/apis/config/scheme:all-srcs", "//internal/apis/config/v1alpha1:all-srcs", diff --git a/internal/apis/config/fuzzer/BUILD.bazel b/internal/apis/config/fuzzer/BUILD.bazel new file mode 100644 index 000000000..5445eab14 --- /dev/null +++ b/internal/apis/config/fuzzer/BUILD.bazel @@ -0,0 +1,28 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = ["fuzzer.go"], + importpath = "github.com/jetstack/cert-manager/internal/apis/config/fuzzer", + visibility = ["//:__subpackages__"], + deps = [ + "//internal/apis/config:go_default_library", + "@com_github_google_gofuzz//:go_default_library", + "@io_k8s_apimachinery//pkg/runtime/serializer:go_default_library", + "@io_k8s_utils//pointer:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], + visibility = ["//visibility:public"], +) diff --git a/internal/apis/config/fuzzer/fuzzer.go b/internal/apis/config/fuzzer/fuzzer.go new file mode 100644 index 000000000..ce0307a8a --- /dev/null +++ b/internal/apis/config/fuzzer/fuzzer.go @@ -0,0 +1,41 @@ +/* +Copyright 2021 The cert-manager 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 fuzzer + +import ( + fuzz "github.com/google/gofuzz" + runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer" + "k8s.io/utils/pointer" + + "github.com/jetstack/cert-manager/internal/apis/config" +) + +// Funcs returns the fuzzer functions for the apps api group. +var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} { + return []interface{}{ + func(s *config.WebhookConfiguration, c fuzz.Continue) { + c.FuzzNoCustom(s) // fuzz self without calling this function again + + if s.HealthzPort == nil { + s.HealthzPort = pointer.Int(12) + } + if s.SecurePort == nil { + s.SecurePort = pointer.Int(123) + } + }, + } +} diff --git a/internal/apis/config/install/BUILD.bazel b/internal/apis/config/install/BUILD.bazel index 05f0a4549..5cc101baf 100644 --- a/internal/apis/config/install/BUILD.bazel +++ b/internal/apis/config/install/BUILD.bazel @@ -29,19 +29,13 @@ filegroup( go_test( name = "go_default_test", - srcs = [ - "pruning_test.go", - "roundtrip_test.go", - ], + srcs = ["roundtrip_test.go"], data = [ "//deploy/crds:templated_files", ], embed = [":go_default_library"], deps = [ - "//internal/apis/acme/fuzzer:go_default_library", - "//pkg/api:go_default_library", - "//pkg/api/testing:go_default_library", - "@com_github_munnerz_crd_schema_fuzz//:go_default_library", + "//internal/apis/config/fuzzer:go_default_library", "@io_k8s_apimachinery//pkg/api/apitesting/roundtrip:go_default_library", ], ) diff --git a/internal/apis/config/install/pruning_test.go b/internal/apis/config/install/pruning_test.go deleted file mode 100644 index 9c82bdb00..000000000 --- a/internal/apis/config/install/pruning_test.go +++ /dev/null @@ -1,32 +0,0 @@ -/* -Copyright 2020 The cert-manager 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 install - -import ( - "testing" - - crdfuzz "github.com/munnerz/crd-schema-fuzz" - - acmefuzzer "github.com/jetstack/cert-manager/internal/apis/acme/fuzzer" - "github.com/jetstack/cert-manager/pkg/api" - apitesting "github.com/jetstack/cert-manager/pkg/api/testing" -) - -func TestPruneTypes(t *testing.T) { - crdfuzz.SchemaFuzzTestForCRDWithPath(t, api.Scheme, apitesting.PathForCRD(t, "orders"), acmefuzzer.Funcs) - crdfuzz.SchemaFuzzTestForCRDWithPath(t, api.Scheme, apitesting.PathForCRD(t, "challenges"), acmefuzzer.Funcs) -} diff --git a/internal/apis/config/install/roundtrip_test.go b/internal/apis/config/install/roundtrip_test.go index c634f2f00..29c588600 100644 --- a/internal/apis/config/install/roundtrip_test.go +++ b/internal/apis/config/install/roundtrip_test.go @@ -21,9 +21,9 @@ import ( "k8s.io/apimachinery/pkg/api/apitesting/roundtrip" - acmefuzzer "github.com/jetstack/cert-manager/internal/apis/acme/fuzzer" + configfuzzer "github.com/jetstack/cert-manager/internal/apis/config/fuzzer" ) func TestRoundTripTypes(t *testing.T) { - roundtrip.RoundTripTestForAPIGroup(t, Install, acmefuzzer.Funcs) + roundtrip.RoundTripTestForAPIGroup(t, Install, configfuzzer.Funcs) }