Add tests for PSL_TYPE_NO_STAR_RULE

This commit is contained in:
Claudio Saavedra 2018-02-21 17:58:52 +02:00
parent 9e9341f5b9
commit c198e29384
2 changed files with 81 additions and 53 deletions

View File

@ -56,38 +56,40 @@ static void test_psl(void)
*domain;
int
result;
int
no_star_result;
} test_data[] = {
{ "www.example.com", 0 },
{ "com.ar", 1 },
{ "www.com.ar", 0 },
{ "cc.ar.us", 1 },
{ ".cc.ar.us", 1 },
{ "www.example.com", 0, 0 },
{ "com.ar", 1, 1 },
{ "www.com.ar", 0, 0 },
{ "cc.ar.us", 1, 1 },
{ ".cc.ar.us", 1, 1 },
{ "www.cc.ar.us", 0 },
{ "www.ck", 0 }, /* exception from *.ck */
{ "abc.www.ck", 0 },
{ "xxx.ck", 1 },
{ "www.xxx.ck", 0 },
{ "\345\225\206\346\240\207", 1 }, /* xn--czr694b oder ?? */
{ "www.\345\225\206\346\240\207", 0 },
{ "xn--czr694b", 1 },
{ "www.xn--czr694b", 0 },
{ "www.ck", 0, 0 }, /* exception from *.ck */
{ "abc.www.ck", 0, 0 },
{ "xxx.ck", 1, 1 },
{ "www.xxx.ck", 0, 0 },
{ "\345\225\206\346\240\207", 1, 1 }, /* xn--czr694b oder ?? */
{ "www.\345\225\206\346\240\207", 0, 0 },
{ "xn--czr694b", 1, 1 },
{ "www.xn--czr694b", 0, 0 },
/* some special test follow ('name' and 'forgot.his.name' are public, but e.g. his.name is not) */
{ "name", 1 },
{ ".name", 1 },
{ "his.name", 0 },
{ ".his.name", 0 },
{ "forgot.his.name", 1 },
{ ".forgot.his.name", 1 },
{ "whoever.his.name", 0 },
{ "whoever.forgot.his.name", 0 },
{ "whatever.platform.sh", 1 },
{ ".platform.sh", 1 },
{ "whatever.yokohama.jp", 1 },
{ ".yokohama.jp", 1 },
{ ".", 1 }, /* special case */
{ "", 1 }, /* special case */
{ NULL, 1 }, /* special case */
{ "adfhoweirh", 1 }, /* unknown TLD */
{ "name", 1, 1 },
{ ".name", 1, 1 },
{ "his.name", 0, 0 },
{ ".his.name", 0, 0 },
{ "forgot.his.name", 1, 1 },
{ ".forgot.his.name", 1, 1 },
{ "whoever.his.name", 0, 0 },
{ "whoever.forgot.his.name", 0, 0 },
{ "whatever.platform.sh", 1, 1 },
{ ".platform.sh", 1, 1 },
{ "whatever.yokohama.jp", 1, 1 },
{ ".yokohama.jp", 1, 1 },
{ ".", 1, 0 }, /* special case */
{ "", 1, 0 }, /* special case */
{ NULL, 1, 1 }, /* special case */
{ "adfhoweirh", 1, 0 }, /* unknown TLD */
};
unsigned it;
const psl_ctx_t *psl;
@ -108,6 +110,18 @@ static void test_psl(void)
}
}
for (it = 0; it < countof(test_data); it++) {
const struct test_data *t = &test_data[it];
int result = psl_is_public_suffix2(psl, t->domain, PSL_TYPE_ANY|PSL_TYPE_NO_STAR_RULE);
if (result == t->no_star_result) {
ok++;
} else {
failed++;
printf("psl_is_public_suffix2(%s, NO_STAR_RULE)=%d (expected %d)\n", t->domain, result, t->no_star_result);
}
}
printf("psl_builtin_file_time()=%ld\n", psl_builtin_file_time());
psl_builtin_file_time() == 0 ? failed++ : ok++;

View File

@ -56,32 +56,34 @@ static void test_psl(void)
*domain;
int
result;
int
no_star_result;
} test_data[] = {
{ "www.example.com", 0 },
{ "com.ar", 1 },
{ "www.com.ar", 0 },
{ "cc.ar.us", 1 },
{ ".cc.ar.us", 1 },
{ "www.cc.ar.us", 0 },
{ "www.ck", 0 }, /* exception from *.ck */
{ "abc.www.ck", 0 },
{ "xxx.ck", 1 },
{ "www.xxx.ck", 0 },
{ "\345\225\206\346\240\207", 1 }, /* xn--czr694b or ?? */
{ "www.\345\225\206\346\240\207", 0 },
{ "www.example.com", 0, 0 },
{ "com.ar", 1 , 1},
{ "www.com.ar", 0, 0 },
{ "cc.ar.us", 1, 1 },
{ ".cc.ar.us", 1, 1 },
{ "www.cc.ar.us", 0, 0 },
{ "www.ck", 0, 0 }, /* exception from *.ck */
{ "abc.www.ck", 0, 0 },
{ "xxx.ck", 1, 1 },
{ "www.xxx.ck", 0, 0 },
{ "\345\225\206\346\240\207", 1, 1 }, /* xn--czr694b or ?? */
{ "www.\345\225\206\346\240\207", 0, 0 },
/* some special test follow ('name' and 'forgot.his.name' are public, but e.g. his.name is not) */
{ "name", 1 },
{ ".name", 1 },
{ "his.name", 0 },
{ ".his.name", 0 },
{ "forgot.his.name", 1 },
{ ".forgot.his.name", 1 },
{ "whoever.his.name", 0 },
{ "whoever.forgot.his.name", 0 },
{ ".", 1 }, /* special case */
{ "", 1 }, /* special case */
{ NULL, 1 }, /* special case */
{ "adfhoweirh", 1 }, /* unknown TLD */
{ "name", 1, 0 },
{ ".name", 1, 0 },
{ "his.name", 0, 0 },
{ ".his.name", 0, 0 },
{ "forgot.his.name", 1, 1 },
{ ".forgot.his.name", 1, 1 },
{ "whoever.his.name", 0, 0 },
{ "whoever.forgot.his.name", 0, 0},
{ ".", 1, 0 }, /* special case */
{ "", 1, 0 }, /* special case */
{ NULL, 1, 1 }, /* special case */
{ "adfhoweirh", 1, 0 }, /* unknown TLD */
};
unsigned it;
int result, ver;
@ -103,6 +105,18 @@ static void test_psl(void)
}
}
for (it = 0; it < countof(test_data); it++) {
const struct test_data *t = &test_data[it];
result = psl_is_public_suffix2(psl, t->domain, PSL_TYPE_ANY|PSL_TYPE_NO_STAR_RULE);
if (result == t->no_star_result) {
ok++;
} else {
failed++;
printf("psl_is_public_suffix2(%s, NO_STAR_RULE)=%d (expected %d)\n", t->domain, result, t->no_star_result);
}
}
/* do some checks to cover more code paths in libpsl */
psl_is_public_suffix(NULL, "xxx");