tunnels_test.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. //go:build e2e_testing
  2. // +build e2e_testing
  3. package e2e
  4. import (
  5. "fmt"
  6. "net/netip"
  7. "testing"
  8. "time"
  9. "github.com/slackhq/nebula/cert"
  10. "github.com/slackhq/nebula/cert_test"
  11. "github.com/slackhq/nebula/e2e/router"
  12. "github.com/slackhq/nebula/header"
  13. "github.com/slackhq/nebula/udp"
  14. "github.com/stretchr/testify/assert"
  15. "gopkg.in/yaml.v3"
  16. )
  17. func TestDropInactiveTunnels(t *testing.T) {
  18. t.Parallel()
  19. // The goal of this test is to ensure the shortest inactivity timeout will close the tunnel on both sides
  20. // under ideal conditions
  21. ca, _, caKey, _ := cert_test.NewTestCaCert(cert.Version1, cert.Curve_CURVE25519, time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
  22. myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "me", "10.128.0.1/24", m{"tunnels": m{"drop_inactive": true, "inactivity_timeout": "5s"}})
  23. theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "them", "10.128.0.2/24", m{"tunnels": m{"drop_inactive": true, "inactivity_timeout": "10m"}})
  24. // Share our underlay information
  25. myControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr)
  26. theirControl.InjectLightHouseAddr(myVpnIpNet[0].Addr(), myUdpAddr)
  27. // Start the servers
  28. myControl.Start()
  29. theirControl.Start()
  30. r := router.NewR(t, myControl, theirControl)
  31. r.Log("Assert the tunnel between me and them works")
  32. assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
  33. r.Log("Go inactive and wait for the tunnels to get dropped")
  34. waitStart := time.Now()
  35. for {
  36. myIndexes := len(myControl.GetHostmap().Indexes)
  37. theirIndexes := len(theirControl.GetHostmap().Indexes)
  38. if myIndexes == 0 && theirIndexes == 0 {
  39. break
  40. }
  41. since := time.Since(waitStart)
  42. r.Logf("my tunnels: %v; their tunnels: %v; duration: %v", myIndexes, theirIndexes, since)
  43. if since > time.Second*30 {
  44. t.Fatal("Tunnel should have been declared inactive after 5 seconds and before 30 seconds")
  45. }
  46. time.Sleep(1 * time.Second)
  47. r.FlushAll()
  48. }
  49. r.Logf("Inactive tunnels were dropped within %v", time.Since(waitStart))
  50. myControl.Stop()
  51. theirControl.Stop()
  52. }
  53. func TestCertUpgrade(t *testing.T) {
  54. t.Parallel()
  55. // The goal of this test is to ensure the shortest inactivity timeout will close the tunnel on both sides
  56. // under ideal conditions
  57. ca, _, caKey, _ := cert_test.NewTestCaCert(cert.Version1, cert.Curve_CURVE25519, time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
  58. caB, err := ca.MarshalPEM()
  59. if err != nil {
  60. panic(err)
  61. }
  62. ca2, _, caKey2, _ := cert_test.NewTestCaCert(cert.Version2, cert.Curve_CURVE25519, time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
  63. ca2B, err := ca2.MarshalPEM()
  64. if err != nil {
  65. panic(err)
  66. }
  67. caStr := fmt.Sprintf("%s\n%s", caB, ca2B)
  68. myCert, _, myPrivKey, _ := cert_test.NewTestCert(cert.Version1, cert.Curve_CURVE25519, ca, caKey, "me", time.Now(), time.Now().Add(5*time.Minute), []netip.Prefix{netip.MustParsePrefix("10.128.0.1/24")}, nil, []string{})
  69. _, myCert2Pem := cert_test.NewTestCertDifferentVersion(myCert, cert.Version2, ca2, caKey2)
  70. theirCert, _, theirPrivKey, _ := cert_test.NewTestCert(cert.Version1, cert.Curve_CURVE25519, ca, caKey, "them", time.Now(), time.Now().Add(5*time.Minute), []netip.Prefix{netip.MustParsePrefix("10.128.0.2/24")}, nil, []string{})
  71. theirCert2, _ := cert_test.NewTestCertDifferentVersion(theirCert, cert.Version2, ca2, caKey2)
  72. myControl, myVpnIpNet, myUdpAddr, myC := newServer([]cert.Certificate{ca, ca2}, []cert.Certificate{myCert}, myPrivKey, m{})
  73. theirControl, theirVpnIpNet, theirUdpAddr, _ := newServer([]cert.Certificate{ca, ca2}, []cert.Certificate{theirCert, theirCert2}, theirPrivKey, m{})
  74. // Share our underlay information
  75. myControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr)
  76. theirControl.InjectLightHouseAddr(myVpnIpNet[0].Addr(), myUdpAddr)
  77. // Start the servers
  78. myControl.Start()
  79. theirControl.Start()
  80. r := router.NewR(t, myControl, theirControl)
  81. defer r.RenderFlow()
  82. r.Log("Assert the tunnel between me and them works")
  83. assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
  84. r.Log("yay")
  85. //todo ???
  86. time.Sleep(1 * time.Second)
  87. r.FlushAll()
  88. mc := m{
  89. "pki": m{
  90. "ca": caStr,
  91. "cert": string(myCert2Pem),
  92. "key": string(myPrivKey),
  93. },
  94. //"tun": m{"disabled": true},
  95. "firewall": myC.Settings["firewall"],
  96. //"handshakes": m{
  97. // "try_interval": "1s",
  98. //},
  99. "listen": myC.Settings["listen"],
  100. "logging": myC.Settings["logging"],
  101. "timers": myC.Settings["timers"],
  102. }
  103. cb, err := yaml.Marshal(mc)
  104. if err != nil {
  105. panic(err)
  106. }
  107. r.Logf("reload new v2-only config")
  108. err = myC.ReloadConfigString(string(cb))
  109. assert.NoError(t, err)
  110. r.Log("yay, spin until their sees it")
  111. waitStart := time.Now()
  112. for {
  113. assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
  114. c := theirControl.GetHostInfoByVpnAddr(myVpnIpNet[0].Addr(), false)
  115. if c == nil {
  116. r.Log("nil")
  117. } else {
  118. version := c.Cert.Version()
  119. r.Logf("version %d", version)
  120. if version == cert.Version2 {
  121. break
  122. }
  123. }
  124. since := time.Since(waitStart)
  125. if since > time.Second*10 {
  126. t.Fatal("Cert should be new by now")
  127. }
  128. time.Sleep(time.Second)
  129. }
  130. r.RenderHostmaps("Final hostmaps", myControl, theirControl)
  131. myControl.Stop()
  132. theirControl.Stop()
  133. }
  134. func TestCertDowngrade(t *testing.T) {
  135. t.Parallel()
  136. // The goal of this test is to ensure the shortest inactivity timeout will close the tunnel on both sides
  137. // under ideal conditions
  138. ca, _, caKey, _ := cert_test.NewTestCaCert(cert.Version1, cert.Curve_CURVE25519, time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
  139. caB, err := ca.MarshalPEM()
  140. if err != nil {
  141. panic(err)
  142. }
  143. ca2, _, caKey2, _ := cert_test.NewTestCaCert(cert.Version2, cert.Curve_CURVE25519, time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
  144. ca2B, err := ca2.MarshalPEM()
  145. if err != nil {
  146. panic(err)
  147. }
  148. caStr := fmt.Sprintf("%s\n%s", caB, ca2B)
  149. myCert, _, myPrivKey, myCertPem := cert_test.NewTestCert(cert.Version1, cert.Curve_CURVE25519, ca, caKey, "me", time.Now(), time.Now().Add(5*time.Minute), []netip.Prefix{netip.MustParsePrefix("10.128.0.1/24")}, nil, []string{})
  150. myCert2, _ := cert_test.NewTestCertDifferentVersion(myCert, cert.Version2, ca2, caKey2)
  151. theirCert, _, theirPrivKey, _ := cert_test.NewTestCert(cert.Version1, cert.Curve_CURVE25519, ca, caKey, "them", time.Now(), time.Now().Add(5*time.Minute), []netip.Prefix{netip.MustParsePrefix("10.128.0.2/24")}, nil, []string{})
  152. theirCert2, _ := cert_test.NewTestCertDifferentVersion(theirCert, cert.Version2, ca2, caKey2)
  153. myControl, myVpnIpNet, myUdpAddr, myC := newServer([]cert.Certificate{ca, ca2}, []cert.Certificate{myCert2}, myPrivKey, m{})
  154. theirControl, theirVpnIpNet, theirUdpAddr, _ := newServer([]cert.Certificate{ca, ca2}, []cert.Certificate{theirCert, theirCert2}, theirPrivKey, m{})
  155. // Share our underlay information
  156. myControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr)
  157. theirControl.InjectLightHouseAddr(myVpnIpNet[0].Addr(), myUdpAddr)
  158. // Start the servers
  159. myControl.Start()
  160. theirControl.Start()
  161. r := router.NewR(t, myControl, theirControl)
  162. defer r.RenderFlow()
  163. r.Log("Assert the tunnel between me and them works")
  164. //assertTunnel(t, theirVpnIpNet[0].Addr(), myVpnIpNet[0].Addr(), theirControl, myControl, r)
  165. //r.Log("yay")
  166. assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
  167. r.Log("yay")
  168. //todo ???
  169. time.Sleep(1 * time.Second)
  170. r.FlushAll()
  171. mc := m{
  172. "pki": m{
  173. "ca": caStr,
  174. "cert": string(myCertPem),
  175. "key": string(myPrivKey),
  176. },
  177. "firewall": myC.Settings["firewall"],
  178. "listen": myC.Settings["listen"],
  179. "logging": myC.Settings["logging"],
  180. "timers": myC.Settings["timers"],
  181. }
  182. cb, err := yaml.Marshal(mc)
  183. if err != nil {
  184. panic(err)
  185. }
  186. r.Logf("reload new v1-only config")
  187. err = myC.ReloadConfigString(string(cb))
  188. assert.NoError(t, err)
  189. r.Log("yay, spin until their sees it")
  190. waitStart := time.Now()
  191. for {
  192. assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
  193. c := theirControl.GetHostInfoByVpnAddr(myVpnIpNet[0].Addr(), false)
  194. c2 := myControl.GetHostInfoByVpnAddr(theirVpnIpNet[0].Addr(), false)
  195. if c == nil || c2 == nil {
  196. r.Log("nil")
  197. } else {
  198. version := c.Cert.Version()
  199. theirVersion := c2.Cert.Version()
  200. r.Logf("version %d,%d", version, theirVersion)
  201. if version == cert.Version1 {
  202. break
  203. }
  204. }
  205. since := time.Since(waitStart)
  206. if since > time.Second*5 {
  207. r.Log("it is unusual that the cert is not new yet, but not a failure yet")
  208. }
  209. if since > time.Second*10 {
  210. r.Log("wtf")
  211. t.Fatal("Cert should be new by now")
  212. }
  213. time.Sleep(time.Second)
  214. }
  215. r.RenderHostmaps("Final hostmaps", myControl, theirControl)
  216. myControl.Stop()
  217. theirControl.Stop()
  218. }
  219. func TestCertMismatchCorrection(t *testing.T) {
  220. t.Parallel()
  221. // The goal of this test is to ensure the shortest inactivity timeout will close the tunnel on both sides
  222. // under ideal conditions
  223. ca, _, caKey, _ := cert_test.NewTestCaCert(cert.Version1, cert.Curve_CURVE25519, time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
  224. ca2, _, caKey2, _ := cert_test.NewTestCaCert(cert.Version2, cert.Curve_CURVE25519, time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
  225. myCert, _, myPrivKey, _ := cert_test.NewTestCert(cert.Version1, cert.Curve_CURVE25519, ca, caKey, "me", time.Now(), time.Now().Add(5*time.Minute), []netip.Prefix{netip.MustParsePrefix("10.128.0.1/24")}, nil, []string{})
  226. myCert2, _ := cert_test.NewTestCertDifferentVersion(myCert, cert.Version2, ca2, caKey2)
  227. theirCert, _, theirPrivKey, _ := cert_test.NewTestCert(cert.Version1, cert.Curve_CURVE25519, ca, caKey, "them", time.Now(), time.Now().Add(5*time.Minute), []netip.Prefix{netip.MustParsePrefix("10.128.0.2/24")}, nil, []string{})
  228. theirCert2, _ := cert_test.NewTestCertDifferentVersion(theirCert, cert.Version2, ca2, caKey2)
  229. myControl, myVpnIpNet, myUdpAddr, _ := newServer([]cert.Certificate{ca, ca2}, []cert.Certificate{myCert2}, myPrivKey, m{})
  230. theirControl, theirVpnIpNet, theirUdpAddr, _ := newServer([]cert.Certificate{ca, ca2}, []cert.Certificate{theirCert, theirCert2}, theirPrivKey, m{})
  231. // Share our underlay information
  232. myControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr)
  233. theirControl.InjectLightHouseAddr(myVpnIpNet[0].Addr(), myUdpAddr)
  234. // Start the servers
  235. myControl.Start()
  236. theirControl.Start()
  237. r := router.NewR(t, myControl, theirControl)
  238. defer r.RenderFlow()
  239. r.Log("Assert the tunnel between me and them works")
  240. //assertTunnel(t, theirVpnIpNet[0].Addr(), myVpnIpNet[0].Addr(), theirControl, myControl, r)
  241. //r.Log("yay")
  242. assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
  243. r.Log("yay")
  244. //todo ???
  245. time.Sleep(1 * time.Second)
  246. r.FlushAll()
  247. waitStart := time.Now()
  248. for {
  249. assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
  250. c := theirControl.GetHostInfoByVpnAddr(myVpnIpNet[0].Addr(), false)
  251. c2 := myControl.GetHostInfoByVpnAddr(theirVpnIpNet[0].Addr(), false)
  252. if c == nil || c2 == nil {
  253. r.Log("nil")
  254. } else {
  255. version := c.Cert.Version()
  256. theirVersion := c2.Cert.Version()
  257. r.Logf("version %d,%d", version, theirVersion)
  258. if version == theirVersion {
  259. break
  260. }
  261. }
  262. since := time.Since(waitStart)
  263. if since > time.Second*5 {
  264. r.Log("wtf")
  265. }
  266. if since > time.Second*10 {
  267. r.Log("wtf")
  268. t.Fatal("Cert should be new by now")
  269. }
  270. time.Sleep(time.Second)
  271. }
  272. r.RenderHostmaps("Final hostmaps", myControl, theirControl)
  273. myControl.Stop()
  274. theirControl.Stop()
  275. }
  276. func TestCrossStackRelaysWork(t *testing.T) {
  277. t.Parallel()
  278. ca, _, caKey, _ := cert_test.NewTestCaCert(cert.Version2, cert.Curve_CURVE25519, time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
  279. myControl, myVpnIpNet, _, _ := newSimpleServer(cert.Version2, ca, caKey, "me ", "10.128.0.1/24,fc00::1/64", m{"relay": m{"use_relays": true}})
  280. relayControl, relayVpnIpNet, relayUdpAddr, _ := newSimpleServer(cert.Version2, ca, caKey, "relay ", "10.128.0.128/24,fc00::128/64", m{"relay": m{"am_relay": true}})
  281. theirUdp := netip.MustParseAddrPort("10.0.0.2:4242")
  282. theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServerWithUdp(cert.Version2, ca, caKey, "them ", "fc00::2/64", theirUdp, m{"relay": m{"use_relays": true}})
  283. //myVpnV4 := myVpnIpNet[0]
  284. myVpnV6 := myVpnIpNet[1]
  285. relayVpnV4 := relayVpnIpNet[0]
  286. relayVpnV6 := relayVpnIpNet[1]
  287. theirVpnV6 := theirVpnIpNet[0]
  288. // Teach my how to get to the relay and that their can be reached via the relay
  289. myControl.InjectLightHouseAddr(relayVpnV4.Addr(), relayUdpAddr)
  290. myControl.InjectLightHouseAddr(relayVpnV6.Addr(), relayUdpAddr)
  291. myControl.InjectRelays(theirVpnV6.Addr(), []netip.Addr{relayVpnV6.Addr()})
  292. relayControl.InjectLightHouseAddr(theirVpnV6.Addr(), theirUdpAddr)
  293. // Build a router so we don't have to reason who gets which packet
  294. r := router.NewR(t, myControl, relayControl, theirControl)
  295. defer r.RenderFlow()
  296. // Start the servers
  297. myControl.Start()
  298. relayControl.Start()
  299. theirControl.Start()
  300. t.Log("Trigger a handshake from me to them via the relay")
  301. myControl.InjectTunUDPPacket(theirVpnV6.Addr(), 80, myVpnV6.Addr(), 80, []byte("Hi from me"))
  302. p := r.RouteForAllUntilTxTun(theirControl)
  303. r.Log("Assert the tunnel works")
  304. assertUdpPacket(t, []byte("Hi from me"), p, myVpnV6.Addr(), theirVpnV6.Addr(), 80, 80)
  305. t.Log("reply?")
  306. theirControl.InjectTunUDPPacket(myVpnV6.Addr(), 80, theirVpnV6.Addr(), 80, []byte("Hi from them"))
  307. p = r.RouteForAllUntilTxTun(myControl)
  308. assertUdpPacket(t, []byte("Hi from them"), p, theirVpnV6.Addr(), myVpnV6.Addr(), 80, 80)
  309. r.RenderHostmaps("Final hostmaps", myControl, relayControl, theirControl)
  310. //t.Log("finish up")
  311. //myControl.Stop()
  312. //theirControl.Stop()
  313. //relayControl.Stop()
  314. }
  315. func TestCloseTunnelAuthenticated(t *testing.T) {
  316. t.Parallel()
  317. ca, _, caKey, _ := cert_test.NewTestCaCert(cert.Version1, cert.Curve_CURVE25519, time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
  318. myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "me", "10.128.0.1/24", m{"tunnels": m{"drop_inactive": true, "inactivity_timeout": "5s"}})
  319. theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "them", "10.128.0.2/24", m{"tunnels": m{"drop_inactive": true, "inactivity_timeout": "10m"}})
  320. // Share our underlay information
  321. myControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr)
  322. theirControl.InjectLightHouseAddr(myVpnIpNet[0].Addr(), myUdpAddr)
  323. // Start the servers
  324. myControl.Start()
  325. theirControl.Start()
  326. r := router.NewR(t, myControl, theirControl)
  327. r.Log("Assert the tunnel between me and them works")
  328. assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
  329. r.Log("Close the tunnel")
  330. myControl.CloseTunnel(theirVpnIpNet[0].Addr(), false)
  331. r.FlushAll()
  332. waitStart := time.Now()
  333. for {
  334. myIndexes := len(myControl.GetHostmap().Indexes)
  335. theirIndexes := len(theirControl.GetHostmap().Indexes)
  336. if myIndexes == 0 && theirIndexes == 0 {
  337. break
  338. }
  339. since := time.Since(waitStart)
  340. r.Logf("my tunnels: %v; their tunnels: %v; duration: %v", myIndexes, theirIndexes, since)
  341. if since > time.Second*6 {
  342. t.Fatal("Tunnel should have been declared inactive after 2 seconds and before 6 seconds")
  343. }
  344. time.Sleep(1 * time.Second)
  345. //r.FlushAll()
  346. }
  347. r.Logf("Happy path success, tunnels were dropped within %v", time.Since(waitStart))
  348. myControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr)
  349. theirControl.InjectLightHouseAddr(myVpnIpNet[0].Addr(), myUdpAddr)
  350. r.Log("Assert another tunnel between me and them works")
  351. assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
  352. hi := myControl.GetHostInfoByVpnAddr(theirVpnIpNet[0].Addr(), false)
  353. if hi == nil {
  354. t.Fatal("There is no hostinfo for this tunnel")
  355. }
  356. myHi := theirControl.GetHostInfoByVpnAddr(myVpnIpNet[0].Addr(), false)
  357. if myHi == nil {
  358. t.Fatal("There is no hostinfo for my tunnel")
  359. }
  360. r.Log("It does")
  361. buf := make([]byte, 1024)
  362. hdr := header.H{
  363. Version: 1,
  364. Type: header.CloseTunnel,
  365. Subtype: 0,
  366. Reserved: 0,
  367. RemoteIndex: hi.RemoteIndex,
  368. MessageCounter: 5,
  369. }
  370. out, err := hdr.Encode(buf)
  371. if err != nil {
  372. t.Fatal(err)
  373. }
  374. pkt := &udp.Packet{
  375. To: hi.CurrentRemote,
  376. From: myHi.CurrentRemote,
  377. Data: out,
  378. }
  379. r.InjectUDPPacket(myControl, theirControl, pkt)
  380. r.Log("Injected bogus close tunnel. Let's see!")
  381. waitStart = time.Now()
  382. for {
  383. myIndexes := len(myControl.GetHostmap().Indexes)
  384. theirIndexes := len(theirControl.GetHostmap().Indexes)
  385. if myIndexes == 0 {
  386. t.Fatal("myIndexes should not be 0")
  387. }
  388. if theirIndexes == 0 {
  389. t.Fatal("theirIndexes should not be 0, they should have rejected this bogus packet")
  390. }
  391. since := time.Since(waitStart)
  392. r.Logf("my tunnels: %v; their tunnels: %v; duration: %v", myIndexes, theirIndexes, since)
  393. if since > time.Second*4 {
  394. t.Log("The tunnel would have been gone by now")
  395. break
  396. }
  397. time.Sleep(1 * time.Second)
  398. r.FlushAll()
  399. }
  400. myControl.Stop()
  401. theirControl.Stop()
  402. }