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://192.168.1.10:4533": "http://192.168.1.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) } } }