-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
600f555
commit 07e7968
Showing
2 changed files
with
51 additions
and
59 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
|
||
} |