diff options
Diffstat (limited to 'src/cli/namestore/test_namestore_put_multiple.sh')
-rwxr-xr-x | src/cli/namestore/test_namestore_put_multiple.sh | 112 |
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 | ||
4 | if ! [ -x "$(command -v gnunet-namestore)" ]; then | ||
5 | echo 'bind/named is not installed' >&2 | ||
6 | exit 1 | ||
7 | fi | ||
8 | |||
9 | # Check if gnunet is running | ||
10 | gnunet-arm -I 2&>1 /dev/null | ||
11 | ret=$? | ||
12 | if [ 0 -ne $ret ]; then | ||
13 | echo 'gnunet services are not running' | ||
14 | exit 1 | ||
15 | fi | ||
16 | |||
17 | ## GNUNET part | ||
18 | # Check if identity exists and deletes and readds it to get rid of entries in zone | ||
19 | gnunet-identity -d | grep randomtestingid 2>&1 /dev/null | ||
20 | ret=$? | ||
21 | |||
22 | if [ 0 -ne $ret ]; then | ||
23 | gnunet-identity -D randomtestingid | ||
24 | gnunet-identity -C randomtestingid | ||
25 | fi | ||
26 | |||
27 | function get_record_type { | ||
28 | arr=$1 | ||
29 | typ=$(echo -n "${arr[0]}" | cut -d' ' -f1) | ||
30 | echo "$typ" | ||
31 | } | ||
32 | |||
33 | function get_value { | ||
34 | arr=$1 | ||
35 | val=$(echo -n "${arr[0]}" | cut -d' ' -f4-) | ||
36 | echo "$val" | ||
37 | } | ||
38 | |||
39 | function 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 | ||
52 | EOF | ||
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 | ||
65 | echo "Testing adding of single A record with -R" | ||
66 | declare -a arr=('A 1200 [r] 127.0.0.1') | ||
67 | testing test1 "${arr[@]}" | ||
68 | # 2 | ||
69 | echo "Testing adding of multiple A records with -R" | ||
70 | declare -a arr=('A 1200 [r] 127.0.0.1' 'A 2400 [r] 127.0.0.2') | ||
71 | testing test2 "${arr[@]}" | ||
72 | # 3 | ||
73 | echo "Testing adding of multiple different records with -R" | ||
74 | declare -a arr=('A 1200 [r] 127.0.0.1' 'AAAA 2400 [r] 2002::') | ||
75 | testing test3 "${arr[@]}" | ||
76 | # 4 | ||
77 | echo "Testing adding of single GNS2DNS record with -R" | ||
78 | declare -a arr=('GNS2DNS 86400 [r] gnu.org@127.0.0.1') | ||
79 | testing test4 "${arr[@]}" | ||
80 | # 5 | ||
81 | echo "Testing adding of single GNS2DNS shadow record with -R" | ||
82 | declare -a arr=('GNS2DNS 86409 [rs] gnu.org@127.0.0.250') | ||
83 | testing test5 "${arr[@]}" | ||
84 | # 6 | ||
85 | echo "Testing adding of multiple GNS2DNS record with -R" | ||
86 | declare -a arr=('GNS2DNS 1 [r] gnunet.org@127.0.0.1' 'GNS2DNS 3600 [s] gnunet.org@127.0.0.2') | ||
87 | testing test6 "${arr[@]}" | ||
88 | val=$(gnunet-gns -t GNS2DNS -u test6.randomtestingid) | ||
89 | if [[ $val == *"127.0.0.1"* ]]; then | ||
90 | echo "shadow!" | ||
91 | fi | ||
92 | echo "Sleeping to let record expire" | ||
93 | sleep 5 | ||
94 | val=$(gnunet-gns -t GNS2DNS -u test6.randomtestingid) | ||
95 | if [[ $val == *"127.0.0.2"* ]]; then | ||
96 | echo "no shadow!" | ||
97 | fi | ||
98 | # 7 | ||
99 | echo "Testing adding MX record with -R" | ||
100 | declare -a arr=('MX 3600 [r] 10,mail') | ||
101 | testing test7 "${arr[@]}" | ||
102 | # 8 | ||
103 | echo "Testing adding TXT record with -R" | ||
104 | declare -a arr=('TXT 3600 [r] Pretty_Unicorns') | ||
105 | testing 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 | ||
112 | gnunet-identity -D randomtestingid | ||