9 "github.com/mjl-/mox/dns"
10 "github.com/mjl-/mox/mlog"
13func TestList(t *testing.T) {
15// ===BEGIN ICANN DOMAINS===
19// Hosts in .hokkaido.jp can't set cookies below level 4...
22// ...except hosts in pref.hokkaido.jp, which can set cookies at level 3.
27// ===END ICANN DOMAINS===
32 log := mlog.New("publicsuffix", nil)
34 l, err := ParseList(log.Logger, strings.NewReader(data))
36 t.Fatalf("parsing list: %s", err)
39 test := func(domain, orgDomain string) {
42 d, err := dns.ParseDomain(domain)
44 t.Fatalf("idna to unicode %q: %s", domain, err)
46 od, err := dns.ParseDomain(orgDomain)
48 t.Fatalf("idna to unicode org domain %q: %s", orgDomain, err)
51 r := l.Lookup(context.Background(), log.Logger, d)
53 t.Fatalf("got %q, expected %q, for domain %q", r, orgDomain, domain)
58 test("foo.com", "foo.com")
59 test("bar.foo.com", "foo.com")
60 test("foo.bar.jp", "foo.bar.jp")
61 test("baz.foo.bar.jp", "foo.bar.jp")
62 test("bar.jp", "bar.jp")
63 test("foo.bar.hokkaido.jp", "foo.bar.hokkaido.jp")
64 test("baz.foo.bar.hokkaido.jp", "foo.bar.hokkaido.jp")
65 test("bar.hokkaido.jp", "bar.hokkaido.jp")
66 test("pref.hokkaido.jp", "pref.hokkaido.jp")
67 test("foo.pref.hokkaido.jp", "pref.hokkaido.jp")
68 test("WwW.EXAMPLE.Com", "example.com")
69 test("bücher.example.com", "bücher.example.com")
70 test("foo.bücher.example.com", "foo.bücher.example.com")
71 test("bar.foo.bücher.example.com", "foo.bücher.example.com")
72 test("xn--bcher-kva.example.com", "bücher.example.com")
73 test("foo.xn--bcher-kva.example.com", "foo.bücher.example.com")
74 test("bar.foo.xn--bcher-kva.example.com", "foo.bücher.example.com")
75 test("x.ignored.example.com", "example.com")
77 l, err = ParseList(log.Logger, bytes.NewReader(publicsuffixData))
79 t.Fatalf("parsing public suffix list: %s", err)
82 // todo: add testcases from https://raw.githubusercontent.com/publicsuffix/list/master/tests/test_psl.txt