From c198e29384581df207ae13d2a9b275e3043dea29 Mon Sep 17 00:00:00 2001 From: Claudio Saavedra Date: Wed, 21 Feb 2018 17:58:52 +0200 Subject: [PATCH] Add tests for PSL_TYPE_NO_STAR_RULE --- tests/test-is-public-builtin.c | 72 ++++++++++++++++++++-------------- tests/test-is-public.c | 62 +++++++++++++++++------------ 2 files changed, 81 insertions(+), 53 deletions(-) diff --git a/tests/test-is-public-builtin.c b/tests/test-is-public-builtin.c index df1cb84..2b8000e 100644 --- a/tests/test-is-public-builtin.c +++ b/tests/test-is-public-builtin.c @@ -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++; diff --git a/tests/test-is-public.c b/tests/test-is-public.c index f48088b..9f29ebd 100644 --- a/tests/test-is-public.c +++ b/tests/test-is-public.c @@ -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");