Skip to content

Commit

Permalink
Migrate fuzz test to testing.F
Browse files Browse the repository at this point in the history
  • Loading branch information
bradleyjkemp committed Apr 17, 2024
1 parent 600f555 commit 07e7968
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 59 deletions.
59 changes: 0 additions & 59 deletions evaluator/fuzz.go

This file was deleted.

51 changes: 51 additions & 0 deletions evaluator/fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package evaluator

import (
"context"
"encoding/json"
"testing"

"github.com/bradleyjkemp/sigma-go"
)

const testRule = `
id: TEST_RULE
detection:
a:
Foo|contains: bar
b:
Bar|endswith: baz
condition: a and b
`

const testConfig = `
title: Test
logsources:
test:
product: test
fieldmappings:
Foo: $.foo
Bar: $.foobar.baz
`

func FuzzRuleMatches(f *testing.F) {
f.Add(testRule, testConfig, `{"foo": "bar", "bar": "baz"}`)
f.Fuzz(func(t *testing.T, rule, config, payload string) {
r, err := sigma.ParseRule([]byte(rule))
if err != nil {
return
}
c, err := sigma.ParseConfig([]byte(config))
if err != nil {
return
}

var e Event
json.Unmarshal([]byte(payload), &e)

eval := ForRule(r, WithConfig(c))
_, err = eval.Matches(context.Background(), e)
})

}

0 comments on commit 07e7968

Please sign in to comment.