Files
Tobias GesellchenandClaude Opus 4.7 ab65dceb9a feat(service): validate server_url and surface resolved DNS intercept IP
Refuse to start the DNS server and reject Settings updates whose
server_url does not resolve to a routable IP. Without this, a
misconfigured hostname caused the DNS server to answer every intercepted
Bose hostname with `CNAME .`, leaving speakers unable to reach the
service while everything looked healthy. The Settings page now displays
the resolved intercept IP (or the resolve error) next to "Target
Domain", so misconfigurations are visible up front instead of buried in
the DNS log.

Refs #269

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-14 14:49:23 +02:00

69 lines
1.7 KiB
Go

package setup
import (
"testing"
)
func TestBuildServerHTTPSURL_PortResolution(t *testing.T) {
// HTTPS_PORT must be unset for the env-var path tests to be
// meaningful. t.Setenv("HTTPS_PORT", "") clears it for the duration
// of each subtest.
tests := []struct {
name string
targetURL string
envHTTPSPort string
want string
}{
{
name: "https with explicit port wins over HTTPS_PORT env",
targetURL: "https://soundtouch.fritz.box:443",
envHTTPSPort: "8443",
want: "https://soundtouch.fritz.box:443/health",
},
{
name: "https without explicit port uses 443",
targetURL: "https://soundtouch.fritz.box",
want: "https://soundtouch.fritz.box:443/health",
},
{
name: "http URL falls back to HTTPS_PORT env var",
targetURL: "http://aftertouch.local:8000",
envHTTPSPort: "9443",
want: "https://aftertouch.local:9443/health",
},
{
name: "http URL with no env var defaults to 8443",
targetURL: "http://aftertouch.local:8000",
want: "https://aftertouch.local:8443/health",
},
{
name: "invalid URL returns empty",
targetURL: "::not-a-url",
want: "",
},
{
name: "URL with no hostname returns empty",
targetURL: "http://",
want: "",
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
if tc.envHTTPSPort != "" {
t.Setenv("HTTPS_PORT", tc.envHTTPSPort)
} else {
t.Setenv("HTTPS_PORT", "")
}
m := &Manager{}
got := m.buildServerHTTPSURL(tc.targetURL)
if got != tc.want {
t.Errorf("buildServerHTTPSURL(%q) = %q, want %q", tc.targetURL, got, tc.want)
}
})
}
}