Skip to content

Commit

Permalink
Do not use host networking in embedded DERP tests
Browse files Browse the repository at this point in the history
fixed linting
  • Loading branch information
juanfont committed Apr 24, 2023
1 parent 991ff25 commit b465592
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
2 changes: 2 additions & 0 deletions integration/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 12 additions & 23 deletions integration/embedded_derp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(),
Expand Down Expand Up @@ -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
Expand All @@ -139,7 +126,6 @@ func (s *EmbeddedDERPServerScenario) CreateHeadscaleEnv(
userName,
"all",
clientCount,
tsic.WithExtraHosts(extraHosts),
)
if err != nil {
return err
Expand All @@ -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",
Expand All @@ -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() {
Expand Down
4 changes: 4 additions & 0 deletions integration/hsic/hsic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit b465592

Please sign in to comment.