-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathyara_test.go
75 lines (68 loc) · 1.71 KB
/
yara_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package filetrove
import (
yarax "github.com/VirusTotal/yara-x/go"
"os"
"reflect"
"testing"
)
// TestYaraCompile checks if a rule from a text file can be compiled, so
// we just check for the wanted error, which is false.
func TestYaraCompile(t *testing.T) {
type args struct {
ruleString string
}
tests := []struct {
name string
args args
// want *yarax.Rules
wantErr bool
}{
{"Successful compile", args{"testdata/yara/testrule.yara"}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
//got, err := YaraCompile(tt.args.ruleString)
_, err := YaraCompile(tt.args.ruleString)
if (err != nil) != tt.wantErr {
t.Errorf("YaraCompile() error = %v, wantErr %v", err, tt.wantErr)
return
}
/*if !reflect.DeepEqual(got, tt.want) {
t.Errorf("YaraCompile() got = %v, want %v", got, tt.want)
}*/
})
}
}
func TestYaraScan(t *testing.T) {
type args struct {
rules *yarax.Rules
inFile string
}
// Compile rules for match testing.
rules, err := YaraCompile("testdata/yara/testrule.yara")
if err != nil {
println("yara compilation error:", err)
os.Exit(1)
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
{"Yara Matching Test Rule", args{rules, "testdata/transparent.png"}, "TestPNGRule", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := YaraScan(tt.args.rules, tt.args.inFile)
if (err != nil) != tt.wantErr {
t.Errorf("YaraScan() error = %v, wantErr %v", err, tt.wantErr)
return
}
matchedRule := got.MatchingRules()[0]
if !reflect.DeepEqual(matchedRule.Identifier(), tt.want) {
t.Errorf("YaraScan() got = %v, want %v", got, tt.want)
}
})
}
}