-
Notifications
You must be signed in to change notification settings - Fork 3
/
cryptolog_test.go
51 lines (44 loc) · 1.48 KB
/
cryptolog_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
package main
import (
"regexp"
"testing"
)
func TestHashIp(t *testing.T) {
salt = []byte("ueErQYkQp5A9LrNbRQ1+XQ==")
ip := "172.17.0.1"
want := "JKx+3b"
if got := hashIP(ip); got != want {
t.Errorf("want %s, got %s", want, got)
}
}
func TestProcessSingleLogEntry(t *testing.T) {
salt = []byte("ueErQYkQp5A9LrNbRQ1+XQ==")
replaceAllRegexp := compileRegexp(true)
replaceOneRegexp := compileRegexp(false)
var tests = []struct {
input string
want string
r *regexp.Regexp
}{
{`[29/Mar/2017:20:09:52 +0000] "GET / HTTP/1.1" 304 -`,
`[29/Mar/2017:20:09:52 +0000] "GET / HTTP/1.1" 304 -`,
replaceAllRegexp},
{`172.17.0.1 - - [29/Mar/2017:20:09:52 +0000] "GET / HTTP/1.1" 304 -`,
`JKx+3b - - [29/Mar/2017:20:09:52 +0000] "GET / HTTP/1.1" 304 -`,
replaceAllRegexp},
{`172.17.0.1 - - 172.17.0.1 - - [29/Mar/2017:20:09:52 +0000] "GET / HTTP/1.1" 304 -`,
`JKx+3b - - JKx+3b - - [29/Mar/2017:20:09:52 +0000] "GET / HTTP/1.1" 304 -`,
replaceAllRegexp},
{`172.17.0.1 - - [29/Mar/2017:20:09:52 +0000] "GET / HTTP/1.1" 304 -`,
`JKx+3b - - [29/Mar/2017:20:09:52 +0000] "GET / HTTP/1.1" 304 -`,
replaceOneRegexp},
{`172.17.0.1 - - 172.17.0.1 - - [29/Mar/2017:20:09:52 +0000] "GET / HTTP/1.1" 304 -`,
`JKx+3b - - 172.17.0.1 - - [29/Mar/2017:20:09:52 +0000] "GET / HTTP/1.1" 304 -`,
replaceOneRegexp},
}
for _, test := range tests {
if got := processSingleLogEntry(test.input, test.r); got != test.want {
t.Errorf("want %s, got %s", test.want, got)
}
}
}