1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2012 Igalia S.L.
7 #include <libsoup/soup.h>
10 #include "test-utils.h"
12 /* From http://publicsuffix.org/list/test.txt */
17 /* NULL input. Not checked here because the API requires a valid hostname. */
19 /* Mixed case. Not checked because the API requires a valid hostname. */
20 /* { "COM", NULL }, */
21 /* { "example.COM", "example.com" }, */
22 /* { "WwW.example.COM", "example.com" }, */
26 { ".example.com", NULL },
27 { ".example.example", NULL },
28 /* Unlisted TLD. Not checked because we do not want to force every URL to have a public suffix.*/
29 /* { "example", NULL }, */
30 /* { "example.example", NULL }, */
31 /* { "b.example.example", NULL }, */
32 /* { "a.b.example.example", NULL }, */
33 /* Listed, but non-Internet, TLD. */
34 /*{ "local", NULL }, */
35 /*{ "example.local", NULL }, */
36 /*{ "b.example.local", NULL }, */
37 /*{ "a.b.example.local", NULL }, */
38 /* TLD with only 1 rule. */
40 { "domain.biz", "domain.biz" },
41 { "b.domain.biz", "domain.biz" },
42 { "a.b.domain.biz", "domain.biz" },
43 /* TLD with some 2-level rules. */
45 { "example.com", "example.com" },
46 { "b.example.com", "example.com" },
47 { "a.b.example.com", "example.com" },
49 { "example.uk.com", "example.uk.com" },
50 { "b.example.uk.com", "example.uk.com" },
51 { "a.b.example.uk.com", "example.uk.com" },
52 { "test.ac", "test.ac" },
53 /* TLD with only 1 (wildcard) rule. */
56 { "b.c.cy", "b.c.cy" },
57 { "a.b.c.cy", "b.c.cy" },
58 /* More complex TLD. */
60 { "test.jp", "test.jp" },
61 { "www.test.jp", "test.jp" },
63 { "test.ac.jp", "test.ac.jp" },
64 { "www.test.ac.jp", "test.ac.jp" },
66 { "c.kyoto.jp", NULL },
67 { "b.c.kyoto.jp", "b.c.kyoto.jp" },
68 { "a.b.c.kyoto.jp", "b.c.kyoto.jp" },
69 { "pref.kyoto.jp", "pref.kyoto.jp" }, /* Exception rule. */
70 { "www.pref.kyoto.jp", "pref.kyoto.jp" }, /* Exception rule. */
71 { "city.kyoto.jp", "city.kyoto.jp" }, /* Exception rule. */
72 { "www.city.kyoto.jp", "city.kyoto.jp" }, /* Exception rule. */
73 /* TLD with a wildcard rule and exceptions. */
76 { "b.test.om", "b.test.om" },
77 { "a.b.test.om", "b.test.om" },
78 { "songfest.om", "songfest.om" },
79 { "www.songfest.om", "songfest.om" },
82 { "test.us", "test.us" },
83 { "www.test.us", "test.us" },
85 { "test.ak.us", "test.ak.us" },
86 { "www.test.ak.us", "test.ak.us" },
87 { "k12.ak.us", NULL },
88 { "test.k12.ak.us", "test.k12.ak.us" },
89 { "www.test.k12.ak.us", "test.k12.ak.us" },
90 /* This is not in http://publicsuffix.org/list/test.txt but we want to check it anyway. */
92 /* The original list does not include non-ASCII tests. Let's add a couple. */
94 { "a.b.åfjord.no", "b.åfjord.no" }
98 main (int argc, char **argv)
102 test_init (argc, argv, NULL);
105 for (i = 0; i < G_N_ELEMENTS (tld_tests); ++i) {
106 gboolean is_public = soup_tld_domain_is_public_suffix (tld_tests[i].hostname);
107 const char *base_domain = soup_tld_get_base_domain (tld_tests[i].hostname, NULL);
109 if (tld_tests[i].result) {
110 /* Public domains have NULL expected results. */
111 if (is_public || g_strcmp0 (tld_tests[i].result, base_domain)) {
112 debug_printf (1, "ERROR: %s got %s (%s expected)\n",
113 tld_tests[i].hostname, base_domain, tld_tests[i].result);
117 /* If there is no expected result then either the domain is public or
118 * the hostname invalid (for example starts with a leading dot).
120 if (!is_public && base_domain) {
121 debug_printf (1, "ERROR: public domain %s got %s (none expected)\n",
122 tld_tests[i].hostname, base_domain);