Do not use host networking in embedded DERP tests

fixed linting
This commit is contained in:
Juan Font 2023-04-23 11:02:28 +00:00
parent 991ff25362
commit b465592c07
3 changed files with 18 additions and 23 deletions

View File

@ -2,12 +2,14 @@ package integration
import ( import (
v1 "github.com/juanfont/headscale/gen/go/headscale/v1" v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
"github.com/ory/dockertest/v3"
) )
type ControlServer interface { type ControlServer interface {
Shutdown() error Shutdown() error
SaveLog(string) error SaveLog(string) error
Execute(command []string) (string, error) Execute(command []string) (string, error)
ConnectToNetwork(network *dockertest.Network) error
GetHealthEndpoint() string GetHealthEndpoint() string
GetEndpoint() string GetEndpoint() string
WaitForReady() error WaitForReady() error

View File

@ -37,8 +37,7 @@ func TestDERPServerScenario(t *testing.T) {
"user1": len(TailscaleVersions), "user1": len(TailscaleVersions),
} }
headscaleConfig := hsic.DefaultConfigEnv() headscaleConfig := map[string]string{}
headscaleConfig["HEADSCALE_LISTEN_ADDR"] = "0.0.0.0:8443"
headscaleConfig["HEADSCALE_DERP_URLS"] = "" headscaleConfig["HEADSCALE_DERP_URLS"] = ""
headscaleConfig["HEADSCALE_DERP_SERVER_ENABLED"] = "true" headscaleConfig["HEADSCALE_DERP_SERVER_ENABLED"] = "true"
headscaleConfig["HEADSCALE_DERP_SERVER_REGION_ID"] = "999" headscaleConfig["HEADSCALE_DERP_SERVER_REGION_ID"] = "999"
@ -49,14 +48,7 @@ func TestDERPServerScenario(t *testing.T) {
err = scenario.CreateHeadscaleEnv( err = scenario.CreateHeadscaleEnv(
spec, spec,
hsic.WithConfigEnv(headscaleConfig), hsic.WithConfigEnv(headscaleConfig),
hsic.WithPort(8443),
hsic.WithTestName("derpserver"), hsic.WithTestName("derpserver"),
hsic.WithHostPortBindings(
map[string][]string{
"8443/tcp": {"8443"},
"3478/udp": {"3478"},
},
),
hsic.WithExtraPorts([]string{"3478/udp"}), hsic.WithExtraPorts([]string{"3478/udp"}),
hsic.WithTLS(), hsic.WithTLS(),
hsic.WithHostnameAsServerURL(), hsic.WithHostnameAsServerURL(),
@ -113,11 +105,6 @@ func (s *EmbeddedDERPServerScenario) CreateHeadscaleEnv(
headscaleURL.Host = fmt.Sprintf("%s:%s", hsServer.GetHostname(), headscaleURL.Port()) 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() err = hsServer.WaitForReady()
if err != nil { if err != nil {
return err return err
@ -139,7 +126,6 @@ func (s *EmbeddedDERPServerScenario) CreateHeadscaleEnv(
userName, userName,
"all", "all",
clientCount, clientCount,
tsic.WithExtraHosts(extraHosts),
) )
if err != nil { if err != nil {
return err return err
@ -166,6 +152,11 @@ func (s *EmbeddedDERPServerScenario) CreateTailscaleIsolatedNodesInUser(
count int, count int,
opts ...tsic.Option, opts ...tsic.Option,
) error { ) error {
hsServer, err := s.Headscale()
if err != nil {
return err
}
if user, ok := s.users[userStr]; ok { if user, ok := s.users[userStr]; ok {
for clientN := 0; clientN < count; clientN++ { for clientN := 0; clientN < count; clientN++ {
networkName := fmt.Sprintf("tsnet-%s-%s-%d", networkName := fmt.Sprintf("tsnet-%s-%s-%d",
@ -183,24 +174,22 @@ func (s *EmbeddedDERPServerScenario) CreateTailscaleIsolatedNodesInUser(
s.tsicNetworks[networkName] = network 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 version := requestedVersion
if requestedVersion == "all" { if requestedVersion == "all" {
version = TailscaleVersions[clientN%len(TailscaleVersions)] version = TailscaleVersions[clientN%len(TailscaleVersions)]
} }
headscale, err := s.Headscale() cert := hsServer.GetCert()
if err != nil {
return fmt.Errorf("failed to create tailscale node: %w", err)
}
cert := headscale.GetCert()
hostname := headscale.GetHostname()
user.createWaitGroup.Add(1) user.createWaitGroup.Add(1)
opts = append(opts, opts = append(opts,
tsic.WithHeadscaleTLS(cert), tsic.WithHeadscaleTLS(cert),
tsic.WithHeadscaleName(hostname),
) )
go func() { go func() {

View File

@ -295,6 +295,10 @@ func New(
return hsic, nil return hsic, nil
} }
func (t *HeadscaleInContainer) ConnectToNetwork(network *dockertest.Network) error {
return t.container.ConnectToNetwork(network)
}
func (t *HeadscaleInContainer) hasTLS() bool { func (t *HeadscaleInContainer) hasTLS() bool {
return len(t.tlsCert) != 0 && len(t.tlsKey) != 0 return len(t.tlsCert) != 0 && len(t.tlsKey) != 0
} }