-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathproxyhandler_test.go
More file actions
52 lines (48 loc) · 1.28 KB
/
proxyhandler_test.go
File metadata and controls
52 lines (48 loc) · 1.28 KB
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
package proxyhandler
import (
"github.com/mailsac/smtpd"
"net"
"testing"
)
func Test_ProxyHandlerV1(t *testing.T) {
t.Run("ehlo", func(t *testing.T) {
proxyIPs := []string{"10.0.0.1", "10.0.0.2"}
p := ProxyHandlerV1{TrustIPs: proxyIPs}
p.EHLO()
})
t.Run("throws error when proxy not supported", func(t *testing.T) {
proxyIPs := []string{"10.0.0.5"}
p := ProxyHandlerV1{TrustIPs: proxyIPs}
server, client := net.Pipe()
defer server.Close()
defer client.Close()
// Do some stuff
conn := &smtpd.Conn{
Conn: client,
}
err := p.Handle(conn, "TCP4 10.0.0.99 2.2.2.2 33372 25")
if err == nil || err.Error() != "PROXY not allowed from 'pipe'" {
t.Errorf("Should not have allowed proxy: %s", err.Error())
t.Fail()
}
})
t.Run("sets and trusts IP when proxied", func(t *testing.T) {
proxyIPs := []string{"pipe"} // would be IP address in real life
p := ProxyHandlerV1{TrustIPs: proxyIPs}
server, client := net.Pipe()
defer server.Close()
defer client.Close()
// Do some stuff
conn := &smtpd.Conn{
Conn: client,
}
err := p.Handle(conn, "TCP4 45.76.28.175 10.0.0.12 33372 25")
if err != nil {
t.Error(err)
return
}
if conn.ForwardedForIP != "45.76.28.175" {
t.Errorf("forward addr not set as expected (%s)", conn.ForwardedForIP)
}
})
}