This repository has been archived by the owner on Feb 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
process_test.go
64 lines (55 loc) · 1.62 KB
/
process_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
package cortexbot
import (
"fmt"
"testing"
cortex "github.com/ilyaglow/go-cortex/v3"
)
func TestObservableConstructor(t *testing.T) {
var cases = []struct {
data string
tlp cortex.TLP
pap cortex.PAP
dataType string
}{
{"1.1.1.1", cortex.TLPWhite, cortex.PAPWhite, "ip"},
{"https://subdomain.domain.com/route/query?param=val", cortex.TLPGreen, cortex.PAPGreen, "url"},
{"subdomain.domain.com", cortex.TLPAmber, cortex.PAPAmber, "domain"},
{"[email protected]", cortex.TLPRed, cortex.PAPRed, "mail"},
{"[email protected]", cortex.TLPRed, cortex.PAPRed, "mail"},
{"a94a8fe5ccb19ba61c4c0873d391e987982fbbd3", cortex.TLPWhite, cortex.PAPWhite, "hash"},
{"randomdata", cortex.TLPGreen, cortex.PAPGreen, "other"},
}
for _, c := range cases {
a := newArtifact(c.data, c.tlp, c.pap)
if a.Description() != c.data {
t.Errorf("need %s, got %s", c.data, a.Description())
}
if a.Type() != c.dataType {
t.Errorf("need %s, got %s", c.dataType, a.Type())
}
}
}
func TestBuildTaxonomies(t *testing.T) {
var txs []cortex.Taxonomy
tx1 := cortex.Taxonomy{
Predicate: "Predicate1",
Namespace: "Namespace1",
Value: "Value1",
Level: "safe",
}
txs = append(txs, tx1)
tx2 := cortex.Taxonomy{
Predicate: "Predicate2",
Namespace: "Namespace2",
Value: "Value2",
Level: "info",
}
txs = append(txs, tx2)
expected := fmt.Sprintf("%s:%s = %s\n%s:%s = %s",
tx1.Namespace, tx1.Predicate, tx1.Value,
tx2.Namespace, tx2.Predicate, tx2.Value,
)
if buildTaxonomies(txs) != expected {
t.Errorf("Wrong taxonomies format:\n%s\n%s", expected, buildTaxonomies(txs))
}
}