-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmispfeedgenerator_test.go
113 lines (98 loc) · 3.32 KB
/
mispfeedgenerator_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package mispfeedgenerator
import (
"testing"
)
// TestNewEvent test instanciation of MispEvent Object
func TestNewEvent(t *testing.T) {
_, err := NewMispEvent()
if err != nil {
t.Errorf("Could not create new event")
}
}
// TestAddAttributewithNoCategory checks when attribute with no category
// is added, the first found category is automatically put
func TestAddAttributewithNoCategory(t *testing.T) {
event, err := NewMispEvent()
if err != nil {
t.Errorf("Could not create new event")
}
event.Info = "Dummy event"
event.Orgc.Name = "TEST ORG"
event.Orgc.UUID = "dc9de8b2-889c-42e5-a65f-68ecda38eed0"
err = event.AddAttribute("btc", "111a3246asd8asd4a8asf5as8afs65fd77a", "")
if err != nil {
t.Errorf("Could not add attribute")
}
if event.Attribute[0].Category == "" {
t.Errorf("Category could not be put automatically for attribute")
}
}
// TestAddTagsToEvent tests tag adding to event
func TestAddTagsToEvent(t *testing.T) {
event, err := NewMispEvent()
if err != nil {
t.Errorf("Could not create new event")
}
event.Info = "Dummy event"
event.Orgc.Name = "TEST ORG"
event.Orgc.UUID = "dc9de8b2-889c-42e5-a65f-68ecda38eed0"
event.AddTag("test", "#004646")
event.AddTag("test2", "#005151")
if len(event.Tag) != 2 {
t.Errorf("Could not add tags")
}
}
// TestAddAttributewithValidCategory checks when a valid category is put to attribute
// it passes the checking logic and stored in object
func TestAddAttributewithValidCategory(t *testing.T) {
event, err := NewMispEvent()
if err != nil {
t.Errorf("Could not create new event")
}
event.Info = "Dummy event"
event.Orgc.Name = "TEST ORG"
event.Orgc.UUID = "dc9de8b2-889c-42e5-a65f-68ecda38eed0"
err = event.AddAttribute("email-dst", "[email protected]", "Network activity")
if err != nil {
t.Errorf("Could not add attribute")
}
if event.Attribute[0].Category != "Network activity" {
t.Errorf("Category could not be put automatically for attribute")
}
}
// TestAddAttributewithValidCategory checks when a valid category is put to attribute
// it fails the checking logic and throws error
func TestAddAttributewithInvalidCategory(t *testing.T) {
event, err := NewMispEvent()
if err != nil {
t.Errorf("Could not create new event")
}
event.Info = "Dummy event"
event.Orgc.Name = "TEST ORG"
event.Orgc.UUID = "dc9de8b2-889c-42e5-a65f-68ecda38eed0"
err = event.AddAttribute("btc", "111a3246asd8asd4a8asf5as8afs65fd77a", "Network activity")
if err == nil {
t.Errorf("Type-Category check does not work")
}
}
// TestFeedGenerationWithMetadata testing if feed with manifest.json and hashes.csv
// can be generated without errors. This test does not check the generated files.
func TestFeedGenerationWithMetadata(t *testing.T) {
defer cleanGeneratedFiles()
event, err := NewMispEvent()
if err != nil {
t.Errorf("Could not create new event")
}
event.Info = "Dummy event"
event.Orgc.Name = "TEST ORG"
event.Orgc.UUID = "dc9de8b2-889c-42e5-a65f-68ecda38eed0"
event.AddTag("test", "#004646")
event.AddTag("test2", "#005151")
event.AddAttribute("email-dst", "[email protected]", "Network activity")
event.AddAttribute("btc", "111a3246asd8asd4a8asf5as8afs65fd77a", "")
event.AddAttribute("md5", "111847356890723489034292345875234", "")
err = event.GenerateFeed(true)
if err != nil {
t.Errorf("Could not generate feed with manifest and hashes. Error: %s", err)
}
}