2
0

tunnels_test.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //go:build e2e_testing
  2. // +build e2e_testing
  3. package e2e
  4. import (
  5. "testing"
  6. "time"
  7. "github.com/slackhq/nebula/cert"
  8. "github.com/slackhq/nebula/cert_test"
  9. "github.com/slackhq/nebula/e2e/router"
  10. )
  11. func TestDropInactiveTunnels(t *testing.T) {
  12. // The goal of this test is to ensure the shortest inactivity timeout will close the tunnel on both sides
  13. // under ideal conditions
  14. ca, _, caKey, _ := cert_test.NewTestCaCert(cert.Version1, cert.Curve_CURVE25519, time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
  15. myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "me", "10.128.0.1/24", m{"tunnels": m{"drop_inactive": true, "inactivity_timeout": "5s"}})
  16. theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "them", "10.128.0.2/24", m{"tunnels": m{"drop_inactive": true, "inactivity_timeout": "10m"}})
  17. // Share our underlay information
  18. myControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr)
  19. theirControl.InjectLightHouseAddr(myVpnIpNet[0].Addr(), myUdpAddr)
  20. // Start the servers
  21. myControl.Start()
  22. theirControl.Start()
  23. r := router.NewR(t, myControl, theirControl)
  24. r.Log("Assert the tunnel between me and them works")
  25. assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
  26. r.Log("Go inactive and wait for the tunnels to get dropped")
  27. waitStart := time.Now()
  28. for {
  29. myIndexes := len(myControl.GetHostmap().Indexes)
  30. theirIndexes := len(theirControl.GetHostmap().Indexes)
  31. if myIndexes == 0 && theirIndexes == 0 {
  32. break
  33. }
  34. since := time.Since(waitStart)
  35. r.Logf("my tunnels: %v; their tunnels: %v; duration: %v", myIndexes, theirIndexes, since)
  36. if since > time.Second*30 {
  37. t.Fatal("Tunnel should have been declared inactive after 5 seconds and before 30 seconds")
  38. }
  39. time.Sleep(1 * time.Second)
  40. r.FlushAll()
  41. }
  42. r.Logf("Inactive tunnels were dropped within %v", time.Since(waitStart))
  43. myControl.Stop()
  44. theirControl.Stop()
  45. }