-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathheaderv1_test.go
45 lines (41 loc) · 1.04 KB
/
headerv1_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
package proxyprotocol
import (
"bytes"
"net"
"testing"
"github.com/stretchr/testify/assert"
)
func TestHeaderV1_WriteTo(t *testing.T) {
check := func(name string, hdr HeaderV1, exp string) {
t.Helper()
buf := new(bytes.Buffer)
_, err := hdr.WriteTo(buf)
assert.NoError(t, err, name)
assert.Equal(t, exp, buf.String(), name)
}
check("blank", HeaderV1{}, "PROXY UNKNOWN\r\n")
check("ipv4", HeaderV1{
SrcPort: 1234,
DestPort: 5678,
SrcIP: net.ParseIP("192.168.0.1"),
DestIP: net.ParseIP("192.168.0.2"),
},
"PROXY TCP4 192.168.0.1 192.168.0.2 1234 5678\r\n",
)
check("ipv4-6-mismatch", HeaderV1{
SrcPort: 1234,
DestPort: 5678,
SrcIP: net.ParseIP("2001:db8:85a3::8a2e:370:7334"),
DestIP: net.ParseIP("192.168.0.2"),
},
"PROXY UNKNOWN\r\n",
)
check("ipv6", HeaderV1{
SrcPort: 1234,
DestPort: 5678,
SrcIP: net.ParseIP("2001:db8:85a3::8a2e:370:7334"),
DestIP: net.ParseIP("2002:db8:85a3::8a2e:370:7334"),
},
"PROXY TCP6 2001:db8:85a3::8a2e:370:7334 2002:db8:85a3::8a2e:370:7334 1234 5678\r\n",
)
}