mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-22 12:58:37 +00:00
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 <crawshaw@tailscale.com>
This commit is contained in:
parent
0b2761ca92
commit
4fcce70df5
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user