Skip to content

Commit

Permalink
added fuzz tests for subscriber (#4507)
Browse files Browse the repository at this point in the history
* added fuzz tests for subscriber

Signed-off-by: Amit Kumar Das <amit.das@harness.io>

* fixed go fmt

Signed-off-by: Amit Kumar Das <amit.das@harness.io>

---------

Signed-off-by: Amit Kumar Das <amit.das@harness.io>
Co-authored-by: Vedant Shrotria <vedant.shrotria@harness.io>
  • Loading branch information
amityt and Jonsy13 authored Mar 13, 2024
1 parent 916d3d3 commit 731bdc4
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 0 deletions.
2 changes: 2 additions & 0 deletions chaoscenter/subscriber/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module subscriber
go 1.20

require (
github.com/golang/mock v1.6.0
github.com/argoproj/argo-workflows/v3 v3.3.1
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/gorilla/websocket v1.5.0
Expand All @@ -13,6 +14,7 @@ require (
k8s.io/api v0.26.0
k8s.io/apimachinery v0.26.0
k8s.io/client-go v12.0.0+incompatible
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24
)

require (
Expand Down
5 changes: 5 additions & 0 deletions chaoscenter/subscriber/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiy
cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos=
cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU=
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8=
github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
github.com/Azure/go-autorest/autorest v0.11.12/go.mod h1:eipySxLmqSyC5s5k1CLupqet0PSENBEDP93LQ9a8QYw=
github.com/Azure/go-autorest/autorest/adal v0.9.5/go.mod h1:B7KF7jKIeC9Mct5spmyCB/A8CG/sEz1vwIRGv/bbw7A=
Expand Down Expand Up @@ -100,6 +102,8 @@ github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down Expand Up @@ -381,6 +385,7 @@ golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjs
golang.org/x/tools v0.0.0-20200505023115-26f46d2f7ef8/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
192 changes: 192 additions & 0 deletions chaoscenter/subscriber/pkg/events/mocks/events.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("0")
42 changes: 42 additions & 0 deletions chaoscenter/subscriber/pkg/events/utils_fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package events

import (
"fmt"
"subscriber/pkg/graphql"
"subscriber/pkg/k8s"
"subscriber/pkg/types"
"testing"

fuzz "github.com/AdaLogics/go-fuzz-headers"
"github.com/golang/mock/gomock"
)

func FuzzGenerateWorkflowPayload(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzzConsumer := fuzz.NewConsumer(data)

targetStruct := &struct {
cid, accessKey, version, completed string
wfEvent types.WorkflowEvent
}{}
err := fuzzConsumer.GenerateStruct(targetStruct)
if err != nil {
return
}

ctrl := gomock.NewController(t)
defer ctrl.Finish()
subscriberGraphql := graphql.NewSubscriberGql()
subscriberK8s := k8s.NewK8sSubscriber(subscriberGraphql)
subscriberEvents := NewSubscriberEventsOperator(subscriberGraphql, subscriberK8s)

event, err := subscriberEvents.GenerateWorkflowPayload(targetStruct.cid, targetStruct.accessKey, targetStruct.version, targetStruct.completed, targetStruct.wfEvent)
if err != nil {
fmt.Println(event)
t.Errorf("Unexpected error: %v", err)
}
if event == nil {
t.Errorf("Returned payload is nil")
}
})
}

0 comments on commit 731bdc4

Please sign in to comment.