diff options
| author | Cy Schubert <cy@FreeBSD.org> | 2024-08-16 16:41:16 +0000 |
|---|---|---|
| committer | Cy Schubert <cy@FreeBSD.org> | 2024-08-16 16:41:16 +0000 |
| commit | 96ef46e5cff01648c80c09c4364d10bc6f58119d (patch) | |
| tree | a759010619ad11a8eaaaed7269bb06a9dfc2fa16 /testcode | |
| parent | c2a80056864d6eda0398fd127dc0ae515b39752b (diff) | |
Diffstat (limited to 'testcode')
| -rw-r--r-- | testcode/fake_event.c | 10 | ||||
| -rwxr-xr-x | testcode/mini_tdir.sh | 11 | ||||
| -rw-r--r-- | testcode/petal.c | 2 | ||||
| -rw-r--r-- | testcode/readzone.c | 1 | ||||
| -rw-r--r-- | testcode/streamtcp.c | 4 | ||||
| -rw-r--r-- | testcode/testbound.c | 17 | ||||
| -rw-r--r-- | testcode/unitmain.c | 106 | ||||
| -rw-r--r-- | testcode/unitverify.c | 6 | ||||
| -rw-r--r-- | testcode/unitzonemd.c | 11 |
9 files changed, 142 insertions, 26 deletions
diff --git a/testcode/fake_event.c b/testcode/fake_event.c index 09269289dd44..a517fa5f373e 100644 --- a/testcode/fake_event.c +++ b/testcode/fake_event.c @@ -1655,6 +1655,12 @@ void comm_timer_set(struct comm_timer* timer, struct timeval* tv) timeval_add(&t->tv, &t->runtime->now_tv); } +int comm_timer_is_set(struct comm_timer* timer) +{ + struct fake_timer* t = (struct fake_timer*)timer; + return t->enabled; +} + void comm_timer_delete(struct comm_timer* timer) { struct fake_timer* t = (struct fake_timer*)timer; @@ -1978,4 +1984,8 @@ void http2_stream_add_meshstate(struct http2_stream* ATTR_UNUSED(h2_stream), { } +void http2_stream_remove_mesh_state(struct http2_stream* ATTR_UNUSED(h2_stream)) +{ +} + /*********** End of Dummy routines ***********/ diff --git a/testcode/mini_tdir.sh b/testcode/mini_tdir.sh index 624ecdf7fe5b..d1f7bfce94a8 100755 --- a/testcode/mini_tdir.sh +++ b/testcode/mini_tdir.sh @@ -127,6 +127,7 @@ dir=$name.$$ result=result.$name done=.done-$name skip=.skip-$name +asan_text="SUMMARY: AddressSanitizer" success="no" if test -x "`which bash`"; then shell="bash" @@ -200,6 +201,16 @@ if test -f $name.post -a ! -f ../$skip; then echo "Warning: $name.post did not exit successfully" fi fi +# Check if there were any AddressSanitizer errors +# if compiled with -fsanitize=address +if grep "$asan_text" $result >/dev/null 2>&1; then + if test -f ../$done; then + rm ../$done + fi + echo "$name: FAILED (AddressSanitizer)" >> $result + echo "$name: FAILED (AddressSanitizer)" + success="no" +fi echo "DateRunEnd: "`date "+%s" 2>/dev/null` >> $result mv $result .. diff --git a/testcode/petal.c b/testcode/petal.c index 63d3d452ee34..6d825f1e0ca4 100644 --- a/testcode/petal.c +++ b/testcode/petal.c @@ -256,7 +256,7 @@ setup_ctx(char* key, char* cert) #if HAVE_DECL_SSL_CTX_SET_ECDH_AUTO if (!SSL_CTX_set_ecdh_auto(ctx,1)) if(verb>=1) printf("failed to set_ecdh_auto, not enabling ECDHE\n"); -#elif defined(USE_ECDSA) +#elif defined(USE_ECDSA) && defined(HAVE_SSL_CTX_SET_TMP_ECDH) if(1) { EC_KEY *ecdh = EC_KEY_new_by_curve_name (NID_X9_62_prime256v1); if (!ecdh) { diff --git a/testcode/readzone.c b/testcode/readzone.c index 94511e5771f4..f50eea31f2e8 100644 --- a/testcode/readzone.c +++ b/testcode/readzone.c @@ -45,7 +45,6 @@ #include <string.h> #include <unistd.h> -#include <stdint.h> #include "sldns/str2wire.h" #include "sldns/wire2str.h" diff --git a/testcode/streamtcp.c b/testcode/streamtcp.c index 037bcfd8b6a4..60122c4ddfd1 100644 --- a/testcode/streamtcp.c +++ b/testcode/streamtcp.c @@ -471,7 +471,11 @@ send_em(const char* svr, const char* pp2_client, int udp, int usessl, } } if(1) { +#ifdef HAVE_SSL_GET1_PEER_CERTIFICATE + X509* x = SSL_get1_peer_certificate(ssl); +#else X509* x = SSL_get_peer_certificate(ssl); +#endif if(!x) printf("SSL: no peer certificate\n"); else { X509_print_fp(stdout, x); diff --git a/testcode/testbound.c b/testcode/testbound.c index f023860e086e..123fe0d4e46f 100644 --- a/testcode/testbound.c +++ b/testcode/testbound.c @@ -72,23 +72,6 @@ int daemon_main(int argc, char* argv[]); /** config files (removed at exit) */ static struct config_strlist* cfgfiles = NULL; -#ifdef UNBOUND_ALLOC_STATS -# define strdup(s) unbound_stat_strdup_log(s, __FILE__, __LINE__, __func__) -char* unbound_stat_strdup_log(char* s, const char* file, int line, - const char* func); -char* unbound_stat_strdup_log(char* s, const char* file, int line, - const char* func) { - char* result; - size_t len; - if(!s) return NULL; - len = strlen(s); - log_info("%s:%d %s strdup(%u)", file, line, func, (unsigned)len+1); - result = unbound_stat_malloc(len+1); - memmove(result, s, len+1); - return result; -} -#endif /* UNBOUND_ALLOC_STATS */ - /** give commandline usage for testbound. */ static void testbound_usage(void) diff --git a/testcode/unitmain.c b/testcode/unitmain.c index 647cbca3b05b..084c12b93b4f 100644 --- a/testcode/unitmain.c +++ b/testcode/unitmain.c @@ -1117,7 +1117,7 @@ static void edns_ede_encode_encodedecode(struct query_info* qinfo, sldns_buffer_skip(pkt, 2 + 2); /* decode */ unit_assert(parse_edns_from_query_pkt(pkt, edns, NULL, NULL, NULL, 0, - region) == 0); + region, NULL) == 0); } static void edns_ede_encode_check(struct edns_data* edns, int* found_ede, @@ -1252,6 +1252,109 @@ static void edns_ede_answer_encode_test(void) regional_destroy(region); } +#include "services/localzone.h" +/* Utility function that compares two localzone trees */ +static void compare_localzone_trees(struct local_zones* z1, + struct local_zones* z2) +{ + struct local_zone *node1, *node2; + lock_rw_rdlock(&z1->lock); + lock_rw_rdlock(&z2->lock); + /* size should be the same */ + unit_assert(z1->ztree.count == z2->ztree.count); + for(node1=(struct local_zone*)rbtree_first(&z1->ztree), + node2=(struct local_zone*)rbtree_first(&z2->ztree); + (rbnode_type*)node1 != RBTREE_NULL && + (rbnode_type*)node2 != RBTREE_NULL; + node1=(struct local_zone*)rbtree_next((rbnode_type*)node1), + node2=(struct local_zone*)rbtree_next((rbnode_type*)node2)) { + int labs; + /* the same zone should be at the same nodes */ + unit_assert(!dname_lab_cmp( + node1->name, node1->namelabs, + node2->name, node2->namelabs, + &labs)); + /* the zone's parent should be the same on both nodes */ + unit_assert( + (node1->parent == NULL && node2->parent == NULL) || + (node1->parent != NULL && node2->parent != NULL)); + if(node1->parent) { + unit_assert(!dname_lab_cmp( + node1->parent->name, node1->parent->namelabs, + node2->parent->name, node2->parent->namelabs, + &labs)); + } + } + lock_rw_unlock(&z1->lock); + lock_rw_unlock(&z2->lock); +} + +/* test that zone addition results in the same tree from both the configuration + * file and the unbound-control commands */ +static void localzone_parents_test(void) +{ + struct local_zones *z1, *z2; + size_t i; + char* zone_data[] = { + "one", + "a.b.c.one", + "b.c.one", + "c.one", + "two", + "c.two", + "b.c.two", + "a.b.c.two", + "a.b.c.three", + "b.c.three", + "c.three", + "three", + "c.four", + "b.c.four", + "a.b.c.four", + "four", + "." + }; + unit_show_feature("localzones parent calculation"); + z1 = local_zones_create(); + z2 = local_zones_create(); + /* parse test data */ + for(i=0; i<sizeof(zone_data)/sizeof(zone_data[0]); i++) { + uint8_t* nm; + int nmlabs; + size_t nmlen; + struct local_zone* z; + + /* This is the config way */ + z = lz_enter_zone(z1, zone_data[i], "always_nxdomain", + LDNS_RR_CLASS_IN); + (void)z; /* please compiler when no threading and no lock + code; the following line disappears and z stays unused */ + lock_rw_unlock(&z->lock); + lz_init_parents(z1); + + /* This is the unbound-control way */ + nm = sldns_str2wire_dname(zone_data[i], &nmlen); + if(!nm) unit_assert(0); + nmlabs = dname_count_size_labels(nm, &nmlen); + lock_rw_wrlock(&z2->lock); + local_zones_add_zone(z2, nm, nmlen, nmlabs, LDNS_RR_CLASS_IN, + local_zone_always_nxdomain); + lock_rw_unlock(&z2->lock); + } + /* The trees should be the same, iterate and check the nodes */ + compare_localzone_trees(z1, z2); + + /* cleanup */ + local_zones_delete(z1); + local_zones_delete(z2); +} + +/** localzone unit tests */ +static void localzone_test(void) +{ + localzone_parents_test(); +} + void unit_show_func(const char* file, const char* func) { printf("test %s:%s\n", file, func); @@ -1325,6 +1428,7 @@ main(int argc, char* argv[]) tcpreuse_test(); msgparse_test(); edns_ede_answer_encode_test(); + localzone_test(); #ifdef CLIENT_SUBNET ecs_test(); #endif /* CLIENT_SUBNET */ diff --git a/testcode/unitverify.c b/testcode/unitverify.c index 395b4c257427..275435c73a0d 100644 --- a/testcode/unitverify.c +++ b/testcode/unitverify.c @@ -178,6 +178,7 @@ verifytest_rrset(struct module_env* env, struct val_env* ve, struct query_info* qinfo) { enum sec_status sec; + char reasonbuf[256]; char* reason = NULL; uint8_t sigalg[ALGO_NEEDS_MAX+1]; int verified = 0; @@ -188,8 +189,9 @@ verifytest_rrset(struct module_env* env, struct val_env* ve, } setup_sigalg(dnskey, sigalg); /* check all algorithms in the dnskey */ /* ok to give null as qstate here, won't be used for answer section. */ - sec = dnskeyset_verify_rrset(env, ve, rrset, dnskey, sigalg, &reason, NULL, - LDNS_SECTION_ANSWER, NULL, &verified); + sec = dnskeyset_verify_rrset(env, ve, rrset, dnskey, sigalg, &reason, + NULL, LDNS_SECTION_ANSWER, NULL, &verified, reasonbuf, + sizeof(reasonbuf)); if(vsig) { printf("verify outcome is: %s %s\n", sec_status_to_string(sec), reason?reason:""); diff --git a/testcode/unitzonemd.c b/testcode/unitzonemd.c index 23c9f7010644..bf130df5a25b 100644 --- a/testcode/unitzonemd.c +++ b/testcode/unitzonemd.c @@ -256,7 +256,6 @@ static void zonemd_verify_test(char* zname, char* zfile, char* tastr, struct auth_zone* z; /* setup test harness */ - memset(&mods, 0, sizeof(mods)); memset(&env, 0, sizeof(env)); env.scratch = regional_create(); if(!env.scratch) @@ -288,8 +287,10 @@ static void zonemd_verify_test(char* zname, char* zfile, char* tastr, if(!env.auth_zones) fatal_exit("out of memory"); modstack_init(&mods); - if(!modstack_setup(&mods, env.cfg->module_conf, &env)) - fatal_exit("could not modstack_setup"); + if(!modstack_call_startup(&mods, env.cfg->module_conf, &env)) + fatal_exit("could not modstack_startup"); + if(!modstack_call_init(&mods, env.cfg->module_conf, &env)) + fatal_exit("could not modstack_call_init"); env.mesh = mesh_create(&mods, &env); if(!env.mesh) fatal_exit("out of memory"); @@ -327,7 +328,9 @@ static void zonemd_verify_test(char* zname, char* zfile, char* tastr, /* desetup test harness */ mesh_delete(env.mesh); - modstack_desetup(&mods, &env); + modstack_call_deinit(&mods, &env); + modstack_call_destartup(&mods, &env); + modstack_free(&mods); auth_zones_delete(env.auth_zones); anchors_delete(env.anchors); config_delete(env.cfg); |
