From 4fcce70df57428dae6becd0569754505584f550f Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Mon, 30 Aug 2021 13:38:53 +0000 Subject: [PATCH] tstest/integration: listen on the specified IP By default httptest listens only on the loopback adapter. Instead, listen on the IP the user asked for. The VM test needs this, as it wants to start DERP and STUN servers on the host that can be reached by guest VMs. Signed-off-by: David Crawshaw --- tstest/integration/integration.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tstest/integration/integration.go b/tstest/integration/integration.go index 442a0d32e..d4724bb47 100644 --- a/tstest/integration/integration.go +++ b/tstest/integration/integration.go @@ -131,7 +131,13 @@ func RunDERPAndSTUN(t testing.TB, logf logger.Logf, ipAddress string) (derpMap * } d := derp.NewServer(serverPrivateKey, logf) + ln, err := net.Listen("tcp", net.JoinHostPort(ipAddress, "0")) + if err != nil { + t.Fatal(err) + } + httpsrv := httptest.NewUnstartedServer(derphttp.Handler(d)) + httpsrv.Listener = ln httpsrv.Config.ErrorLog = logger.StdLogger(logf) httpsrv.Config.TLSNextProto = make(map[string]func(*http.Server, *tls.Conn, http.Handler)) httpsrv.StartTLS() @@ -153,18 +159,21 @@ func RunDERPAndSTUN(t testing.TB, logf logger.Logf, ipAddress string) (derpMap * STUNPort: stunAddr.Port, DERPPort: httpsrv.Listener.Addr().(*net.TCPAddr).Port, InsecureForTests: true, - STUNTestIP: stunAddr.IP.String(), + STUNTestIP: ipAddress, }, }, }, }, } + t.Logf("DERP httpsrv listener: %v", httpsrv.Listener.Addr()) + t.Cleanup(func() { httpsrv.CloseClientConnections() httpsrv.Close() d.Close() stunCleanup() + ln.Close() }) return m