aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/test_namestore_put_multiple.sh
blob: 81e1ad2b5ba1ec2dbf2c10fbdfb7abdbe79dac50 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash

# Check for required packages
if ! [ -x "$(command -v gnunet-namestore)" ]; then
    echo 'bind/named is not installed' >&2
    exit 1
fi

# Check if gnunet is running
gnunet-arm -I 2&>1 /dev/null
ret=$?
if [ 0 -ne $ret ]; then
    echo 'gnunet services are not running'
    exit 1
fi

## GNUNET part
# Check if identity exists and delets and readds it to get rid of entries in zone
gnunet-identity -d | grep randomtestingid 2>&1 /dev/null
ret=$?

if [ 0 -ne $ret ]; then
    gnunet-identity -D randomtestingid
    gnunet-identity -C randomtestingid
fi

function minimize_ttl {
    ttl=10000000
    arr=$1
    # parse each element and update ttl to smallest one
    for i in "${arr[@]}"
    do
        currttl=$(echo -n "$i" | cut -d' ' -f1)
        if [ "$currttl"  -lt "$ttl" ]
        then
            ttl=$currttl
        fi

    done
    echo "$ttl"
}

function get_record_type {
    arr=$1
    typ=$(echo -n "${arr[0]}" | cut -d' ' -f2)
    echo "$typ"
}

function get_value {
    arr=$1
    val=$(echo -n "${arr[0]}" | cut -d' ' -f4-)
    echo "$val"
}

function testing {
    label=$1
    records=$2
    recordstring=""
    typ=$(get_record_type "${records[@]}")
    for i in "${records[@]}"
    do
        recordstring+="-R $i"
    done
    #echo "$recordstring"
    gnunet-namestore -z randomtestingid -n "$label" "$recordstring" 2>&1  /dev/null
    if [ 0 -ne $ret ]; then
        echo "failed to add record $label: $recordstring"
    fi
    gnunet-gns -t "$typ" -u foo2.randomtestingid 2>&1 /dev/null
    if [ 0 -ne $ret ]; then
        echo "record $label could not be found"
    fi
}

# TEST CASES
# 1
echo "Testing adding of single A record with -R"
testing test1 "${arr[@]}"
# 2
echo "Testing adding of multiple A records with -R"
declare -a arr=('1200 A n 127.0.0.1' '2400 A n 127.0.0.2')
testing test2 "${arr[@]}"
# 3
echo "Testing adding of multiple different records with -R"
declare -a arr=('1200 A n 127.0.0.1' '2400 AAAA n 2002::')
testing test3 "${arr[@]}"
# 4
echo "Testing adding of single GNS2DNS record with -R"
declare -a arr=('86400 GNS2DNS n gnu.org@127.0.0.1')
testing test4 "${arr[@]}"
# 5
echo "Testing adding of single GNS2DNS shadow record with -R"
declare -a arr=('86409 GNS2DNS s gnu.org@127.0.0.250')
testing test5 "${arr[@]}"
# 6
echo "Testing adding of multiple GNS2DNS record with -R"
declare -a arr=('1 GNS2DNS n gnunet.org@127.0.0.1' '3600 GNS2DNS s gnunet.org@127.0.0.2')
testing test6 "${arr[@]}"
val=$(gnunet-gns -t GNS2DNS -u test6.randomtestingid)
if [[ $val == *"127.0.0.1"* ]]; then
    echo "shadow!"
fi
echo "Sleeping to let record expire"
sleep 5
val=$(gnunet-gns -t GNS2DNS -u test6.randomtestingid)
if [[ $val == *"127.0.0.2"* ]]; then
    echo "no shadow!"
fi
# 7
echo "Testing adding MX record with -R"
declare -a arr=('3600 MX n 10,mail')
testing test7 "${arr[@]}"
# 8
echo "Testing adding TXT record with -R"
declare -a arr=('3600 TXT n Pretty_Unicorns')
testing test8 "${arr[@]}"
# 8
echo "Testing adding TXT record with -R"
declare -a arr=('3600 SRV n _autodiscover_old._tcp.bfh.ch.')
testing test8 "${arr[@]}"

# CLEANUP
gnunet-identity -D randomtestingid