diff options
author | rexxnor <rexxnor+gnunet@brief.li> | 2018-11-13 14:22:01 +0100 |
---|---|---|
committer | rexxnor <rexxnor+gnunet@brief.li> | 2018-11-13 14:28:08 +0100 |
commit | c84054626c6cc460bad4b6562ee89c221be308aa (patch) | |
tree | 26a517d45e587f8d1ea75b906d3ef363ff12dc41 /src/namestore | |
parent | 9d1e77b9331acb9bd8b6c99aa942f62b9759e650 (diff) | |
download | gnunet-c84054626c6cc460bad4b6562ee89c221be308aa.tar.gz gnunet-c84054626c6cc460bad4b6562ee89c221be308aa.zip |
added -R tests for multiple arguments
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/test_namestore_put_multiple.sh | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/src/namestore/test_namestore_put_multiple.sh b/src/namestore/test_namestore_put_multiple.sh new file mode 100644 index 000000000..48ad95a3c --- /dev/null +++ b/src/namestore/test_namestore_put_multiple.sh | |||
@@ -0,0 +1,124 @@ | |||
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 delets 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 minimize_ttl { | ||
28 | ttl=10000000 | ||
29 | arr=$1 | ||
30 | # parse each element and update ttl to smallest one | ||
31 | for i in "${arr[@]}" | ||
32 | do | ||
33 | currttl=$(echo -n "$i" | cut -d' ' -f1) | ||
34 | if [ "$currttl" -lt "$ttl" ] | ||
35 | then | ||
36 | ttl=$currttl | ||
37 | fi | ||
38 | |||
39 | done | ||
40 | echo "$ttl" | ||
41 | } | ||
42 | |||
43 | function get_record_type { | ||
44 | arr=$1 | ||
45 | typ=$(echo -n "${arr[0]}" | cut -d' ' -f2) | ||
46 | echo "$typ" | ||
47 | } | ||
48 | |||
49 | function get_value { | ||
50 | arr=$1 | ||
51 | val=$(echo -n "${arr[0]}" | cut -d' ' -f4-) | ||
52 | echo "$val" | ||
53 | } | ||
54 | |||
55 | function testing { | ||
56 | label=$1 | ||
57 | records=$2 | ||
58 | recordstring="" | ||
59 | typ=$(get_record_type "${records[@]}") | ||
60 | for i in "${records[@]}" | ||
61 | do | ||
62 | recordstring+="-R $i" | ||
63 | done | ||
64 | #echo "$recordstring" | ||
65 | gnunet-namestore -z randomtestingid -n "$label" "$recordstring" 2>&1 /dev/null | ||
66 | if [ 0 -ne $ret ]; then | ||
67 | echo "failed to add record $label: $recordstring" | ||
68 | fi | ||
69 | gnunet-gns -t "$typ" -u foo2.randomtestingid 2>&1 /dev/null | ||
70 | if [ 0 -ne $ret ]; then | ||
71 | echo "record $label could not be found" | ||
72 | fi | ||
73 | } | ||
74 | |||
75 | # TEST CASES | ||
76 | # 1 | ||
77 | echo "Testing adding of single A record with -R" | ||
78 | declare -a arr=('1200 A n 127.0.0.1') | ||
79 | testing test1 "${arr[@]}" | ||
80 | # 2 | ||
81 | echo "Testing adding of multiple A records with -R" | ||
82 | declare -a arr=('1200 A n 127.0.0.1' '2400 A n 127.0.0.2') | ||
83 | testing test2 "${arr[@]}" | ||
84 | # 3 | ||
85 | echo "Testing adding of multiple different records with -R" | ||
86 | declare -a arr=('1200 A n 127.0.0.1' '2400 AAAA n 2002::') | ||
87 | testing test3 "${arr[@]}" | ||
88 | # 4 | ||
89 | echo "Testing adding of single GNS2DNS record with -R" | ||
90 | declare -a arr=('86400 GNS2DNS n gnu.org@127.0.0.1') | ||
91 | testing test4 "${arr[@]}" | ||
92 | # 5 | ||
93 | echo "Testing adding of single GNS2DNS shadow record with -R" | ||
94 | declare -a arr=('86409 GNS2DNS s gnu.org@127.0.0.250') | ||
95 | testing test5 "${arr[@]}" | ||
96 | # 6 | ||
97 | echo "Testing adding of multiple GNS2DNS record with -R" | ||
98 | declare -a arr=('1 GNS2DNS n gnunet.org@127.0.0.1' '3600 GNS2DNS s gnunet.org@127.0.0.2') | ||
99 | testing test6 "${arr[@]}" | ||
100 | val=$(gnunet-gns -t GNS2DNS -u test6.randomtestingid) | ||
101 | if [[ $val == *"127.0.0.1"* ]]; then | ||
102 | echo "shadow!" | ||
103 | fi | ||
104 | echo "Sleeping to let record expire" | ||
105 | sleep 5 | ||
106 | val=$(gnunet-gns -t GNS2DNS -u test6.randomtestingid) | ||
107 | if [[ $val == *"127.0.0.2"* ]]; then | ||
108 | echo "no shadow!" | ||
109 | fi | ||
110 | # 7 | ||
111 | echo "Testing adding MX record with -R" | ||
112 | declare -a arr=('3600 MX n 10,mail') | ||
113 | testing test7 "${arr[@]}" | ||
114 | # 8 | ||
115 | echo "Testing adding TXT record with -R" | ||
116 | declare -a arr=('3600 TXT n Pretty_Unicorns') | ||
117 | testing test8 "${arr[@]}" | ||
118 | # 8 | ||
119 | echo "Testing adding TXT record with -R" | ||
120 | declare -a arr=('3600 SRV n _autodiscover_old._tcp.bfh.ch.') | ||
121 | testing test8 "${arr[@]}" | ||
122 | |||
123 | # CLEANUP | ||
124 | gnunet-identity -D randomtestingid | ||