aboutsummaryrefslogtreecommitdiff
path: root/src/cli/namestore/test_namestore_put_multiple.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli/namestore/test_namestore_put_multiple.sh')
-rwxr-xr-xsrc/cli/namestore/test_namestore_put_multiple.sh112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/cli/namestore/test_namestore_put_multiple.sh b/src/cli/namestore/test_namestore_put_multiple.sh
new file mode 100755
index 000000000..4c7340440
--- /dev/null
+++ b/src/cli/namestore/test_namestore_put_multiple.sh
@@ -0,0 +1,112 @@
1#!/bin/bash
2
3# Check for required packages
4if ! [ -x "$(command -v gnunet-namestore)" ]; then
5 echo 'bind/named is not installed' >&2
6 exit 1
7fi
8
9# Check if gnunet is running
10gnunet-arm -I 2&>1 /dev/null
11ret=$?
12if [ 0 -ne $ret ]; then
13 echo 'gnunet services are not running'
14 exit 1
15fi
16
17## GNUNET part
18# Check if identity exists and deletes and readds it to get rid of entries in zone
19gnunet-identity -d | grep randomtestingid 2>&1 /dev/null
20ret=$?
21
22if [ 0 -ne $ret ]; then
23 gnunet-identity -D randomtestingid
24 gnunet-identity -C randomtestingid
25fi
26
27function get_record_type {
28 arr=$1
29 typ=$(echo -n "${arr[0]}" | cut -d' ' -f1)
30 echo "$typ"
31}
32
33function get_value {
34 arr=$1
35 val=$(echo -n "${arr[0]}" | cut -d' ' -f4-)
36 echo "$val"
37}
38
39function testing {
40 label=$1
41 records=$2
42 recordstring=""
43 typ=$(get_record_type "${records[@]}")
44 for i in "${records[@]}"
45 do
46 recordstring+="$i"$'\n'
47 done
48 echo "$recordstring"
49 gnunet-namestore -a -S <<EOF
50$label.randomtestingid:
51 $recordstring
52EOF
53 ret=$?
54 if [ 0 -ne $ret ]; then
55 echo "failed to add record $label: $recordstring"
56 fi
57 gnunet-gns -t "$typ" -u foo2.randomtestingid 2>&1 /dev/null
58 if [ 0 -ne $ret ]; then
59 echo "record $label could not be found"
60 fi
61}
62
63# TEST CASES
64# 1
65echo "Testing adding of single A record with -R"
66declare -a arr=('A 1200 [r] 127.0.0.1')
67testing test1 "${arr[@]}"
68# 2
69echo "Testing adding of multiple A records with -R"
70declare -a arr=('A 1200 [r] 127.0.0.1' 'A 2400 [r] 127.0.0.2')
71testing test2 "${arr[@]}"
72# 3
73echo "Testing adding of multiple different records with -R"
74declare -a arr=('A 1200 [r] 127.0.0.1' 'AAAA 2400 [r] 2002::')
75testing test3 "${arr[@]}"
76# 4
77echo "Testing adding of single GNS2DNS record with -R"
78declare -a arr=('GNS2DNS 86400 [r] gnu.org@127.0.0.1')
79testing test4 "${arr[@]}"
80# 5
81echo "Testing adding of single GNS2DNS shadow record with -R"
82declare -a arr=('GNS2DNS 86409 [rs] gnu.org@127.0.0.250')
83testing test5 "${arr[@]}"
84# 6
85echo "Testing adding of multiple GNS2DNS record with -R"
86declare -a arr=('GNS2DNS 1 [r] gnunet.org@127.0.0.1' 'GNS2DNS 3600 [s] gnunet.org@127.0.0.2')
87testing test6 "${arr[@]}"
88val=$(gnunet-gns -t GNS2DNS -u test6.randomtestingid)
89if [[ $val == *"127.0.0.1"* ]]; then
90 echo "shadow!"
91fi
92echo "Sleeping to let record expire"
93sleep 5
94val=$(gnunet-gns -t GNS2DNS -u test6.randomtestingid)
95if [[ $val == *"127.0.0.2"* ]]; then
96 echo "no shadow!"
97fi
98# 7
99echo "Testing adding MX record with -R"
100declare -a arr=('MX 3600 [r] 10,mail')
101testing test7 "${arr[@]}"
102# 8
103echo "Testing adding TXT record with -R"
104declare -a arr=('TXT 3600 [r] Pretty_Unicorns')
105testing test8 "${arr[@]}"
106# 8
107#echo "Testing adding TXT record with -R"
108#declare -a arr=('SRV 3600 [r] _autodiscover_old._tcp.bfh.ch.')
109#testing test8 "${arr[@]}"
110
111# CLEANUP
112gnunet-identity -D randomtestingid