]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/unbound/testdata/cachedb_no_store.tdir/cachedb_no_store.test
unbound: Vendor import 1.19.1
[FreeBSD/FreeBSD.git] / contrib / unbound / testdata / cachedb_no_store.tdir / cachedb_no_store.test
1 # #-- cachedb_no_store.test --#
2 # source the master var file when it's there
3 [ -f ../.tpkg.var.master ] && source ../.tpkg.var.master
4 # use .tpkg.var.test for in test variable passing
5 [ -f .tpkg.var.test ] && source .tpkg.var.test
6
7 PRE="../.."
8 . ../common.sh
9
10 # do the test
11 get_ldns_testns
12
13 # query for a text record that is stored by unbound's cache and cachedb
14 # in the testframe cache.
15 echo "> dig txt1.example.com."
16 dig @localhost -p $UNBOUND_PORT txt1.example.com. TXT | tee outfile
17 if grep "example text message" outfile; then
18         echo "OK"
19 else
20         echo "Not OK"
21         exit 1
22 fi
23
24 # stop the forwarder with servfail, to check the answer came from the cache
25 echo "> stop ldns-testns"
26 kill_pid $FWD_PID
27 echo "> start ldns-testns with servfails"
28 $LDNS_TESTNS -p $FWD_PORT cachedb_no_store.servfail.testns >fwd2.log 2>&1 &
29 FWD_PID=$!
30 echo "FWD_PID=$FWD_PID" >> .tpkg.var.test
31 wait_ldns_testns_up fwd2.log
32
33 echo "> dig txt1.example.com. from unbound cache"
34 dig @localhost -p $UNBOUND_PORT txt1.example.com. TXT | tee outfile
35 if grep "example text message" outfile; then
36         echo "OK"
37 else
38         echo "Not OK"
39         exit 1
40 fi
41
42 # clear the cache of unbound, but not cachedb testframe cache
43 echo "> unbound-control flush"
44 $PRE/unbound-control -c ub.conf flush_type txt1.example.com. TXT
45 if test $? -ne 0; then
46         echo "wrong exit value."
47         exit 1
48 else
49         echo "exit value: OK"
50 fi
51
52 echo "> dig txt1.example.com. from cachedb"
53 dig @localhost -p $UNBOUND_PORT txt1.example.com. TXT | tee outfile
54 if grep "example text message" outfile; then
55         echo "OK"
56 else
57         echo "Not OK"
58         exit 1
59 fi
60
61 # start the forwarder again.
62 echo "> stop ldns-testns"
63 kill_pid $FWD_PID
64 echo "> start ldns-testns"
65 $LDNS_TESTNS -p $FWD_PORT cachedb_no_store.testns >fwd3.log 2>&1 &
66 FWD_PID=$!
67 echo "FWD_PID=$FWD_PID" >> .tpkg.var.test
68 wait_ldns_testns_up fwd3.log
69
70 # stop unbound to flush the cachedb cache
71 echo "> stop unbound"
72 kill_pid `cat unbound.pid`
73
74 echo ""
75 echo "> config unbound with cachedb-no-store: yes"
76 echo "cachedb: cachedb-no-store: yes" >> ub.conf
77
78 # start unbound again.
79 echo "> start unbound"
80 $PRE/unbound -d -c ub.conf >unbound2.log 2>&1 &
81 UNBOUND_PID=$!
82 echo "UNBOUND_PID=$UNBOUND_PID" >> .tpkg.var.test
83 wait_unbound_up unbound2.log
84
85 echo ""
86 echo "> dig txt1.example.com."
87 dig @localhost -p $UNBOUND_PORT txt1.example.com. TXT | tee outfile
88 if grep "example text message" outfile; then
89         echo "OK"
90 else
91         echo "Not OK"
92         exit 1
93 fi
94
95 # stop the forwarder with servfail, to check the answer came from the cache
96 echo "> stop ldns-testns"
97 kill_pid $FWD_PID
98 echo "> start ldns-testns with servfails"
99 $LDNS_TESTNS -p $FWD_PORT cachedb_no_store.servfail.testns >fwd4.log 2>&1 &
100 FWD_PID=$!
101 echo "FWD_PID=$FWD_PID" >> .tpkg.var.test
102 wait_ldns_testns_up fwd4.log
103
104 echo "> dig txt1.example.com. from unbound cache"
105 dig @localhost -p $UNBOUND_PORT txt1.example.com. TXT | tee outfile
106 if grep "example text message" outfile; then
107         echo "OK"
108 else
109         echo "Not OK"
110         exit 1
111 fi
112
113 # clear the cache of unbound, but not cachedb testframe cache
114 echo "> unbound-control flush"
115 $PRE/unbound-control -c ub.conf flush_type txt1.example.com. TXT
116 if test $? -ne 0; then
117         echo "wrong exit value."
118         exit 1
119 else
120         echo "exit value: OK"
121 fi
122
123 echo "> dig txt1.example.com. from cachedb, but that has no message stored"
124 dig @localhost -p $UNBOUND_PORT txt1.example.com. TXT | tee outfile
125 if grep "SERVFAIL" outfile; then
126         echo "OK"
127 else
128         echo "Not OK"
129         exit 1
130 fi
131
132 exit 0