-remove debug message
[oweals/gnunet.git] / src / namestore / test_plugin_rest_namestore.sh
1 #!/bin/sh
2 trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
3
4 LOCATION=$(which gnunet-config)
5 if [ -z $LOCATION ]
6 then
7   LOCATION="gnunet-config"
8 fi
9 $LOCATION --version 1> /dev/null
10 if test $? != 0
11 then
12         echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13         exit 77
14 fi
15
16 rm -rf `gnunet-config -c test_namestore_api.conf -f -s paths -o GNUNET_TEST_HOME`
17
18 namestore_link="http://localhost:7776/namestore"
19 wrong_link="http://localhost:7776/namestoreandmore"
20
21
22 curl_get () {
23   #$1 is link
24   #$2 is grep
25   resp=$(curl -v "$1" 2>&1)
26   cache="$(echo $resp | grep "$2")"
27   #echo $cache
28   if [ "" = "$cache" ]
29   then
30     echo "Error in get response: $resp, expected $2"
31     gnunet-arm -e -c test_namestore_api.conf
32     exit 1
33   fi
34 }
35
36 curl_post () {
37   #$1 is link
38   #$2 is data
39   #$3 is grep
40   resp=$(curl -v -X "POST" "$1" --data "$2" 2>&1)
41   cache="$(echo $resp | grep "$3")"
42   #echo $cache
43   if [ "" = "$cache" ]
44   then
45     echo "Error in post response: $resp ($2), expected $3"
46     gnunet-arm -e -c test_namestore_api.conf
47     exit 1
48   fi
49 }
50
51 curl_delete () {
52   #$1 is link
53   #$2 is grep
54   resp=$(curl -v -X "DELETE" "$1" 2>&1)
55   cache="$(echo $resp | grep "$2")"
56   #echo $cache
57   if [ "" = "$cache" ]
58   then
59     echo "Error in delete response: $resp, expected $2"
60     gnunet-arm -e -c test_namestore_api.conf
61     exit 1
62   fi
63 }
64
65 # curl_put () {
66 #     #$1 is link
67 #     #$2 is data
68 #     #$3 is grep
69 #     cache="$(curl -v -X "PUT" "$1" --data "$2" 2>&1 | grep "$3")"
70 #     #echo $cache
71 #     if [ "" == "$cache" ]
72 #     then
73 #         exit 1
74 #     fi
75 # }
76
77 #Test subsystem default identity
78
79 TEST_ID="test"
80 gnunet-arm -s -c test_namestore_api.conf
81 gnunet-arm -i rest -c test_namestore_api.conf
82 #Test GET
83 gnunet-identity -C $TEST_ID -c test_namestore_api.conf
84 test="$(gnunet-namestore -D -z $TEST_ID -c test_namestore_api.conf)"
85 name=$TEST_ID
86 public="$(gnunet-identity -d -c test_namestore_api.conf | grep $TEST_ID | awk 'NR==1{print $3}')"
87 gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" -c test_namestore_api.conf
88 curl_get "${namestore_link}" "HTTP/1.1 200 OK"
89 curl_get "${namestore_link}/$name" "HTTP/1.1 200 OK"
90 curl_get "${namestore_link}/$public" "error"
91 gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf
92
93 #Test POST with NAME
94 curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0}],"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
95 gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
96
97 # invalid values
98 curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "record_type":"PKEY", "expiration_time":"1d","flag":0}],"record_name":"test_entry"}' "error"
99 gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
100
101
102 curl_post "${namestore_link}/$name" '{"data": [{"value":"", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name"}]:"test_entry"}' "error"
103 gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
104
105 curl_post "${namestore_link}/$name" '{"data": [{"record_type":"PKEY", "expiration_time":"1d","flag":0}],"record_name":"test_entry"}' "error"
106 gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
107
108 #expirations
109 curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"0d","flag":0}],"record_name":"test_entry"}' "HTTP/1.1 204"
110 gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
111
112 curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"10000d","flag":0}],"record_name":"test_entry"}' "HTTP/1.1 204"
113 gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
114
115 curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"now","flag":0}],"record_name":"test_entry"}' "error"
116 gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
117
118 curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time_missing":"1d","flag":0}],"record_name":"test_entry"}' "error"
119 gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1
120
121 #record_name
122 curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0}],"record_name":""}' "error"
123 gnunet-namestore -z $name -d -n "test_entry"  -c test_namestore_api.conf > /dev/null 2>&1
124 curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0}],"record_name_missing":"test_entry"}' "error"
125 gnunet-namestore -z $name -d -n "test_entry"  -c test_namestore_api.conf > /dev/null 2>&1
126
127 #Test DELETE
128 gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY"  -c test_namestore_api.conf
129 curl_delete "${namestore_link}/$name?record_name=test_entry" "HTTP/1.1 204" 
130 curl_delete "${namestore_link}/$name?record_name=test_entry" "error" 
131 gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY"  -c test_namestore_api.conf
132 curl_delete "${namestore_link}/$public?record_name=test_entry" "error" 
133
134 gnunet-arm -e  -c test_namestore_api.conf
135 exit 0;
136