Skip to content

Commit

Permalink
Move fuzzers upstream from cncf-fuzzing
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Korczynski <[email protected]>
  • Loading branch information
AdamKorcz committed Jan 15, 2025
1 parent 30541a1 commit c2aea57
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/reconciler/sensor/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,20 @@ func FuzzSensorControllerReconcile(f *testing.F) {
_ = Reconcile(cl, nil, args, logging.NewArgoEventsLogger())
})
}

func FuzzValidateSensor(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fdp := fuzz.NewConsumer(data)
eventBus := &eventbusv1alpha1.EventBus{}
err := fdp.GenerateStruct(eventBus)
if err != nil {
return
}
sensor := &eventbusv1alpha1.Sensor{}
err = fdp.GenerateStruct(sensor)
if err != nil {
return
}
_ = ValidateSensor(sensor, eventBus)
})
}
53 changes: 53 additions & 0 deletions pkg/sensors/fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright 2025 The Argoproj 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 sensors

import (
"context"
"testing"

fuzz "github.com/AdaLogics/go-fuzz-headers"
"github.com/argoproj/argo-events/pkg/apis/events/v1alpha1"
)

func FuzzGetDependencyExpression(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fdp := fuzz.NewConsumer(data)
templBytes, err := fdp.GetBytes()

Check failure on line 27 in pkg/sensors/fuzz_test.go

View workflow job for this annotation

GitHub Actions / lint

declared and not used: templBytes (typecheck)

Check failure on line 27 in pkg/sensors/fuzz_test.go

View workflow job for this annotation

GitHub Actions / Unit Tests

declared and not used: templBytes
if err != nil {
return
}
templ := &v1alpha1.TriggerTemplate{}
err = fdp.GenerateStruct(templ)
if err != nil {
return
}
sensorObj := &v1alpha1.Sensor{}
err = fdp.GenerateStruct(sensorObj)
if err != nil {
return
}
ft := &v1alpha1.Trigger{}
err = fdp.GenerateStruct(ft)
if err != nil {
return
}
ft.Template = templ
sensorObj.Spec.Triggers = []v1alpha1.Trigger{*ft}
sensorCtx := &SensorContext{
sensor: sensorObj,
}
_, _ = sensorCtx.getDependencyExpression(context.Background(), *ft)
})
}
50 changes: 50 additions & 0 deletions pkg/sensors/triggers/argo-workflow/fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright 2025 The Argoproj 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 argo_workflow

import (
"context"
"testing"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/yaml"
)

func bytesToUnstructuredFuzz(jsonBytes []byte) (*unstructured.Unstructured, error) {
obj := make(map[string]interface{})
err := yaml.Unmarshal(jsonBytes, &obj)
if err != nil {
return nil, err
}
return &unstructured.Unstructured{Object: obj}, nil
}
func FuzzArgoWorkflowTriggerExecute(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
ctx := context.Background()
var actual string
firstArg := "--foo"
secondArg := "--bar"
unstr, err := bytesToUnstructuredFuzz(data)
if err != nil {
return
}
trigger := storingCmdTrigger(&actual, firstArg, secondArg)
_, err = namespacedClientFrom(trigger).Namespace(unstr.GetNamespace()).Create(ctx, unstr, metav1.CreateOptions{})
if err != nil {
return
}
_, _ = trigger.Execute(ctx, nil, unstr)
})
}
33 changes: 33 additions & 0 deletions pkg/shared/expr/fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright 2025 The Argoproj 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 expr

import (
"encoding/json"
"testing"
)

func FuzzExpr(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte, input string) {
env := make(map[string]interface{})
err := json.Unmarshal(data, &env)
if err != nil {
return
}
_, _ = EvalBool(input, env)
})
}

0 comments on commit c2aea57

Please sign in to comment.