-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfqdn_test.go
executable file
·52 lines (47 loc) · 1.51 KB
/
fqdn_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package net
import "testing"
func TestIsFqdn(t *testing.T) {
var hostTests = []struct {
hostname string
expected bool
}{
{"www.company.com", true},
{"*.company.com", true},
{"company.com", false}, // -> domain
{"www.de.company.com", true},
{"www_de.company.com", true},
{"www-de.company.com", true},
{"www.de.company.com/newsticker", false}, // -> URL
{"1.2.3.4", false}, // -> IP address
{"612050612050612050612050612050612050-dot-onk89909.wn.r.appspot.com", true},
{"9876543456886756565656-secondary.z19.web.core.windows.net", true},
{"президент.рф", false}, // kremlin.ru (unicode) -> domain
{"xn--d1abbgf6aiiy.xn--p1ai", false}, // kremlin.ru (punycode) -> domain
{"www.президент.рф", true}, // www.kremlin.ru (unicode)
{"www.xn--d1abbgf6aiiy.xn--p1ai", true}, // www.kremlin.ru (punycode)
}
for _, e := range hostTests {
if IsFQDN(e.hostname) != e.expected {
t.Errorf("%s", e.hostname)
}
}
}
func TestDomainFromFqdn(t *testing.T) {
var domainFromFqdnTests = []struct {
fqdn string
domain string
}{
{"www.company.com", "company.com"},
{"a.b.core.windows.net", "windows.net"},
{"www.windows.co.uk", "windows.co.uk"},
{"a.b.windows.co.uk", "windows.co.uk"},
{"a.b.com.windows.co.uk", "windows.co.uk"},
}
for _, e := range domainFromFqdnTests {
if domain := DomainFromFqdn(e.fqdn); domain != "" {
if domain != e.domain {
t.Errorf("%s: %s ./. %s", e.fqdn, e.domain, domain)
}
}
}
}