From 5aeea09736b29216b7ad0a9737387489193de542 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Wed, 31 Jul 2024 19:00:01 +0200 Subject: [PATCH] more test Signed-off-by: Kristoffer Dalby --- hscontrol/types/config.go | 6 ++++-- integration/dns_test.go | 31 +++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/hscontrol/types/config.go b/hscontrol/types/config.go index baf66c72027..2c84896986b 100644 --- a/hscontrol/types/config.go +++ b/hscontrol/types/config.go @@ -232,7 +232,7 @@ func LoadConfig(path string, isFile bool) error { viper.SetDefault("log.format", TextLogFormat) viper.SetDefault("dns.magic_dns", true) - viper.SetDefault("dns.base_domain", "headscale.net") + viper.SetDefault("dns.base_domain", "") viper.SetDefault("dns.nameservers.global", []string{}) viper.SetDefault("dns.nameservers.split", map[string]string{}) viper.SetDefault("dns.search_domains", []string{}) @@ -625,7 +625,9 @@ func DNSToTailcfgDNS(dns DNSConfig) *tailcfg.DNSConfig { routes, domains := dns.SplitResolvers() cfg.Routes = routes - cfg.Domains = append([]string{dns.BaseDomain}, domains...) + if dns.BaseDomain != "" { + cfg.Domains = append([]string{dns.BaseDomain}, domains...) + } cfg.Domains = append(cfg.Domains, dns.SearchDomains...) return &cfg diff --git a/integration/dns_test.go b/integration/dns_test.go index dba2fdc217b..685aecd7eaa 100644 --- a/integration/dns_test.go +++ b/integration/dns_test.go @@ -102,6 +102,31 @@ func TestValidateResolvConf(t *testing.T) { wantConfCompareFunc func(*testing.T, string) }{ // New config + { + name: "no-config", + conf: map[string]string{ + "HEADSCALE_DNS_BASE_DOMAIN": "", + "HEADSCALE_DNS_MAGIC_DNS": "false", + "HEADSCALE_DNS_NAMESERVERS_GLOBAL": "", + }, + wantConfCompareFunc: func(t *testing.T, got string) { + assert.NotContains(t, got, "100.100.100.100") + }, + }, + { + name: "global-only", + conf: map[string]string{ + "HEADSCALE_DNS_BASE_DOMAIN": "", + "HEADSCALE_DNS_MAGIC_DNS": "false", + "HEADSCALE_DNS_NAMESERVERS_GLOBAL": "8.8.8.8 1.1.1.1", + }, + wantConfCompareFunc: func(t *testing.T, got string) { + want := resolvconf(` + nameserver 100.100.100.100 + `) + assert.Equal(t, want, got) + }, + }, { name: "base-integration-config", conf: map[string]string{ @@ -185,8 +210,10 @@ func TestValidateResolvConf(t *testing.T) { defer scenario.Shutdown() spec := map[string]int{ - "resolvconf1": len(MustTestVersions), - "resolvconf2": len(MustTestVersions), + // "resolvconf1": len(MustTestVersions), + // "resolvconf2": len(MustTestVersions), + "resolvconf1": 1, + "resolvconf2": 1, } err = scenario.CreateHeadscaleEnv(spec, []tsic.Option{}, hsic.WithTestName("resolvconf"), hsic.WithConfigEnv(tt.conf))