From b465592c07d245c2f6c463244f5f513677e4b209 Mon Sep 17 00:00:00 2001 From: Juan Font Date: Sun, 23 Apr 2023 11:02:28 +0000 Subject: [PATCH] Do not use host networking in embedded DERP tests fixed linting --- integration/control.go | 2 ++ integration/embedded_derp_test.go | 35 +++++++++++-------------------- integration/hsic/hsic.go | 4 ++++ 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/integration/control.go b/integration/control.go index 231705f3..02d2750d 100644 --- a/integration/control.go +++ b/integration/control.go @@ -2,12 +2,14 @@ package integration import ( v1 "github.com/juanfont/headscale/gen/go/headscale/v1" + "github.com/ory/dockertest/v3" ) type ControlServer interface { Shutdown() error SaveLog(string) error Execute(command []string) (string, error) + ConnectToNetwork(network *dockertest.Network) error GetHealthEndpoint() string GetEndpoint() string WaitForReady() error diff --git a/integration/embedded_derp_test.go b/integration/embedded_derp_test.go index a166ba4b..5f831bf4 100644 --- a/integration/embedded_derp_test.go +++ b/integration/embedded_derp_test.go @@ -37,8 +37,7 @@ func TestDERPServerScenario(t *testing.T) { "user1": len(TailscaleVersions), } - headscaleConfig := hsic.DefaultConfigEnv() - headscaleConfig["HEADSCALE_LISTEN_ADDR"] = "0.0.0.0:8443" + headscaleConfig := map[string]string{} headscaleConfig["HEADSCALE_DERP_URLS"] = "" headscaleConfig["HEADSCALE_DERP_SERVER_ENABLED"] = "true" headscaleConfig["HEADSCALE_DERP_SERVER_REGION_ID"] = "999" @@ -49,14 +48,7 @@ func TestDERPServerScenario(t *testing.T) { err = scenario.CreateHeadscaleEnv( spec, hsic.WithConfigEnv(headscaleConfig), - hsic.WithPort(8443), hsic.WithTestName("derpserver"), - hsic.WithHostPortBindings( - map[string][]string{ - "8443/tcp": {"8443"}, - "3478/udp": {"3478"}, - }, - ), hsic.WithExtraPorts([]string{"3478/udp"}), hsic.WithTLS(), hsic.WithHostnameAsServerURL(), @@ -113,11 +105,6 @@ func (s *EmbeddedDERPServerScenario) CreateHeadscaleEnv( headscaleURL.Host = fmt.Sprintf("%s:%s", hsServer.GetHostname(), headscaleURL.Port()) - extraHosts := []string{ - "host.docker.internal:host-gateway", - fmt.Sprintf("%s:host-gateway", hsServer.GetHostname()), - } - err = hsServer.WaitForReady() if err != nil { return err @@ -139,7 +126,6 @@ func (s *EmbeddedDERPServerScenario) CreateHeadscaleEnv( userName, "all", clientCount, - tsic.WithExtraHosts(extraHosts), ) if err != nil { return err @@ -166,6 +152,11 @@ func (s *EmbeddedDERPServerScenario) CreateTailscaleIsolatedNodesInUser( count int, opts ...tsic.Option, ) error { + hsServer, err := s.Headscale() + if err != nil { + return err + } + if user, ok := s.users[userStr]; ok { for clientN := 0; clientN < count; clientN++ { networkName := fmt.Sprintf("tsnet-%s-%s-%d", @@ -183,24 +174,22 @@ func (s *EmbeddedDERPServerScenario) CreateTailscaleIsolatedNodesInUser( s.tsicNetworks[networkName] = network + err = hsServer.ConnectToNetwork(network) + if err != nil { + return fmt.Errorf("failed to connect headscale to %s network: %w", networkName, err) + } + version := requestedVersion if requestedVersion == "all" { version = TailscaleVersions[clientN%len(TailscaleVersions)] } - headscale, err := s.Headscale() - if err != nil { - return fmt.Errorf("failed to create tailscale node: %w", err) - } - - cert := headscale.GetCert() - hostname := headscale.GetHostname() + cert := hsServer.GetCert() user.createWaitGroup.Add(1) opts = append(opts, tsic.WithHeadscaleTLS(cert), - tsic.WithHeadscaleName(hostname), ) go func() { diff --git a/integration/hsic/hsic.go b/integration/hsic/hsic.go index 30a51c65..6517b745 100644 --- a/integration/hsic/hsic.go +++ b/integration/hsic/hsic.go @@ -295,6 +295,10 @@ func New( return hsic, nil } +func (t *HeadscaleInContainer) ConnectToNetwork(network *dockertest.Network) error { + return t.container.ConnectToNetwork(network) +} + func (t *HeadscaleInContainer) hasTLS() bool { return len(t.tlsCert) != 0 && len(t.tlsKey) != 0 }