-
Notifications
You must be signed in to change notification settings - Fork 2
/
artifacts_test.go
92 lines (69 loc) · 2.13 KB
/
artifacts_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
package go4th
import (
"testing"
)
func TestAddArtifact(t *testing.T) {
alert := NewAlert()
art, err := NewArtifact("file", "./testData/thehive.txt")
if err != nil {
t.Errorf("unexpected error: %s", err.Error())
}
alert.AddArtifact(art)
if len(alert.Artifacts) != 1 {
t.Errorf("expecting one artifact, but found %d", len(alert.Artifacts))
}
}
func TestSetTLPArtifact(t *testing.T) {
art, err := NewArtifact("file", "./testData/thehive.txt")
if err != nil {
t.Errorf("unexpected error: %s", err.Error())
}
if art.TLP != Amber {
t.Errorf("expected TLP to be %d, but found %d", Amber, art.TLP)
}
art.SetTLP(Red)
if art.TLP != Red {
t.Errorf("expected TLP to be %d, but found %d", Red, art.TLP)
}
err = art.SetTLP(10)
if err != nil && err.Error() != "tlp provided is not a valid value" {
t.Errorf("expected tlp provided is not a valid value as error, but none was found")
}
}
func TestSetMessage(t *testing.T) {
art, err := NewArtifact("file", "./testData/thehive.txt")
if err != nil {
t.Errorf("unexpected error: %s", err.Error())
}
if art.Message != "" {
t.Errorf("expected Message to be empty, but found %s", art.Message)
}
art.SetMessage("Testing")
if art.Message != "Testing" {
t.Errorf("expected Message to be Testing, but found %s", art.Message)
}
err = art.SetMessage("")
if err != nil && err.Error() != "msg could not be empty" {
t.Errorf("expected msg could not be empty as error, but none was found")
}
}
func TestSetTagsArtifact(t *testing.T) {
art, err := NewArtifact("file", "./testData/thehive.txt")
if err != nil {
t.Errorf("unexpected error: %s", err.Error())
}
if len(art.Tags) != 0 {
t.Errorf("expected Tags to be empty, but found %d", len(art.Tags))
}
art.SetTags([]string{"one", "two"})
if len(art.Tags) != 2 {
t.Errorf("expected Tags to have two, but found %d", len(art.Tags))
}
if art.Tags[0] != "one" || art.Tags[1] != "two" {
t.Errorf("expected Tags to be [one, two], but found %s", art.Tags)
}
err = art.SetTags([]string{})
if err != nil && err.Error() != "tags could not be empty" {
t.Errorf("expected tags could not be empty as error, but none was found")
}
}