more permissive hostname validation

In particular, allow hostnames without periods (like on a LAN).
This shouldn't be a client compability concern since we allow
vhosts without periods.
This commit is contained in:
Shivaram Lingamneni 2019-12-18 09:21:45 -05:00
parent 4b37b5dd3e
commit f1e2bbc0e4
3 changed files with 28 additions and 12 deletions

View file

@ -24,14 +24,18 @@ var (
"gsf.ds342.co.uk",
"324.net.uk",
"xn--bcher-kva.ch",
"pentos",
"pentos.",
"www.google.com.",
}
badHostnames = []string{
"-lol-.net.uk",
"-lol.net.uk",
"_irc._sctp.lol.net.uk",
"irc",
"com",
"irc.l%l.net.uk",
"irc..net.uk",
".",
"",
}
)
@ -56,6 +60,15 @@ func TestIsHostname(t *testing.T) {
}
}
func TestIsServerName(t *testing.T) {
if IsServerName("pentos") {
t.Error("irc server names must contain a period")
}
if !IsServerName("darwin.network") {
t.Error("failed to validate a perfectly good server name")
}
}
func TestNormalizeToNet(t *testing.T) {
a := net.ParseIP("8.8.8.8")
b := net.ParseIP("8.8.4.4")