From 6fc79a70a3127d96fad34a35c1d4e8fc0a45557c Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Mon, 5 Feb 2018 15:33:32 +0000 Subject: [PATCH] Fixup tests for checklocks. Add auth axfr test for socket code. git-svn-id: file:///svn/unbound/trunk@4511 be551aaa-1e26-0410-a405-d3ace91eadb9 --- dnscrypt/dnscrypt.c | 8 +++- libunbound/libunbound.c | 1 + testdata/auth_axfr.tdir/auth_axfr.conf | 18 +++++++++ testdata/auth_axfr.tdir/auth_axfr.dsc | 16 ++++++++ testdata/auth_axfr.tdir/auth_axfr.post | 10 +++++ testdata/auth_axfr.tdir/auth_axfr.pre | 31 ++++++++++++++ testdata/auth_axfr.tdir/auth_axfr.test | 51 ++++++++++++++++++++++++ testdata/auth_axfr.tdir/auth_axfr.testns | 27 +++++++++++++ 8 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 testdata/auth_axfr.tdir/auth_axfr.conf create mode 100644 testdata/auth_axfr.tdir/auth_axfr.dsc create mode 100644 testdata/auth_axfr.tdir/auth_axfr.post create mode 100644 testdata/auth_axfr.tdir/auth_axfr.pre create mode 100644 testdata/auth_axfr.tdir/auth_axfr.test create mode 100644 testdata/auth_axfr.tdir/auth_axfr.testns diff --git a/dnscrypt/dnscrypt.c b/dnscrypt/dnscrypt.c index f139ce8b2..3545d3d9b 100644 --- a/dnscrypt/dnscrypt.c +++ b/dnscrypt/dnscrypt.c @@ -980,6 +980,7 @@ dnsc_apply_cfg(struct dnsc_env *env, struct config_file *cfg) if(dnsc_load_local_data(env, cfg) <= 0) { fatal_exit("dnsc_apply_cfg: could not load local data"); } + lock_basic_lock(&env->shared_secrets_cache_lock); env->shared_secrets_cache = slabhash_create( cfg->dnscrypt_shared_secret_cache_slabs, HASH_DEFAULT_STARTARRAY, @@ -990,9 +991,11 @@ dnsc_apply_cfg(struct dnsc_env *env, struct config_file *cfg) dnsc_shared_secrets_deldatafunc, NULL ); + lock_basic_unlock(&env->shared_secrets_cache_lock); if(!env->shared_secrets_cache){ fatal_exit("dnsc_apply_cfg: could not create shared secrets cache."); } + lock_basic_lock(&env->nonces_cache_lock); env->nonces_cache = slabhash_create( cfg->dnscrypt_nonce_cache_slabs, HASH_DEFAULT_STARTARRAY, @@ -1003,6 +1006,7 @@ dnsc_apply_cfg(struct dnsc_env *env, struct config_file *cfg) dnsc_nonces_deldatafunc, NULL ); + lock_basic_unlock(&env->nonces_cache_lock); return 0; } @@ -1017,10 +1021,10 @@ dnsc_delete(struct dnsc_env *env) sodium_free(env->rotated_certs); sodium_free(env->certs); sodium_free(env->keypairs); - slabhash_delete(env->shared_secrets_cache); - slabhash_delete(env->nonces_cache); lock_basic_destroy(&env->shared_secrets_cache_lock); lock_basic_destroy(&env->nonces_cache_lock); + slabhash_delete(env->shared_secrets_cache); + slabhash_delete(env->nonces_cache); free(env); } diff --git a/libunbound/libunbound.c b/libunbound/libunbound.c index 4be2bf64f..b4cd7fa0b 100644 --- a/libunbound/libunbound.c +++ b/libunbound/libunbound.c @@ -89,6 +89,7 @@ static struct ub_ctx* ub_ctx_create_nopipe(void) WSADATA wsa_data; #endif + checklock_start(); log_init(NULL, 0, NULL); /* logs to stderr */ log_ident_set("libunbound"); #ifdef USE_WINSOCK diff --git a/testdata/auth_axfr.tdir/auth_axfr.conf b/testdata/auth_axfr.tdir/auth_axfr.conf new file mode 100644 index 000000000..b7f03bb48 --- /dev/null +++ b/testdata/auth_axfr.tdir/auth_axfr.conf @@ -0,0 +1,18 @@ +server: + verbosity: 7 + # num-threads: 1 + interface: 127.0.0.1 + port: @PORT@ + use-syslog: no + directory: "" + pidfile: "unbound.pid" + chroot: "" + username: "" + do-not-query-localhost: no + use-caps-for-id: yes +auth-zone: + name: "example.com" + for-upstream: yes + for-downstream: yes + master: "127.0.0.1@@TOPORT@" + diff --git a/testdata/auth_axfr.tdir/auth_axfr.dsc b/testdata/auth_axfr.tdir/auth_axfr.dsc new file mode 100644 index 000000000..a33867137 --- /dev/null +++ b/testdata/auth_axfr.tdir/auth_axfr.dsc @@ -0,0 +1,16 @@ +BaseName: auth_axfr +Version: 1.0 +Description: Perform AXFR for authority zone +CreationDate: Tue 13 Jun 09:35:40 CEST 2017 +Maintainer: dr. W.C.A. Wijngaards +Category: +Component: +CmdDepends: +Depends: +Help: +Pre: auth_axfr.pre +Post: auth_axfr.post +Test: auth_axfr.test +AuxFiles: +Passed: +Failure: diff --git a/testdata/auth_axfr.tdir/auth_axfr.post b/testdata/auth_axfr.tdir/auth_axfr.post new file mode 100644 index 000000000..5b2f7c620 --- /dev/null +++ b/testdata/auth_axfr.tdir/auth_axfr.post @@ -0,0 +1,10 @@ +# #-- auth_axfr.post --# +# source the master var file when it's there +[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master +# source the test var file when it's there +[ -f .tpkg.var.test ] && source .tpkg.var.test +# +# do your teardown here +. ../common.sh +kill_pid $FWD_PID +kill_pid $UNBOUND_PID diff --git a/testdata/auth_axfr.tdir/auth_axfr.pre b/testdata/auth_axfr.tdir/auth_axfr.pre new file mode 100644 index 000000000..01e9cea1a --- /dev/null +++ b/testdata/auth_axfr.tdir/auth_axfr.pre @@ -0,0 +1,31 @@ +# #-- auth_axfr.pre--# +# source the master var file when it's there +[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master +# use .tpkg.var.test for in test variable passing +[ -f .tpkg.var.test ] && source .tpkg.var.test + +. ../common.sh +get_random_port 2 +UNBOUND_PORT=$RND_PORT +FWD_PORT=$(($RND_PORT + 1)) +echo "UNBOUND_PORT=$UNBOUND_PORT" >> .tpkg.var.test +echo "FWD_PORT=$FWD_PORT" >> .tpkg.var.test + +# start forwarder +get_ldns_testns +$LDNS_TESTNS -p $FWD_PORT auth_axfr.testns >fwd.log 2>&1 & +FWD_PID=$! +echo "FWD_PID=$FWD_PID" >> .tpkg.var.test + +# make config file +sed -e 's/@PORT\@/'$UNBOUND_PORT'/' -e 's/@TOPORT\@/'$FWD_PORT'/' < auth_axfr.conf > ub.conf +# start unbound in the background +PRE="../.." +$PRE/unbound -d -c ub.conf >unbound.log 2>&1 & +UNBOUND_PID=$! +echo "UNBOUND_PID=$UNBOUND_PID" >> .tpkg.var.test + +cat .tpkg.var.test +wait_ldns_testns_up fwd.log +wait_unbound_up unbound.log + diff --git a/testdata/auth_axfr.tdir/auth_axfr.test b/testdata/auth_axfr.tdir/auth_axfr.test new file mode 100644 index 000000000..f9171eea0 --- /dev/null +++ b/testdata/auth_axfr.tdir/auth_axfr.test @@ -0,0 +1,51 @@ +# #-- auth_axfr.test --# +# source the master var file when it's there +[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master +# use .tpkg.var.test for in test variable passing +[ -f .tpkg.var.test ] && source .tpkg.var.test + +PRE="../.." +# do the test +echo "> dig www.example.com." +dig @localhost -p $UNBOUND_PORT www.example.com. | tee outfile +if grep SERVFAIL outfile; then + echo "> try again" + dig @localhost -p $UNBOUND_PORT www.example.com. | tee outfile +fi +if grep SERVFAIL outfile; then + echo "> try again" + sleep 1 + dig @localhost -p $UNBOUND_PORT www.example.com. | tee outfile +fi +if grep SERVFAIL outfile; then + echo "> try again" + sleep 1 + dig @localhost -p $UNBOUND_PORT www.example.com. | tee outfile +fi +if grep SERVFAIL outfile; then + echo "> try again" + sleep 1 + dig @localhost -p $UNBOUND_PORT www.example.com. | tee outfile +fi +if grep SERVFAIL outfile; then + echo "> try again" + sleep 10 + dig @localhost -p $UNBOUND_PORT www.example.com. | tee outfile +fi +if grep SERVFAIL outfile; then + echo "> try again" + sleep 10 + dig @localhost -p $UNBOUND_PORT www.example.com. | tee outfile +fi +echo "> cat logfiles" +cat fwd.log +cat unbound.log +echo "> check answer" +if grep "1.2.3.4" outfile; then + echo "OK" +else + echo "Not OK" + exit 1 +fi + +exit 0 diff --git a/testdata/auth_axfr.tdir/auth_axfr.testns b/testdata/auth_axfr.tdir/auth_axfr.testns new file mode 100644 index 000000000..f1678a1cc --- /dev/null +++ b/testdata/auth_axfr.tdir/auth_axfr.testns @@ -0,0 +1,27 @@ +ENTRY_BEGIN +MATCH opcode qtype qname +ADJUST copy_id +REPLY QR AA NOERROR +SECTION QUESTION +example.com. IN SOA +SECTION ANSWER +example.com. IN SOA ns.example.com. hostmaster.example.com. 1 3600 900 86400 3600 +ENTRY_END + +ENTRY_BEGIN +MATCH opcode qtype qname +ADJUST copy_id +REPLY QR AA NOERROR +SECTION QUESTION +example.com. IN AXFR +SECTION ANSWER +example.com. IN SOA ns.example.com. hostmaster.example.com. 1 3600 900 86400 3600 +example.com. IN NS ns.example.net. +EXTRA_PACKET +REPLY QR AA NOERROR +SECTION QUESTION +example.com. IN AXFR +SECTION ANSWER +www.example.com. IN A 1.2.3.4 +example.com. IN SOA ns.example.com. hostmaster.example.com. 1 3600 900 86400 3600 +ENTRY_END -- 2.47.3