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 fc276af
Show file tree
Hide file tree
Showing 4 changed files with 149 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)
})
}
49 changes: 49 additions & 0 deletions pkg/sensors/fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
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)
templ := &v1alpha1.TriggerTemplate{}
err = fdp.GenerateStruct(templ)

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

View workflow job for this annotation

GitHub Actions / lint

undefined: err

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

View workflow job for this annotation

GitHub Actions / Unit Tests

undefined: err
if err != nil {

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

View workflow job for this annotation

GitHub Actions / lint

undefined: err

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

View workflow job for this annotation

GitHub Actions / Unit Tests

undefined: err
return
}
sensorObj := &v1alpha1.Sensor{}
err = fdp.GenerateStruct(sensorObj)

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

View workflow job for this annotation

GitHub Actions / lint

undefined: err

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

View workflow job for this annotation

GitHub Actions / Unit Tests

undefined: err
if err != nil {

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

View workflow job for this annotation

GitHub Actions / lint

undefined: err

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

View workflow job for this annotation

GitHub Actions / Unit Tests

undefined: err
return
}
ft := &v1alpha1.Trigger{}
err = fdp.GenerateStruct(ft)

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

View workflow job for this annotation

GitHub Actions / lint

undefined: err

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

View workflow job for this annotation

GitHub Actions / Unit Tests

undefined: err
if err != nil {

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

View workflow job for this annotation

GitHub Actions / lint

undefined: err (typecheck)

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

View workflow job for this annotation

GitHub Actions / Unit Tests

undefined: err
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 fc276af

Please sign in to comment.