-
Notifications
You must be signed in to change notification settings - Fork 4
/
fp_rule_test.go
57 lines (47 loc) · 1.33 KB
/
fp_rule_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package limacharlie
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestFPRuleList(t *testing.T) {
a := assert.New(t)
org := getTestOrgFromEnv(a)
_, err := org.FPRules()
a.NoError(err)
}
func TestFPRuleAddDelete(t *testing.T) {
a := assert.New(t)
org := getTestOrgFromEnv(a)
rules, err := org.FPRules()
a.NoError(err)
a.Empty(rules, "unexpected preexisting rules in list: %+v", rules)
fpRuleName := "testrule" + "-" + randSeq(6)
err = org.FPRuleAdd(fpRuleName, Dict{
"op": "ends with",
"path": "detect/event/FILE_PATH",
"value": "this_is_fine.exe",
})
a.NoError(err)
err = org.FPRuleAdd(fpRuleName, Dict{
"op": "ends with",
"path": "detect/event/FILE_PATH",
"value": "this_is_fine_again.exe",
})
a.Error(err, "adding a rule with the same name should raise an error: %s", err)
err = org.FPRuleAdd(fpRuleName, Dict{
"op": "ends with",
"path": "detect/event/FILE_PATH",
"value": "this_is_fine_again.exe",
}, FPRuleOptions{IsReplace: true})
a.NoError(err, "replacing a rule should not raise an error: %s", err)
rules, err = org.FPRules()
a.NoError(err)
a.GreaterOrEqual(1, len(rules))
err = org.FPRuleDelete(fpRuleName)
a.NoError(err)
rules, err = org.FPRules()
a.NoError(err)
if _, ok := rules[fpRuleName]; ok {
t.Errorf("fp rule with key %s was not deleted ", fpRuleName)
}
}