forked from mandiant/gocat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlers_test.go
55 lines (49 loc) · 1.25 KB
/
handlers_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
package gocat
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestLogLevelString(t *testing.T) {
for _, test := range []struct {
ll LogLevel
expected string
}{
{
ll: InfoMessage,
expected: "INFO",
},
{
ll: WarnMessage,
expected: "WARN",
},
{
ll: ErrorMessage,
expected: "ERROR",
},
{
ll: AdviceMessage,
expected: "ADVICE",
},
{
ll: LogLevel(9),
expected: "UNKNOWN",
},
} {
assert.Equal(t, test.expected, test.ll.String())
}
}
func TestGetCrackedPassword(t *testing.T) {
pl, err := getCrackedPassword(1, "deadbeefdeadbeefdeadbeefdeadbeef:chris", ":")
assert.Nilf(t, err, "expected err to be nil")
assert.Equalf(t, "chris", pl.Value, "expected the value to be chris")
assert.Equal(t, "deadbeefdeadbeefdeadbeefdeadbeef", pl.Hash, "expected the hash to be deadbeef yo!")
pl, err = getCrackedPassword(1, "deadbeefdeadbeefdeadbeefdeadbeef:chris", ";")
assert.Equalf(t, err, ErrCrackedPayload{
Separator: ";",
CrackedMsg: "deadbeefdeadbeefdeadbeefdeadbeef:chris",
}, "err payload is not correct")
ecperr, ok := err.(ErrCrackedPayload)
assert.True(t, ok)
assert.NotNil(t, ecperr)
assert.Equal(t, "Could not locate separator `;` in msg", err.Error())
}