From 108237798dec5b697ae42c632529d4ce0189ab82 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Tue, 5 May 2020 01:42:20 -0400 Subject: [PATCH] controlclient and ipn tests: supply --advertise-tags and --advertise-routes. This helps validate the server's behaviour when these are present. --- control/controlclient/direct_test.go | 17 +++++++++++++++++ ipn/e2e_test.go | 21 +++++++++++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/control/controlclient/direct_test.go b/control/controlclient/direct_test.go index bcae24ccf..3dd744c28 100644 --- a/control/controlclient/direct_test.go +++ b/control/controlclient/direct_test.go @@ -54,6 +54,23 @@ func TestClientsReusingKeys(t *testing.T) { hi := NewHostinfo() hi.FrontendLogID = "go-test-only" hi.BackendLogID = "go-test-only" + + // Let's test some nonempty extra hostinfo fields to make sure + // the server can handle them. + hi.RequestTags = []string{"tag:abc"} + cidr, err := wgcfg.ParseCIDR("1.2.3.4/24") + if err != nil { + t.Fatalf("ParseCIDR: %v", err) + } + hi.RoutableIPs = []wgcfg.CIDR{cidr} + hi.Services = []tailcfg.Service{ + { + Proto: tailcfg.TCP, + Port: 1234, + Description: "Description", + }, + } + c1, err := NewDirect(Options{ ServerURL: httpsrv.URL, HTTPTestClient: httpsrv.Client(), diff --git a/ipn/e2e_test.go b/ipn/e2e_test.go index f0ecafb19..f1bdcf1e9 100644 --- a/ipn/e2e_test.go +++ b/ipn/e2e_test.go @@ -19,6 +19,7 @@ import ( "time" "github.com/tailscale/wireguard-go/tun/tuntest" + "github.com/tailscale/wireguard-go/wgcfg" "tailscale.com/control/controlclient" "tailscale.com/tailcfg" "tailscale.com/tstest" @@ -39,7 +40,7 @@ func TestIPN(t *testing.T) { tstest.FixLogs(t) defer tstest.UnfixLogs(t) - // Turn off STUN for the test to make it hermitic. + // Turn off STUN for the test to make it hermetic. // TODO(crawshaw): add a test that runs against a local STUN server. magicsock.DisableSTUNForTesting = true defer func() { magicsock.DisableSTUNForTesting = false }() @@ -72,11 +73,11 @@ func TestIPN(t *testing.T) { t.Fatal(err) } - n1 := newNode(t, "n1", https) + n1 := newNode(t, "n1", https, false) defer n1.Backend.Shutdown() n1.Backend.StartLoginInteractive() - n2 := newNode(t, "n2", https) + n2 := newNode(t, "n2", https, true) defer n2.Backend.Shutdown() n2.Backend.StartLoginInteractive() @@ -188,7 +189,7 @@ type testNode struct { } // Create a new IPN node. -func newNode(t *testing.T, prefix string, https *httptest.Server) testNode { +func newNode(t *testing.T, prefix string, https *httptest.Server, weirdPrefs bool) testNode { t.Helper() logfe := func(fmt string, args ...interface{}) { t.Logf(prefix+".e: "+fmt, args...) @@ -221,6 +222,18 @@ func newNode(t *testing.T, prefix string, https *httptest.Server) testNode { prefs := NewPrefs() prefs.ControlURL = https.URL prefs.Persist = &c + + if weirdPrefs { + // Let's test some nonempty extra prefs fields to make sure + // the server can handle them. + prefs.AdvertiseTags = []string{"tag:abc"} + cidr, err := wgcfg.ParseCIDR("1.2.3.4/24") + if err != nil { + t.Fatalf("ParseCIDR: %v", err) + } + prefs.AdvertiseRoutes = []wgcfg.CIDR{cidr} + } + n.Start(Options{ FrontendLogID: prefix + "-f", Prefs: prefs,