]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
Fixup tests for checklocks. Add auth axfr test for socket code.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 5 Feb 2018 15:33:32 +0000 (15:33 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 5 Feb 2018 15:33:32 +0000 (15:33 +0000)
git-svn-id: file:///svn/unbound/trunk@4511 be551aaa-1e26-0410-a405-d3ace91eadb9

dnscrypt/dnscrypt.c
libunbound/libunbound.c
testdata/auth_axfr.tdir/auth_axfr.conf [new file with mode: 0644]
testdata/auth_axfr.tdir/auth_axfr.dsc [new file with mode: 0644]
testdata/auth_axfr.tdir/auth_axfr.post [new file with mode: 0644]
testdata/auth_axfr.tdir/auth_axfr.pre [new file with mode: 0644]
testdata/auth_axfr.tdir/auth_axfr.test [new file with mode: 0644]
testdata/auth_axfr.tdir/auth_axfr.testns [new file with mode: 0644]

index f139ce8b22b4fe678b34195f746aa5880f523465..3545d3d9b43fa6ec9916cdefb8cfb68a3db826d6 100644 (file)
@@ -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);
 }
 
index 4be2bf64f6b4d4844420e43494a522c62d164b1d..b4cd7fa0bcc20394b3bee2afb99e9cca41365381 100644 (file)
@@ -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 (file)
index 0000000..b7f03bb
--- /dev/null
@@ -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 (file)
index 0000000..a338671
--- /dev/null
@@ -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 (file)
index 0000000..5b2f7c6
--- /dev/null
@@ -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 (file)
index 0000000..01e9cea
--- /dev/null
@@ -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 (file)
index 0000000..f9171ee
--- /dev/null
@@ -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 (file)
index 0000000..f1678a1
--- /dev/null
@@ -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