Skip to content

Commit

Permalink
Added fuzzing targets for capm3.
Browse files Browse the repository at this point in the history
  • Loading branch information
as20203 committed Jul 19, 2023
1 parent 053874a commit 44d89dd
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 2 deletions.
38 changes: 38 additions & 0 deletions test/fuzz/metal3cluster_manager_test_fuzzer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package fuzz_test

import (
fuzz "github.com/AdaLogics/go-fuzz-headers"
"github.com/go-logr/logr"
infrav1 "github.com/metal3-io/cluster-api-provider-metal3/api/v1beta1"
"github.com/metal3-io/cluster-api-provider-metal3/baremetal"
"golang.org/x/exp/slices"
)

func FuzzTestFinalizers(data []byte) int {
f := fuzz.NewConsumer(data)
template := &infrav1.Metal3DataTemplate{}
err := f.GenerateStruct(template)
if err != nil {
return 0
}
templateMgr, err := baremetal.NewDataTemplateManager(nil, template,
logr.Discard(),
)
if err != nil {
return 0
}

templateMgr.SetFinalizer()

if !slices.Contains(template.ObjectMeta.Finalizers, infrav1.DataTemplateFinalizer) {
return 0
}

templateMgr.UnsetFinalizer()

if slices.Contains(template.ObjectMeta.Finalizers, infrav1.DataTemplateFinalizer) {
return 0
}

return 1
}
8 changes: 6 additions & 2 deletions test/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ replace sigs.k8s.io/cluster-api/test => sigs.k8s.io/cluster-api/test v1.4.2
replace github.com/metal3-io/cluster-api-provider-metal3/api => ./../api

require (
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230106234847-43070de90fa1 // indirect
github.com/BurntSushi/toml v1.0.0 // indirect
github.com/MakeNowJust/heredoc v1.0.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
Expand All @@ -42,6 +43,7 @@ require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/coredns/caddy v1.1.1 // indirect
github.com/coredns/corefile-migration v1.0.20 // indirect
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
Expand All @@ -66,7 +68,7 @@ require (
github.com/google/go-github/v48 v48.2.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
Expand All @@ -80,6 +82,7 @@ require (
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/metal3-io/baremetal-operator/pkg/hardwareutils v0.3.0 // indirect
github.com/metal3-io/cluster-api-provider-metal3 v1.4.1
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
Expand All @@ -106,7 +109,8 @@ require (
github.com/subosito/gotenv v1.4.2 // indirect
github.com/valyala/fastjson v1.6.4 // indirect
golang.org/x/crypto v0.10.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/oauth2 v0.6.0 // indirect
golang.org/x/sys v0.9.0 // indirect
Expand Down
Loading

0 comments on commit 44d89dd

Please sign in to comment.