1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2012 Igalia S.L.
6 #include "test-utils.h"
8 /* From http://publicsuffix.org/list/test.txt */
14 /* NULL input. Not checked here because the API requires a valid hostname. */
15 /* { NULL, NULL, -1 }, */
16 /* Mixed case. Not checked because the API requires a valid hostname. */
17 /* { "COM", NULL, -1 }, */
18 /* { "example.COM", "example.com", -1 }, */
19 /* { "WwW.example.COM", "example.com", -1 }, */
21 { ".com", NULL, SOUP_TLD_ERROR_INVALID_HOSTNAME },
22 { ".example", NULL, SOUP_TLD_ERROR_INVALID_HOSTNAME },
23 { ".example.com", NULL, SOUP_TLD_ERROR_INVALID_HOSTNAME },
24 { ".example.example", NULL, SOUP_TLD_ERROR_INVALID_HOSTNAME },
25 /* TLD with only 1 rule. */
26 { "biz", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
27 { "domain.biz", "domain.biz", -1 },
28 { "b.domain.biz", "domain.biz", -1 },
29 { "a.b.domain.biz", "domain.biz", -1 },
30 /* TLD with some 2-level rules. */
31 { "com", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
32 { "example.com", "example.com", -1 },
33 { "b.example.com", "example.com", -1 },
34 { "a.b.example.com", "example.com", -1 },
35 { "uk.com", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
36 { "example.uk.com", "example.uk.com", -1 },
37 { "b.example.uk.com", "example.uk.com", -1 },
38 { "a.b.example.uk.com", "example.uk.com", -1 },
39 { "test.ac", "test.ac", -1 },
40 /* TLD with only 1 (wildcard) rule. */
41 { "cy", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
42 { "c.cy", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
43 { "b.c.cy", "b.c.cy", -1 },
44 { "a.b.c.cy", "b.c.cy", -1 },
45 /* More complex TLD. */
46 { "jp", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
47 { "test.jp", "test.jp", -1 },
48 { "www.test.jp", "test.jp", -1 },
49 { "ac.jp", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
50 { "test.ac.jp", "test.ac.jp", -1 },
51 { "www.test.ac.jp", "test.ac.jp", -1 },
52 { "kyoto.jp", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
53 { "minami.kyoto.jp", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
54 { "b.minami.kyoto.jp", "b.minami.kyoto.jp", -1 },
55 { "a.b.minami.kyoto.jp", "b.minami.kyoto.jp", -1 },
56 { "pref.kyoto.jp", "pref.kyoto.jp", -1 },
57 { "www.pref.kyoto.jp", "pref.kyoto.jp", -1 },
58 { "city.kyoto.jp", "city.kyoto.jp", -1 },
59 { "www.city.kyoto.jp", "city.kyoto.jp", -1 },
60 /* TLD with a wildcard rule and exceptions. */
61 { "ck", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
62 { "test.ck", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
63 { "b.test.ck", "b.test.ck", -1 },
64 { "a.b.test.ck", "b.test.ck", -1 },
65 { "www.ck", "www.ck", -1 },
66 { "www.www.ck", "www.ck", -1 },
68 { "us", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
69 { "test.us", "test.us", -1 },
70 { "www.test.us", "test.us", -1 },
71 { "ak.us", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
72 { "test.ak.us", "test.ak.us", -1 },
73 { "www.test.ak.us", "test.ak.us", -1 },
74 { "k12.ak.us", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
75 { "test.k12.ak.us", "test.k12.ak.us", -1 },
76 { "www.test.k12.ak.us", "test.k12.ak.us", -1 },
78 { "食狮.com.cn", "食狮.com.cn", -1 },
79 { "食狮.公司.cn", "食狮.公司.cn", -1 },
80 { "www.食狮.公司.cn", "食狮.公司.cn", -1 },
81 { "shishi.公司.cn", "shishi.公司.cn", -1 },
82 { "公司.cn", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
83 { "食狮.中国", "食狮.中国", -1 },
84 { "www.食狮.中国", "食狮.中国", -1 },
85 { "shishi.中国", "shishi.中国", -1 },
86 { "中国", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
87 /* Same as above, but punycoded. */
88 { "xn--85x722f.com.cn", "xn--85x722f.com.cn", -1 },
89 { "xn--85x722f.xn--55qx5d.cn", "xn--85x722f.xn--55qx5d.cn", -1 },
90 { "www.xn--85x722f.xn--55qx5d.cn", "xn--85x722f.xn--55qx5d.cn", -1 },
91 { "shishi.xn--55qx5d.cn", "shishi.xn--55qx5d.cn", -1 },
92 { "xn--55qx5d.cn", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
93 { "xn--85x722f.xn--fiqs8s", "xn--85x722f.xn--fiqs8s", -1 },
94 { "www.xn--85x722f.xn--fiqs8s", "xn--85x722f.xn--fiqs8s", -1 },
95 { "shishi.xn--fiqs8s", "shishi.xn--fiqs8s", -1 },
96 { "xn--fiqs8s", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
97 /* End of publicsuffix.org tests */
99 /* Let's just double-check this one... */
100 { "co.uk", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
101 { "test.co.uk", "test.co.uk", -1 },
102 { "www.test.co.uk", "test.co.uk", -1 },
104 /* Two levels of non-ASCII */
105 { "våler.østfold.no", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
106 { "test.våler.østfold.no", "test.våler.østfold.no", -1 },
107 { "www.test.våler.østfold.no", "test.våler.østfold.no", -1 },
108 { "xn--vler-qoa.xn--stfold-9xa.no", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
109 { "test.xn--vler-qoa.xn--stfold-9xa.no", "test.xn--vler-qoa.xn--stfold-9xa.no", -1 },
110 { "www.test.xn--vler-qoa.xn--stfold-9xa.no", "test.xn--vler-qoa.xn--stfold-9xa.no", -1 },
113 /* Non Internet TLDs have NULL as expected result
115 non_inet_tld_tests[] = {
118 { "example.example", NULL },
119 { "b.example.example", NULL },
120 { "a.b.example.example", NULL },
121 /* Listed, but non-Internet, TLD. */
123 { "example.local", NULL },
124 { "b.example.local", NULL },
125 { "a.b.example.local", NULL }
133 for (i = 0; i < G_N_ELEMENTS (tld_tests); i++) {
134 GError *error = NULL;
136 const char *base_domain;
138 debug_printf (1, "Testing %s\n", tld_tests[i].hostname);
140 is_public = soup_tld_domain_is_public_suffix (tld_tests[i].hostname);
141 base_domain = soup_tld_get_base_domain (tld_tests[i].hostname, &error);
144 g_assert_no_error (error);
145 g_assert_false (is_public);
146 g_assert_cmpstr (base_domain, ==, tld_tests[i].result);
148 g_assert_null (tld_tests[i].result);
149 g_assert_error (error, SOUP_TLD_ERROR, tld_tests[i].error);
150 g_clear_error (&error);
156 do_non_inet_tests (void)
160 g_test_bug ("679230");
161 g_test_bug ("681085");
163 for (i = 0; i < G_N_ELEMENTS (non_inet_tld_tests); i++) {
165 const char *base_domain;
167 debug_printf (1, "Testing %s\n", non_inet_tld_tests[i].hostname);
169 is_public = soup_tld_domain_is_public_suffix (non_inet_tld_tests[i].hostname);
170 base_domain = soup_tld_get_base_domain (non_inet_tld_tests[i].hostname, NULL);
172 g_assert_false (is_public);
173 g_assert_null (base_domain);
178 main (int argc, char **argv)
182 test_init (argc, argv, NULL);
184 g_test_add_func ("/tld/inet", do_inet_tests);
185 g_test_add_func ("/tld/non-inet", do_non_inet_tests);