From 43c91c8161f041fd4f0ee45a7660d9344f2a509d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 1 Nov 2025 08:42:24 +0000 Subject: [PATCH] Fix Domain() to return BaseDomain instead of ServerURL hostname Co-authored-by: kradalby <98431+kradalby@users.noreply.github.com> --- hscontrol/mapper/builder_test.go | 9 +++++---- hscontrol/types/config.go | 12 ++++-------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/hscontrol/mapper/builder_test.go b/hscontrol/mapper/builder_test.go index 978b2c0e..f36a120b 100644 --- a/hscontrol/mapper/builder_test.go +++ b/hscontrol/mapper/builder_test.go @@ -57,10 +57,10 @@ func TestMapResponseBuilder_WithCapabilityVersion(t *testing.T) { } func TestMapResponseBuilder_WithDomain(t *testing.T) { - domain := "test.example.com" + baseDomain := "internal.example.com" cfg := &types.Config{ - ServerURL: "https://test.example.com", - BaseDomain: domain, + ServerURL: "https://headscale.external.com", + BaseDomain: baseDomain, } mockState := &state.State{} @@ -74,7 +74,8 @@ func TestMapResponseBuilder_WithDomain(t *testing.T) { builder := m.NewMapResponseBuilder(nodeID). WithDomain() - assert.Equal(t, domain, builder.resp.Domain) + // Domain should be the BaseDomain (internal tailnet domain), not ServerURL hostname + assert.Equal(t, baseDomain, builder.resp.Domain) assert.False(t, builder.hasErrors()) } diff --git a/hscontrol/types/config.go b/hscontrol/types/config.go index 732b4d5a..dfd069a1 100644 --- a/hscontrol/types/config.go +++ b/hscontrol/types/config.go @@ -246,15 +246,11 @@ func validatePKCEMethod(method string) error { return nil } -// Domain returns the hostname/domain part of the ServerURL. -// If the ServerURL is not a valid URL, it returns the BaseDomain. +// Domain returns the base domain for the tailnet. +// This is the domain used for MagicDNS and displayed in Tailscale clients +// as the network name. func (c *Config) Domain() string { - u, err := url.Parse(c.ServerURL) - if err != nil { - return c.BaseDomain - } - - return u.Hostname() + return c.BaseDomain } // LoadConfig prepares and loads the Headscale configuration into Viper.