Files
minstrel/internal/netsettings/publicurl_test.go
T
bvandeusenandClaude Opus 5.5 1942cb39cf test: example addresses come from the documentation range
Sonos, UPnP and public-address tests used addresses from a real home
network. They now use 198.51.100.x (RFC 5737), keeping the last number.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 08:59:25 -05:00

35 lines
1.1 KiB
Go

package netsettings
import "testing"
func TestNormalizePublicURL(t *testing.T) {
ok := map[string]string{
"": "",
" ": "",
"https://music.example.com": "https://music.example.com",
"https://music.example.com/": "https://music.example.com",
"http://198.51.100.10:4533": "http://198.51.100.10:4533",
" https://Music.Example.com/ ": "https://Music.Example.com",
}
for in, want := range ok {
got, err := NormalizePublicURL(in)
if err != nil || got != want {
t.Errorf("NormalizePublicURL(%q) = %q, %v; want %q", in, got, err, want)
}
}
for _, in := range []string{
"music.example.com", // no scheme
"ftp://music.example.com", // wrong scheme
"https://", // no host
"https://music.example.com/app", // path
"https://music.example.com/?x=1", // query
"https://music.example.com/#frag", // fragment
"https://user:pw@music.example.com",
"javascript:alert(1)",
} {
if _, err := NormalizePublicURL(in); err == nil {
t.Errorf("NormalizePublicURL(%q) accepted, want ErrInvalidPublicURL", in)
}
}
}