summaryrefslogtreecommitdiff
path: root/pkg/test/proxy_test.go
blob: 46782d20767c194abd71210ac6427a75b3db7c44 (plain)
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
package test

import (
	"testing"
)

func TestProxyHook(t *testing.T) {
	e := newEnv(t)
	defer e.Free()

	c := e.newInstance()

	c.Exec("add name C listen,addr=%%0 proxy,addr=@[addr] dial,addr=@[tunnel.S.listen]")
	c.Exec("add name S listen,addr=%%0 proxy")

	c.Exec("set tunnel.S.proxy.auth user:password")
	c.Exec("set tunnel.C.proxy.auth user:password")

	listen := e.Listen("tcp", "127.0.0.1:0")
	c.Set("addr", listen.Addr())

	out := e.Dial("tcp", c.Get("tunnel.C.listen"))
	in := e.Accept(listen)

	e.Write(out, dummy)

	buf := make([]byte, len(dummy))
	e.ReadFull(in, buf)

	if r := string(buf); r != dummy {
		t.Fatalf("wrong reply: send '%s', recv '%s'", dummy, r)
	}
}