summaryrefslogtreecommitdiff
path: root/tcpproxy_test.go
diff options
context:
space:
mode:
authorDavid Anderson <[email protected]>2017-07-05 18:18:48 -0700
committerDave Anderson <[email protected]>2017-07-06 20:08:35 -0700
commit2065af4b1e2d181a987a23f64c66f43e474469ff (patch)
tree70ef7d0d85f2095ec3d63a03d9ad011ecc5d74b4 /tcpproxy_test.go
parente03035937341374a9be6eb8459ffe4f23bacd185 (diff)
Support HAProxy's PROXY protocol v1 in DialProxy.
Diffstat (limited to 'tcpproxy_test.go')
-rw-r--r--tcpproxy_test.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/tcpproxy_test.go b/tcpproxy_test.go
index 4cfb0ab..45d8b0e 100644
--- a/tcpproxy_test.go
+++ b/tcpproxy_test.go
@@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"io"
+ "io/ioutil"
"net"
"strings"
"testing"
@@ -268,3 +269,42 @@ func TestProxySNI(t *testing.T) {
t.Fatalf("got %q; want %q", buf, msg)
}
}
+
+func TestProxyPROXYOut(t *testing.T) {
+ front := newLocalListener(t)
+ defer front.Close()
+ back := newLocalListener(t)
+ defer back.Close()
+
+ p := testProxy(t, front)
+ p.AddRoute(testFrontAddr, &DialProxy{
+ Addr: back.Addr().String(),
+ ProxyProtocolVersion: 1,
+ })
+ if err := p.Start(); err != nil {
+ t.Fatal(err)
+ }
+
+ toFront, err := net.Dial("tcp", front.Addr().String())
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ io.WriteString(toFront, "foo")
+ toFront.Close()
+
+ fromProxy, err := back.Accept()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ bs, err := ioutil.ReadAll(fromProxy)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ want := fmt.Sprintf("PROXY TCP4 %s %d %s %d\r\nfoo", toFront.LocalAddr().(*net.TCPAddr).IP, toFront.LocalAddr().(*net.TCPAddr).Port, toFront.RemoteAddr().(*net.TCPAddr).IP, toFront.RemoteAddr().(*net.TCPAddr).Port)
+ if string(bs) != want {
+ t.Fatalf("got %q; want %q", bs, want)
+ }
+}