-
Notifications
You must be signed in to change notification settings - Fork 16
/
definitions_test.go
71 lines (55 loc) · 1.44 KB
/
definitions_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
package main
import (
"fmt"
"io/ioutil"
"testing"
)
// Test the initialization of the definition manager
func TestNewDefinitionsManager(t *testing.T) {
manager, err := NewDefinitionManager()
if err != nil {
t.Fatal(err)
}
if manager == nil {
t.Fatal("Failed to initialize the definitions download manager")
}
// fmt.Println(manager.EtagMain)
// fmt.Println(manager.EtagDaily)
// fmt.Println(manager.PublicKeyData.Type)
fmt.Println("OK. DefinitionManager init SUCCESS")
}
// Test the parsing of the Clamav virus DB header
func TestParseHeader(t *testing.T) {
// Read all data
data, err := ioutil.ReadFile("main_test.cvd")
if err != nil {
t.Fatal(err)
}
def, err := parseHeader(data)
if err != nil {
t.Fatal(err)
}
if def.Level != 60 {
t.Errorf("Parsing Level header, expected level 60, got %s\n", def.Level)
}
if def.TotalSignatures != 2424225 {
t.Errorf("Parsing TotalSignatures header, expected level 2424225, got %s\n", def.TotalSignatures)
}
if def.Version != 55 {
t.Errorf("Parsing TotalSignatures header, expected level 55, got %s\n", def.Version)
}
if def.MD5Hash == "" {
t.Error("Parsing MD5 hash header and got it empty")
}
if def.Signature == "" {
t.Error("Parsing Signature header and got it empty")
}
files, err := extractFiles(data, MAIN_DEFINITION)
if err != nil {
t.Fatal(err)
}
if len(files) == 0 {
t.Fatal("Could not extract a single file")
}
fmt.Println("OK. Header parsing SUCCESS")
}