From: Alberto Leiva Popper Date: Fri, 16 May 2025 23:48:43 +0000 (-0600) Subject: Grow cache unit tests more X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fecc0720a42c65b99ed38e61245e456dc5bf8dcf;p=thirdparty%2FFORT-validator.git Grow cache unit tests more --- diff --git a/src/Makefile.am b/src/Makefile.am index f6779578..12b13a76 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -95,7 +95,6 @@ fort_SOURCES += validation_handler.h validation_handler.c include asn1/asn1c/Makefile.include fort_SOURCES += $(ASN_MODULE_SRCS) $(ASN_MODULE_HDRS) -# -Werror -Wno-unused fort_CFLAGS = -Wall -Wpedantic #fort_CFLAGS += $(GCC_WARNS) fort_CFLAGS += -std=c99 -D_XOPEN_SOURCE=700 diff --git a/src/abbreviations.txt b/src/abbreviations.txt index c06e6f6c..feae720f 100644 --- a/src/abbreviations.txt +++ b/src/abbreviations.txt @@ -5,6 +5,7 @@ addr: address addr4: IPv4 address addr6: IPv6 address be: Big Endian +cer: certificate cert: certificate certstack: certificate stack ck: check (test assertion, inherited from the unit test framework) @@ -33,6 +34,7 @@ refget: reference get (+1 to reference counter) refput: reference put (-1 to reference counter) rk: Router Key rpp: Repository Publication Point (RFC 6481) +so: Signed Object str: string tmp: temporal ts: timestamp diff --git a/src/cache.c b/src/cache.c index b6c352d5..7fa67cb3 100644 --- a/src/cache.c +++ b/src/cache.c @@ -1005,27 +1005,29 @@ get_fallback(struct extension_uris *uris) } /* Do not free nor modify the result. */ -char * -cache_refresh_by_url(struct uri const *url) +validation_verdict +cache_refresh_by_url(struct uri const *url, char const **result) { struct cache_node *node = NULL; - - // XXX review result signs + validation_verdict vv; if (uri_is_https(url)) - do_refresh(&cache.https, url, &node); + vv = do_refresh(&cache.https, url, &node); else if (uri_is_rsync(url)) - do_refresh(&cache.rsync, url, &node); + vv = do_refresh(&cache.rsync, url, &node); + else + vv = VV_FAIL; - return node ? node->path : NULL; + *result = node ? node->path : NULL; + return vv; } /* * HTTPS (TAs) and rsync only; don't use this for RRDP. * Do not free nor modify the result. */ -char * -cache_get_fallback(struct uri const *url) +validation_verdict +cache_get_fallback(struct uri const *url, char const **result) { struct cache_node *node; @@ -1039,10 +1041,12 @@ cache_get_fallback(struct uri const *url) node = find_node(&cache.fallback, uri_str(url), uri_len(url)); if (!node) { pr_val_debug("Cache data unavailable."); - return NULL; + *result = NULL; + return VV_CONTINUE; } - return node->path; + *result = node->path; + return VV_CONTINUE; } /* @@ -1127,9 +1131,17 @@ cage_map_file(struct cache_cage *cage, struct uri const *url) return file; } -/* Returns true if fallback should be attempted */ +/* + * If refresh enabled, + * Switches to fallback. + * If fallback unavailable, disables the cage. + * Else, if fallback enabled, disables the cage. + * Else (if cage disabled) does nothing. + * + * Returns true if the next option should be attempted. + */ bool -cage_disable_refresh(struct cache_cage *cage) +cage_downgrade(struct cache_cage *cage) { /* * Remember: In addition to honoring the consts of cache->refresh and @@ -1137,20 +1149,13 @@ cage_disable_refresh(struct cache_cage *cage) * modified either. */ - bool enabled = (cage->refresh != NULL); - cage->refresh = NULL; - - if (cage->fallback == NULL) { - pr_val_debug("There is no fallback."); - return false; - } - if (!enabled) { - pr_val_debug("Fallback exhausted."); - return false; + if (cage->refresh) { + cage->refresh = NULL; + return cage->fallback != NULL; } - - pr_val_debug("Attempting fallback."); - return true; + if (cage->fallback) + cage->fallback = NULL; + return false; } struct mft_meta const * @@ -1186,7 +1191,7 @@ cache_commit_rpp(struct uri const *rpkiNotify, struct uri const *caRepository, } void -cache_commit_file(struct cache_mapping *map) +cache_commit_file(struct cache_mapping const *map) { struct cache_commit *commit; @@ -1194,8 +1199,7 @@ cache_commit_file(struct cache_mapping *map) memset(&commit->rpkiNotify, 0, sizeof(commit->rpkiNotify)); memset(&commit->caRepository, 0, sizeof(commit->caRepository)); commit->files = pmalloc(sizeof(*map)); - uri_copy(&commit->files[0].url, &map->url); - commit->files[0].path = pstrdup(map->path); + map_copy(commit->files, map); commit->nfiles = 1; memset(&commit->mft, 0, sizeof(commit->mft)); diff --git a/src/cache.h b/src/cache.h index eaf1092a..1e30014c 100644 --- a/src/cache.h +++ b/src/cache.h @@ -38,17 +38,17 @@ struct extension_uris { void exturis_init(struct extension_uris *); void exturis_cleanup(struct extension_uris *); -char *cache_refresh_by_url(struct uri const *); -char *cache_get_fallback(struct uri const *); +validation_verdict cache_refresh_by_url(struct uri const *, char const **); +validation_verdict cache_get_fallback(struct uri const *, char const **); struct cache_cage; validation_verdict cache_refresh_by_uris(struct extension_uris *, struct cache_cage **); char const *cage_map_file(struct cache_cage *, struct uri const *); -bool cage_disable_refresh(struct cache_cage *); +bool cage_downgrade(struct cache_cage *); struct mft_meta const *cage_mft_fallback(struct cache_cage *); void cache_commit_rpp(struct uri const *, struct uri const *, struct rpp *); -void cache_commit_file(struct cache_mapping *); +void cache_commit_file(struct cache_mapping const *); struct uri const *cage_rpkiNotify(struct cache_cage *); diff --git a/src/object/certificate.c b/src/object/certificate.c index 4eb82822..80b903f3 100644 --- a/src/object/certificate.c +++ b/src/object/certificate.c @@ -1963,7 +1963,7 @@ cer_traverse(struct rpki_certificate *ca) mft.url = ca->uris.rpkiManifest; retry: mft.path = (char *)cage_map_file(cage, &mft.url); /* Will not edit */ if (!mft.path) { - if (cage_disable_refresh(cage)) + if (cage_downgrade(cage)) goto retry; pr_val_err("caRepository '%s' is missing a manifest.", uri_str(&ca->uris.caRepository)); @@ -1972,7 +1972,7 @@ retry: mft.path = (char *)cage_map_file(cage, &mft.url); /* Will not edit */ } if (manifest_traverse(&mft, cage, ca) != 0) { - if (cage_disable_refresh(cage)) + if (cage_downgrade(cage)) goto retry; vv = VV_FAIL; goto end; diff --git a/src/object/tal.c b/src/object/tal.c index 9102bf1e..771d9345 100644 --- a/src/object/tal.c +++ b/src/object/tal.c @@ -175,24 +175,32 @@ validate_ta(struct tal *tal, struct cache_mapping const *ta_map) static validation_verdict try_urls(struct tal *tal, bool (*url_is_protocol)(struct uri const *), - char *(*get_path)(struct uri const *)) + validation_verdict (*get_path)(struct uri const *, char const **)) { struct uri *url; + char const *path; struct cache_mapping map; validation_verdict vv; ARRAYLIST_FOREACH(&tal->urls, url) { - map.url = *url; - if (!url_is_protocol(&map.url)) + if (!url_is_protocol(url)) continue; - map.path = get_path(url); - if (!map.path) + + vv = get_path(url, &path); + if (vv == VV_BUSY) + return VV_BUSY; + if (vv == VV_FAIL || !path) continue; + + map.url = *url; + map.path = (char *)path; + vv = validate_ta(tal, &map); if (vv == VV_BUSY) return VV_BUSY; if (vv == VV_FAIL) continue; + cache_commit_file(&map); return VV_CONTINUE; } diff --git a/test/Makefile.am b/test/Makefile.am index 6d50dd69..f86ae659 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -12,7 +12,7 @@ if USE_TESTS # _CFLAGS is not defined. # Otherwise it must be included manually: # mumble_mumble_CFLAGS = ${AM_CFLAGS} flag1 flag2 flag3 ... -AM_CFLAGS = -Wall -Wpedantic -Wno-unused +AM_CFLAGS = -Wall -Wpedantic # The extra info provided by this flag allows the linker to strip unused # symbols, which reduces required superfluous #includes and mocks. # It's supported by gcc and clang, not sure about others. diff --git a/test/cache_test.c b/test/cache_test.c index 6c37fefe..6908c05a 100644 --- a/test/cache_test.c +++ b/test/cache_test.c @@ -40,20 +40,13 @@ static unsigned int rsync_counter; /* Times the rsync function was called */ -static void -touch_file(char const *dir) -{ - char cmd[64]; - ck_assert(snprintf(cmd, sizeof(cmd), "touch %s/file", dir) < sizeof(cmd)); - ck_assert_int_eq(0, system(cmd)); -} - static struct uri queued_url; static char *queued_path; int rsync_queue(struct uri const *url, char const *path) { + char file[64]; rsync_counter++; if (dl_error) { @@ -62,8 +55,11 @@ rsync_queue(struct uri const *url, char const *path) } printf("Simulating rsync: %s -> %s\n", uri_str(url), path); - ck_assert_int_eq(0, mkdir(path, CACHE_FILEMODE)); - touch_file(path); + touch_dir(path); + ck_assert_int_eq(strlen(path) + 2, snprintf(file, 64, "%s/%s", path, "0")); + touch_file(file); + ck_assert_int_eq(strlen(path) + 2, snprintf(file, 64, "%s/%s", path, "1")); + touch_file(file); uri_copy(&queued_url, url); queued_path = pstrdup(path); @@ -139,14 +135,17 @@ finish_rsync(void) static struct cache_cage * rsync_dance(char *url) { + /* Queue the rsync (includes rsync simulation) */ ck_assert_ptr_eq(NULL, run_dl_rsync(url, VV_BUSY, 1)); + /* Signal rsync completion; no need to wait */ finish_rsync(); + /* Return cached results */ return run_dl_rsync(url, VV_CONTINUE, 0); } static void run_dl_https(char const *url, unsigned int expected_calls, - char const *expected_result) + validation_verdict expected_vv, char const *expected_result) { struct uri uri; char const *result; @@ -156,34 +155,49 @@ run_dl_https(char const *url, unsigned int expected_calls, rsync_counter = 0; https_counter = 0; printf("---- Downloading... ----\n"); - result = cache_refresh_by_url(&uri); + ck_assert_str_eq(expected_vv, cache_refresh_by_url(&uri, &result)); printf("---- Downloaded. ----\n"); ck_assert_uint_eq(0, rsync_counter); ck_assert_uint_eq(expected_calls, https_counter); - ck_assert_str(expected_result, result); - ck_assert_str(NULL, cache_get_fallback(&uri)); + ck_assert_pstr_eq(expected_result, result); + ck_assert_str_eq(VV_CONTINUE, cache_get_fallback(&uri, &result)); + ck_assert_ptr_eq(NULL, result); uri_cleanup(&uri); } +static void +ck_cage(struct cache_cage *cage, bool has_refresh, bool has_fallback) +{ + ck_assert_ptr_ne(NULL, cage); + if (has_refresh) + ck_assert_ptr_ne(NULL, cage->refresh); + else + ck_assert_ptr_eq(NULL, cage->refresh); + if (has_fallback) + ck_assert_ptr_ne(NULL, cage->fallback); + else + ck_assert_ptr_eq(NULL, cage->fallback); +} static void -ck_cage(struct cache_cage *cage, char const *url, - char const *refresh, char const *fallback) +ck_cage_map(struct cache_cage *cage, char const *url, + char const *opt1, char const *opt2) { struct uri uri; - struct cache_node const *bkp; + struct cache_node const *refresh, *fallback; ck_assert_ptr_eq(NULL, uri_init(&uri, url)); + refresh = cage->refresh; + fallback = cage->fallback; - ck_assert_str(refresh, cage_map_file(cage, &uri)); - - bkp = cage->refresh; - cage_disable_refresh(cage); - ck_assert_str(fallback, cage_map_file(cage, &uri)); - cage->refresh = bkp; + ck_assert_pstr_eq(opt1, cage_map_file(cage, &uri)); + ck_assert_uint_eq(!!opt2, cage_downgrade(cage)); + ck_assert_pstr_eq(opt2, cage_map_file(cage, &uri)); + cage->refresh = refresh; + cage->fallback = fallback; uri_cleanup(&uri); } @@ -401,8 +415,9 @@ static void unfreshen(struct cache_table *tbl, struct cache_node *node, void *arg) { node->state = DLS_OUTDATED; - node->attempt_ts -= 4; - node->attempt_ts -= 4; + if (node->attempt_ts) + node->attempt_ts -= 4; + node->success_ts -= 4; } static int @@ -453,17 +468,18 @@ START_TEST(test_cache_download_rsync) printf("==== Startup ====\n"); cage = rsync_dance("rsync://a.b.c/d"); ck_assert_ptr_ne(NULL, cage); - ck_cage(cage, "rsync://a.b.c/d", "rsync/0", NULL); - ck_cage(cage, "rsync://a.b.c/d/e/f.cer", "rsync/0/e/f.cer", NULL); + ck_cage(cage, true, false); + ck_cage_map(cage, "rsync://a.b.c/d", "rsync/0", NULL); + ck_cage_map(cage, "rsync://a.b.c/d/e/f.cer", "rsync/0/e/f.cer", NULL); init_node_rsync(&nodes[0], "rsync://a.b.c/d", "rsync/0", 1, VV_CONTINUE); ck_cache_rsync(nodes); free(cage); - printf("==== Redownload same file, nothing should happen ====\n"); + printf("==== Redownload same file, nothing should change ====\n"); cage = run_dl_rsync("rsync://a.b.c/d", VV_CONTINUE, 0); - ck_assert_ptr_ne(NULL, cage); - ck_cage(cage, "rsync://a.b.c/d", "rsync/0", NULL); - ck_cage(cage, "rsync://a.b.c/d/e/f.cer", "rsync/0/e/f.cer", NULL); + ck_cage(cage, true, false); + ck_cage_map(cage, "rsync://a.b.c/d", "rsync/0", NULL); + ck_cage_map(cage, "rsync://a.b.c/d/e/f.cer", "rsync/0/e/f.cer", NULL); ck_cache_rsync(nodes); free(cage); @@ -473,9 +489,9 @@ START_TEST(test_cache_download_rsync) */ printf("==== Don't redownload child ====\n"); cage = run_dl_rsync("rsync://a.b.c/d/e", VV_CONTINUE, 0); - ck_assert_ptr_ne(NULL, cage); - ck_cage(cage, "rsync://a.b.c/d", "rsync/0", NULL); - ck_cage(cage, "rsync://a.b.c/d/e/f.cer", "rsync/0/e/f.cer", NULL); + ck_cage(cage, true, false); + ck_cage_map(cage, "rsync://a.b.c/d", "rsync/0", NULL); + ck_cage_map(cage, "rsync://a.b.c/d/e/f.cer", "rsync/0/e/f.cer", NULL); ck_cache_rsync(nodes); free(cage); @@ -487,18 +503,18 @@ START_TEST(test_cache_download_rsync) */ printf("==== rsync truncated ====\n"); cage = rsync_dance("rsync://x.y.z/m/n/o"); - ck_assert_ptr_ne(NULL, cage); - ck_cage(cage, "rsync://x.y.z/m", "rsync/1", NULL); - ck_cage(cage, "rsync://x.y.z/m/n/o", "rsync/1/n/o", NULL); + ck_cage(cage, true, false); + ck_cage_map(cage, "rsync://x.y.z/m", "rsync/1", NULL); + ck_cage_map(cage, "rsync://x.y.z/m/n/o", "rsync/1/n/o", NULL); init_node_rsync(&nodes[1], "rsync://x.y.z/m", "rsync/1", 1, VV_CONTINUE); ck_cache_rsync(nodes); free(cage); printf("==== Sibling ====\n"); cage = rsync_dance("rsync://a.b.c/e/f"); - ck_assert_ptr_ne(NULL, cage); - ck_cage(cage, "rsync://a.b.c/e", "rsync/2", NULL); - ck_cage(cage, "rsync://a.b.c/e/f/x/y/z", "rsync/2/f/x/y/z", NULL); + ck_cage(cage, true, false); + ck_cage_map(cage, "rsync://a.b.c/e", "rsync/2", NULL); + ck_cage_map(cage, "rsync://a.b.c/e/f/x/y/z", "rsync/2/f/x/y/z", NULL); init_node_rsync(&nodes[2], "rsync://a.b.c/e", "rsync/2", 1, VV_CONTINUE); ck_cache_rsync(nodes); free(cage); @@ -510,15 +526,20 @@ END_TEST START_TEST(test_cache_download_rsync_error) { struct cache_node nodes[3] = { 0 }; + struct cache_cage *cage; setup_test(); + ck_assert_int_eq(0, mkdir("rsync/0", CACHE_FILEMODE)); + ck_assert_int_eq(0, file_write_txt("rsync/0/0", "A")); + ck_assert_int_eq(0, file_write_txt("rsync/0/1", "B")); + init_node_rsync(&nodes[0], "rsync://a.b.c/d", "rsync/0", 1, VV_CONTINUE); init_node_rsync(&nodes[1], "rsync://a.b.c/e", "rsync/1", 1, VV_FAIL); printf("==== Startup ====\n"); dl_error = 0; - free(rsync_dance("rsync://a.b.c/d")); + free(rsync_dance("rsync://a.b.c/d")); /* Cage already tested above */ dl_error = EINVAL; ck_assert_ptr_eq(NULL, run_dl_rsync("rsync://a.b.c/e", VV_FAIL, 1)); ck_cache_rsync(nodes); @@ -531,6 +552,25 @@ START_TEST(test_cache_download_rsync_error) ck_assert_ptr_eq(NULL, run_dl_rsync("rsync://a.b.c/e", VV_FAIL, 0)); ck_cache_rsync(nodes); + printf("==== New iteration ====\n"); + queue_commit(NULL, "rsync://a.b.c/d", "rsync/0/0", "rsync/0/1"); + cleanup_cache(); + new_iteration(false); + + printf("==== Successful download becomes failure, fallback kicks in without refresh ====\n"); + // XXX it seems cages are only being tested in rsync + dl_error = EINVAL; + cage = run_dl_rsync("rsync://a.b.c/d", VV_CONTINUE, 1); + // XXX Test combination [true, true] + ck_cage(cage, false, true); + ck_cage_map(cage, "rsync://a.b.c/d/manifest.mft", "fallback/0/0", NULL); + ck_cage_map(cage, "rsync://a.b.c/d/cert.cer", "fallback/0/1", NULL); + free(cage); + + nodes[0].verdict = VV_FAIL; + nodes[1].key.id = NULL; + ck_cache_rsync(nodes); + cleanup_test(); } END_TEST @@ -612,21 +652,21 @@ START_TEST(test_cache_download_https) setup_test(); printf("==== Download file ====\n"); - run_dl_https("https://a.b.c/d/e", 1, "https/0"); + run_dl_https("https://a.b.c/d/e", 1, VV_CONTINUE, "https/0"); init_node_https(&nodes[0], "https://a.b.c/d/e", "https/0", 1, VV_CONTINUE); ck_cache_https(nodes); printf("==== Download same file ====\n"); - run_dl_https("https://a.b.c/d/e", 0, "https/0"); + run_dl_https("https://a.b.c/d/e", 0, VV_CONTINUE, "https/0"); ck_cache_https(nodes); printf("==== Download something else 1 ====\n"); - run_dl_https("https://a.b.c/e", 1, "https/1"); + run_dl_https("https://a.b.c/e", 1, VV_CONTINUE, "https/1"); init_node_https(&nodes[1], "https://a.b.c/e", "https/1", 1, VV_CONTINUE); ck_cache_https(nodes); printf("==== Download something else 2 ====\n"); - run_dl_https("https://x.y.z/e", 1, "https/2"); + run_dl_https("https://x.y.z/e", 1, VV_CONTINUE, "https/2"); init_node_https(&nodes[2], "https://x.y.z/e", "https/2", 1, VV_CONTINUE); ck_cache_https(nodes); @@ -645,18 +685,18 @@ START_TEST(test_cache_download_https_error) printf("==== Startup ====\n"); dl_error = 0; - run_dl_https("https://a.b.c/d", 1, "https/0"); + run_dl_https("https://a.b.c/d", 1, VV_CONTINUE, "https/0"); dl_error = EINVAL; - run_dl_https("https://a.b.c/e", 1, NULL); + run_dl_https("https://a.b.c/e", 1, VV_FAIL, NULL); ck_cache_https(nodes); printf("==== Regardless of error, not reattempted because same iteration ====\n"); dl_error = EINVAL; - run_dl_https("https://a.b.c/d", 0, "https/0"); - run_dl_https("https://a.b.c/e", 0, NULL); + run_dl_https("https://a.b.c/d", 0, VV_CONTINUE, "https/0"); + run_dl_https("https://a.b.c/e", 0, VV_FAIL, NULL); dl_error = 0; - run_dl_https("https://a.b.c/d", 0, "https/0"); - run_dl_https("https://a.b.c/e", 0, NULL); + run_dl_https("https://a.b.c/d", 0, VV_CONTINUE, "https/0"); + run_dl_https("https://a.b.c/e", 0, VV_FAIL, NULL); ck_cache_https(nodes); cleanup_test(); @@ -827,7 +867,7 @@ START_TEST(test_context) ck_assert_str_eq(VV_CONTINUE, cache_refresh_by_uris(&sias, &cage)); ck_assert_str_eq(RPKI_NOTIFY, uri_str(&cage->rpkiNotify)); ck_assert_str_eq(FILE_RRDP_PATH, cage_map_file(cage, &file_url)); - ck_assert_int_eq(false, cage_disable_refresh(cage)); + ck_assert_int_eq(false, cage_downgrade(cage)); ck_assert_ptr_eq(NULL, cage_map_file(cage, &file_url)); printf("2. 2nd CA points to the same caRepository,\n"); @@ -841,7 +881,7 @@ START_TEST(test_context) ck_assert_ptr_eq(NULL, uri_str(&cage->rpkiNotify)); ck_assert_str_eq(FILE_RSYNC_PATH, cage_map_file(cage, &file_url)); - ck_assert_int_eq(false, cage_disable_refresh(cage)); + ck_assert_int_eq(false, cage_downgrade(cage)); ck_assert_ptr_eq(NULL, cage_map_file(cage, &file_url)); printf("3. Commit\n"); @@ -868,14 +908,14 @@ START_TEST(test_context) ck_assert_str_eq(VV_CONTINUE, cache_refresh_by_uris(&sias, &cage)); ck_assert_ptr_eq(NULL, uri_str(&cage->rpkiNotify)); ck_assert_str_eq(FILE_RSYNC_PATH, cage_map_file(cage, &file_url)); - ck_assert_int_eq(true, cage_disable_refresh(cage)); + ck_assert_int_eq(true, cage_downgrade(cage)); ck_assert_str_eq("fallback/1/0", cage_map_file(cage, &file_url)); ck_assert_ptr_eq(NULL, uri_init(&sias.rpkiNotify, RPKI_NOTIFY)); ck_assert_str_eq(VV_CONTINUE, cache_refresh_by_uris(&sias, &cage)); ck_assert_str_eq(RPKI_NOTIFY, uri_str(&cage->rpkiNotify)); ck_assert_str_eq(FILE_RRDP_PATH, cage_map_file(cage, &file_url)); - ck_assert_int_eq(true, cage_disable_refresh(cage)); + ck_assert_int_eq(true, cage_downgrade(cage)); ck_assert_str_eq("fallback/0/0", cage_map_file(cage, &file_url)); uri_cleanup(&sias.rpkiNotify); @@ -921,6 +961,7 @@ ck_rrdp(struct rrdp_state *expected, struct rrdp_state *actual) ck_assert_ptr_eq(NULL, acth); } +/* Converts @src into JSON forth and back. Checks the result equals @src. */ static void ck_json(struct cache_node *src) { @@ -937,7 +978,7 @@ ck_json(struct cache_node *src) ck_node_key(&src->key, &dst->key); ck_assert_str_eq(src->path, dst->path); ck_assert_int_eq(DLS_OUTDATED, dst->state); /* Must be reset */ - ck_assert_ptr_eq(NULL, dst->verdict); /* Must be reset */ + ck_assert_pstr_eq(NULL, dst->verdict); /* Must be reset */ ck_assert_int_eq(src->attempt_ts, dst->attempt_ts); ck_assert_int_eq(src->success_ts, dst->success_ts); ck_assert(INTEGER_cmp(&src->mft.num, &dst->mft.num) == 0); @@ -1032,6 +1073,7 @@ START_TEST(test_json_max) ck_json(node); } +/* "Weird URL" refers to the "`rpkiNotify\0caRepository`" indexer hack. */ START_TEST(test_json_weirdurl) { static char const *NOTIF = "https://a.b.c/notif.xml"; @@ -1063,7 +1105,8 @@ START_TEST(test_json_weirdurl) /* Boilerplate */ -static Suite *create_suite(void) +static Suite * +create_suite(void) { Suite *suite; TCase *rsync, *https, *rrdp, *multi, *json; @@ -1100,11 +1143,11 @@ static Suite *create_suite(void) return suite; } -int main(void) +int +main(void) { - Suite *suite; SRunner *runner; - int tests_failed; + int failures; dls[0] = "Fort\n"; @@ -1121,12 +1164,10 @@ int main(void) return 1; } - suite = create_suite(); - - runner = srunner_create(suite); + runner = srunner_create(create_suite()); srunner_run_all(runner, CK_NORMAL); - tests_failed = srunner_ntests_failed(runner); + failures = srunner_ntests_failed(runner); srunner_free(runner); - return (tests_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + return (failures == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/test/cache_util.c b/test/cache_util.c deleted file mode 100644 index 069ddcab..00000000 --- a/test/cache_util.c +++ /dev/null @@ -1,140 +0,0 @@ -#include "cache_util.h" - -/* XXX Might wanna delete this */ - -#include -#include -#include "types/uthash.h" - -void -ck_assert_cachent_eq(struct cache_node *expected, struct cache_node *actual) -{ - struct cache_node *echild, *achild, *tmp; - - pr_clutter("Comparing %s vs %s", expected->url, actual->url); - - ck_assert_str_eq(expected->url, actual->url); - ck_assert_str_eq(expected->path, actual->path); - ck_assert_str_eq(expected->name, actual->name); - ck_assert_int_eq(expected->flags, actual->flags); - ck_assert_str(expected->tmppath, actual->tmmpath); - - HASH_ITER(hh, expected->children, echild, tmp) { - HASH_FIND(hh, actual->children, echild->name, - strlen(echild->name), achild); - if (achild == NULL) - ck_abort_msg("Expected not found: %s", echild->url); - ck_assert_cachent_eq(echild, achild); - } - - HASH_ITER(hh, actual->children, achild, tmp) { - HASH_FIND(hh, expected->children, achild->name, - strlen(achild->name), echild); - if (echild == NULL) - ck_abort_msg("Actual not found: %s", achild->url); - } -} - -static struct cache_node * -vnode(char const *url, char const *path, int flags, char const *tmppath, - va_list children) -{ - struct cache_node *result; - struct cache_node *child; - char buffer[64]; - - result = pzalloc(sizeof(struct cache_node)); - - result->url = (char *)url; - result->path = (char *)path; - result->name = path_filename(result->path); - ck_assert_ptr_ne(NULL, result->name); - result->flags = flags; - result->tmppath = (char *)tmppath; - - while ((child = va_arg(children, struct cache_node *)) != NULL) { - HASH_ADD_KEYPTR(hh, result->children, child->name, - strlen(child->name), child); - child->parent = result; - } - - return result; -} - -struct cache_node * -rftnode(char const *url, char const *path, int flags, char const *tmppath, ...) -{ - struct cache_node *result; - va_list children; - - va_start(children, tmppath); - result = vnode(url, path, flags, tmppath, children); - va_end(children); - - return result; -} - -struct cache_node * -rfnode(char const *url, char const *path, int flags, ...) -{ - struct cache_node *result; - va_list children; - - va_start(children, flags); - result = vnode(url, path, flags, NULL, children); - va_end(children); - - return result; -} - -struct cache_node * -rnode(char const *url, char const *path, ...) -{ - struct cache_node *result; - va_list children; - - va_start(children, path); - result = vnode(url, path, 0, NULL, children); - va_end(children); - - return result; -} - -struct cache_node * -hftnode(char const *url, char const *path, int flags, char const *tmppath, ...) -{ - struct cache_node *result; - va_list children; - - va_start(children, tmppath); - result = vnode(url, path, flags, tmppath, children); - va_end(children); - - return result; -} - -struct cache_node * -hfnode(char const *url, char const *path, int flags, ...) -{ - struct cache_node *result; - va_list children; - - va_start(children, flags); - result = vnode(url, path, flags, NULL, children); - va_end(children); - - return result; -} - -struct cache_node * -hnode(char const *url, char const *path, ...) -{ - struct cache_node *result; - va_list children; - - va_start(children, path); - result = vnode(url, path, 0, NULL, children); - va_end(children); - - return result; -} diff --git a/test/cache_util.h b/test/cache_util.h deleted file mode 100644 index 1d76e0ee..00000000 --- a/test/cache_util.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef TEST_CACHE_UTIL_H_ -#define TEST_CACHE_UTIL_H_ - -#include - -void ck_assert_cachent_eq(struct cache_node *, struct cache_node *); - -struct cache_node *rftnode(char const *, char const *, int, char const *, ...); -struct cache_node *rfnode(char const *, char const *, int, ...); -struct cache_node *rnode(char const *, char const *, ...); - -struct cache_node *hftnode(char const *, char const *, int, char const *, ...); -struct cache_node *hfnode(char const *, char const *, int, ...); -struct cache_node *hnode(char const *, char const *, ...); - -/* rsync offset to url + path */ -#define RO2UP(offset) "rsync://" offset, "tmp/rsync/" offset -/* https offset to url + path */ -#define HO2UP(offset) "https://" offset, "tmp/https/" offset - -/* rsync empty to url + path */ -#define RE2UP "rsync://", "tmp/rsync" -/* https empty to url + path */ -#define HE2UP "https://", "tmp/https" - -#endif /* TEST_CACHE_UTIL_H_ */ diff --git a/test/file_test.c b/test/file_test.c index 29cc0b1e..a18a1b3b 100644 --- a/test/file_test.c +++ b/test/file_test.c @@ -4,31 +4,6 @@ #include "mock.c" -static void -touch_dir(char const *dir) -{ - ck_assert_int_eq(0, file_mkdir(dir, true)); -} - -static void -touch_file(char const *file) -{ - int fd; - int error; - - pr_op_debug("touch %s", file); - - fd = open(file, O_WRONLY | O_CREAT, CACHE_FILEMODE); - if (fd < 0) { - error = errno; - if (error == EEXIST) - return; - ck_abort_msg("open(%s): %s", file, strerror(error)); - } - - close(fd); -} - static void create_test_sandbox(void) { diff --git a/test/mock.c b/test/mock.c index 47c3c8a9..72827402 100644 --- a/test/mock.c +++ b/test/mock.c @@ -133,17 +133,33 @@ MOCK_VOID(fnstack_pop, void) MOCK_VOID(fnstack_cleanup, void) void -ck_assert_str(char const *expected, char const *actual) +ck_assert_uri(char const *expected, struct uri const *actual) { - if (expected) - ck_assert_str_eq(expected, actual); - else - ck_assert_ptr_eq(NULL, actual); + ck_assert_str_eq(expected, uri_str(actual)); + ck_assert_uint_eq(strlen(expected), uri_len(actual)); } void -ck_assert_uri(char const *expected, struct uri const *actual) +touch_dir(char const *dir) { - ck_assert_str_eq(expected, uri_str(actual)); - ck_assert_uint_eq(strlen(expected), uri_len(actual)); + ck_assert_int_eq(0, file_mkdir(dir, true)); +} + +void +touch_file(char const *file) +{ + int fd; + int error; + + pr_op_debug("touch %s", file); + + fd = open(file, O_WRONLY | O_CREAT, CACHE_FILEMODE); + if (fd < 0) { + error = errno; + if (error == EEXIST) + return; + ck_abort_msg("open(%s): %s", file, strerror(error)); + } + + close(fd); } diff --git a/test/resources/rrdp/notif-bad-uri-2.xml b/test/resources/rrdp/notif-bad-uri-2.xml deleted file mode 100644 index 7ca69b5e..00000000 --- a/test/resources/rrdp/notif-bad-uri-2.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - \ No newline at end of file diff --git a/test/rrdp_test.c b/test/rrdp_test.c index 2522c31c..47d8e736 100644 --- a/test/rrdp_test.c +++ b/test/rrdp_test.c @@ -534,17 +534,8 @@ END_TEST START_TEST(test_parse_notification_bad_uri) { - /* XXX not rejected. */ - /* test_parse_notification_error("resources/rrdp/notif-bad-uri-1.xml"); */ - /* test_parse_notification_error("resources/rrdp/notif-bad-uri-2.xml"); */ - /* - * FIXME not rejected. - * Although this might be intended. If curl and rsync can make sense out - * of the space (perhaps by automatically converting it), there would - * perhaps be no real reason to complain here. - * Needs more research. - */ - /* test_parse_notification_error("resources/rrdp/notif-bad-uri-3.xml"); */ + test_parse_notification_error("resources/rrdp/notif-bad-uri-1.xml"); + test_parse_notification_error("resources/rrdp/notif-bad-uri-3.xml"); test_parse_notification_error("resources/rrdp/notif-bad-uri-4.xml"); } END_TEST diff --git a/test/rtr/pdu_handler_test.c b/test/rtr/pdu_handler_test.c index e9cf00d2..df781958 100644 --- a/test/rtr/pdu_handler_test.c +++ b/test/rtr/pdu_handler_test.c @@ -386,19 +386,20 @@ START_TEST(test_bad_session_id) } END_TEST -static Suite *create_suite(void) +static Suite * +create_suite(void) { Suite *suite; TCase *core, *error; core = tcase_create("RFC8210-Defined Protocol Sequences"); tcase_add_test(core, test_start_or_restart); -// tcase_add_test(core, test_typical_exchange); -// tcase_add_test(core, test_no_incremental_update_available); -// tcase_add_test(core, test_cache_has_no_data_available); + tcase_add_test(core, test_typical_exchange); + tcase_add_test(core, test_no_incremental_update_available); + tcase_add_test(core, test_cache_has_no_data_available); error = tcase_create("Unhappy path cases"); -// tcase_add_test(error, test_bad_session_id); + tcase_add_test(error, test_bad_session_id); suite = suite_create("PDU Handler"); suite_add_tcase(suite, core); @@ -406,15 +407,13 @@ static Suite *create_suite(void) return suite; } -int main(void) +int +main(void) { - Suite *suite; SRunner *runner; int tests_failed; - suite = create_suite(); - - runner = srunner_create(suite); + runner = srunner_create(create_suite()); srunner_run_all(runner, CK_NORMAL); tests_failed = srunner_ntests_failed(runner); srunner_free(runner); diff --git a/test/rtr/pdu_stream_test.c b/test/rtr/pdu_stream_test.c index dd1210a4..ceff4a0c 100644 --- a/test/rtr/pdu_stream_test.c +++ b/test/rtr/pdu_stream_test.c @@ -251,7 +251,7 @@ test_read_string_success(unsigned char *input, size_t length, char *expected) stream = create_stream(input, length); actual = read_string(stream, length); - ck_assert_str(expected, actual); + ck_assert_pstr_eq(expected, actual); free(actual); free(stream); diff --git a/test/types/uri_test.c b/test/types/uri_test.c index bac7831e..43235916 100644 --- a/test/types/uri_test.c +++ b/test/types/uri_test.c @@ -104,7 +104,9 @@ START_TEST(test_3986_host) TEST_NORMALIZE("https://[FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:255.255.255.255]/", "https://[ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]/"); TEST_NORMALIZE_FAIL("https://[FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:255.255.255.2555]/", EM_HOST_LITERAL); TEST_NORMALIZE_FAIL("https://[potato]/", EM_HOST_LITERAL); - + TEST_NORMALIZE_FAIL("https://a[2001:db8::1]/", EM_HOST_BADCHR); + TEST_NORMALIZE_FAIL("https://[2001:db8::1]b/", EM_HOST_LITERAL); + TEST_NORMALIZE_FAIL("https://a[2001:db8::1]b/", EM_HOST_BADCHR); TEST_NORMALIZE_FAIL("https://[2001:db8::1][2001:db8::1]/", EM_HOST_LITERAL); } END_TEST