Fix Domain() to return BaseDomain instead of ServerURL hostname

Co-authored-by: kradalby <98431+kradalby@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-11-01 08:42:24 +00:00
parent abde3ef8b3
commit 43c91c8161
2 changed files with 9 additions and 12 deletions

View File

@@ -57,10 +57,10 @@ func TestMapResponseBuilder_WithCapabilityVersion(t *testing.T) {
} }
func TestMapResponseBuilder_WithDomain(t *testing.T) { func TestMapResponseBuilder_WithDomain(t *testing.T) {
domain := "test.example.com" baseDomain := "internal.example.com"
cfg := &types.Config{ cfg := &types.Config{
ServerURL: "https://test.example.com", ServerURL: "https://headscale.external.com",
BaseDomain: domain, BaseDomain: baseDomain,
} }
mockState := &state.State{} mockState := &state.State{}
@@ -74,7 +74,8 @@ func TestMapResponseBuilder_WithDomain(t *testing.T) {
builder := m.NewMapResponseBuilder(nodeID). builder := m.NewMapResponseBuilder(nodeID).
WithDomain() 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()) assert.False(t, builder.hasErrors())
} }

View File

@@ -246,17 +246,13 @@ func validatePKCEMethod(method string) error {
return nil return nil
} }
// Domain returns the hostname/domain part of the ServerURL. // Domain returns the base domain for the tailnet.
// If the ServerURL is not a valid URL, it returns the BaseDomain. // This is the domain used for MagicDNS and displayed in Tailscale clients
// as the network name.
func (c *Config) Domain() string { func (c *Config) Domain() string {
u, err := url.Parse(c.ServerURL)
if err != nil {
return c.BaseDomain return c.BaseDomain
} }
return u.Hostname()
}
// LoadConfig prepares and loads the Headscale configuration into Viper. // LoadConfig prepares and loads the Headscale configuration into Viper.
// This means it sets the default values, reads the configuration file and // This means it sets the default values, reads the configuration file and
// environment variables, and handles deprecated configuration options. // environment variables, and handles deprecated configuration options.