mirror of
https://github.com/mmatczuk/go-http-tunnel.git
synced 2026-05-15 14:16:17 -06:00
integration test: enable auto subscribe
This commit is contained in:
parent
fb55a4ac8a
commit
0d8131b0e4
1 changed files with 7 additions and 19 deletions
|
|
@ -7,7 +7,6 @@ package tunnel_test
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"crypto/x509"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
@ -22,7 +21,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/mmatczuk/go-http-tunnel"
|
"github.com/mmatczuk/go-http-tunnel"
|
||||||
"github.com/mmatczuk/go-http-tunnel/id"
|
|
||||||
"github.com/mmatczuk/go-http-tunnel/log"
|
"github.com/mmatczuk/go-http-tunnel/log"
|
||||||
"github.com/mmatczuk/go-http-tunnel/proto"
|
"github.com/mmatczuk/go-http-tunnel/proto"
|
||||||
)
|
)
|
||||||
|
|
@ -92,16 +90,15 @@ func makeEcho(t testing.TB) (http net.Listener, tcp net.Listener) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeTunnelServer(t testing.TB) *tunnel.Server {
|
func makeTunnelServer(t testing.TB) *tunnel.Server {
|
||||||
cert, identifier := selfSignedCert()
|
|
||||||
s, err := tunnel.NewServer(&tunnel.ServerConfig{
|
s, err := tunnel.NewServer(&tunnel.ServerConfig{
|
||||||
Addr: ":0",
|
Addr: ":0",
|
||||||
TLSConfig: tlsConfig(cert),
|
AutoSubscribe: true,
|
||||||
Logger: log.NewStdLogger(),
|
TLSConfig: tlsConfig(),
|
||||||
|
Logger: log.NewStdLogger(),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
s.Subscribe(identifier)
|
|
||||||
go s.Start()
|
go s.Start()
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
|
@ -131,10 +128,9 @@ func makeTunnelClient(t testing.TB, serverAddr string, httpLocalAddr, httpAddr,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cert, _ := selfSignedCert()
|
|
||||||
c, err := tunnel.NewClient(&tunnel.ClientConfig{
|
c, err := tunnel.NewClient(&tunnel.ClientConfig{
|
||||||
ServerAddr: serverAddr,
|
ServerAddr: serverAddr,
|
||||||
TLSClientConfig: tlsConfig(cert),
|
TLSClientConfig: tlsConfig(),
|
||||||
Tunnels: tunnels,
|
Tunnels: tunnels,
|
||||||
Proxy: tunnel.Proxy(tunnel.ProxyFuncs{
|
Proxy: tunnel.Proxy(tunnel.ProxyFuncs{
|
||||||
HTTP: httpProxy.Proxy,
|
HTTP: httpProxy.Proxy,
|
||||||
|
|
@ -319,23 +315,15 @@ func port(addr net.Addr) string {
|
||||||
return fmt.Sprint(addr.(*net.TCPAddr).Port)
|
return fmt.Sprint(addr.(*net.TCPAddr).Port)
|
||||||
}
|
}
|
||||||
|
|
||||||
func selfSignedCert() (tls.Certificate, id.ID) {
|
func tlsConfig() *tls.Config {
|
||||||
cert, err := tls.LoadX509KeyPair("./testdata/selfsigned.crt", "./testdata/selfsigned.key")
|
cert, err := tls.LoadX509KeyPair("./testdata/selfsigned.crt", "./testdata/selfsigned.key")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
x509Cert, err := x509.ParseCertificate(cert.Certificate[0])
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return cert, id.New(x509Cert.Raw)
|
|
||||||
}
|
|
||||||
|
|
||||||
func tlsConfig(cert tls.Certificate) *tls.Config {
|
|
||||||
c := &tls.Config{
|
c := &tls.Config{
|
||||||
Certificates: []tls.Certificate{cert},
|
Certificates: []tls.Certificate{cert},
|
||||||
ClientAuth: tls.RequestClientCert,
|
ClientAuth: tls.RequireAnyClientCert,
|
||||||
SessionTicketsDisabled: true,
|
SessionTicketsDisabled: true,
|
||||||
InsecureSkipVerify: true,
|
InsecureSkipVerify: true,
|
||||||
MinVersion: tls.VersionTLS12,
|
MinVersion: tls.VersionTLS12,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue