-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathboast_test.go
129 lines (113 loc) · 2.77 KB
/
boast_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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package boast_test
import (
"reflect"
"testing"
"time"
app "github.com/ciphermarco/BOAST"
)
func TestNewEvent(t *testing.T) {
want := app.Event{
ID: "TEST ID",
Time: time.Now(),
TestID: "TEST TestID",
Receiver: "TEST Receiver",
RemoteAddr: "TEST RemoteAddr",
Dump: "TEST Dump",
}
got, err := app.NewEvent(
"TEST TestID",
"TEST Receiver",
"TEST RemoteAddr",
"TEST Dump",
)
if err != nil {
t.Errorf("unexpected error: %v (want) != %v (got)", nil, err)
}
if want.Time.UnixNano() >= got.Time.UnixNano() {
t.Errorf("wrong Time: %v (want) != %v (got)", want.Time, got.Time)
}
want.Time = got.Time
wantLenID := 26
gotLenID := len(got.ID)
if wantLenID != gotLenID {
t.Errorf("wrong ID length: %v (want) != %v (got)",
wantLenID, gotLenID)
}
want.ID = got.ID
if !reflect.DeepEqual(want, got) {
t.Errorf("wrong event")
t.Errorf("Want:")
t.Errorf("%+v", want)
t.Errorf("Got:")
t.Errorf("%+v", got)
}
}
func TestNewDNSEvent(t *testing.T) {
want := app.Event{
ID: "TEST ID",
Time: time.Now(),
TestID: "TEST TestID",
Receiver: "TEST Receiver",
RemoteAddr: "TEST RemoteAddr",
Dump: "TEST Dump",
QueryType: "TEST QueryType",
}
got, err := app.NewDNSEvent(
"TEST TestID",
"TEST Receiver",
"TEST RemoteAddr",
"TEST Dump",
"TEST QueryType",
)
if err != nil {
t.Errorf("unexpected error: %v (want) != %v (got)", nil, err)
}
if want.Time.UnixNano() >= got.Time.UnixNano() {
t.Errorf("wrong Time: %v (want) != %v (got)", want.Time, got.Time)
}
want.Time = got.Time
wantLenID := 26
gotLenID := len(got.ID)
if wantLenID != gotLenID {
t.Errorf("wrong ID length: %v (want) != %v (got)",
wantLenID, gotLenID)
}
want.ID = got.ID
if !reflect.DeepEqual(want, got) {
t.Errorf("wrong event")
t.Errorf("Want:")
t.Errorf("%+v", want)
t.Errorf("Got:")
t.Errorf("%+v", got)
}
}
func TestToBase32(t *testing.T) {
want := map[string]string{
"smcdpjlzu": "onwwgzdqnjwhu5i",
"bdwbpjiic": "mjshoytqnjuwsyy",
"epizdfjvnjt": "mvygs6temzvhm3tkoq",
"fahkwl": "mzqwq23xnq",
"xfzc": "pbthuyy",
"xvvdji": "pb3hmzdkne",
"ufmuhvebnxr": "ovtg25liozswe3tyoi",
"whelamjko": "o5ugk3dbnvvgw3y",
"amcaabgp": "mfwwgylbmjtxa",
"zkqsgvnkhs": "pjvxc43hozxgw2dt",
"dcbf": "mrrwezq",
"ceehfulcs": "mnswk2dgovwgg4y",
"rstfckezdp": "ojzxiztdnnsxuzdq",
"apbwwsoetv": "mfyge53xonxwk5dw",
"dpmvb": "mryg25tc",
"pgsl": "obtxg3a",
"tajzyt": "orqwu6tzoq",
"nufpbgwlqpxx": "nz2wm4dcm53wy4lqpb4a",
"vprqw": "ozyhe4lx",
"yhejthchj": "pfugk2tunbrwq2q",
}
for k, v := range want {
got := app.ToBase32([]byte(k))
if v != got {
t.Errorf("wrong base32: %v (want) != %v (got)", want, got)
}
}
}