Skip to content

Commit

Permalink
more test
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby committed Jul 31, 2024
1 parent b9f80e1 commit 5aeea09
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
6 changes: 4 additions & 2 deletions hscontrol/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down Expand Up @@ -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
Expand Down
31 changes: 29 additions & 2 deletions integration/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 5aeea09

Please sign in to comment.