test_twister.sh (6185B)
1 #!/bin/sh 2 3 # This file is part of GNUnet. 4 # Copyright (C) 2018 Taler Systems SA 5 # 6 # Twister is free software; you can redistribute it and/or 7 # modify it under the terms of the GNU General Public License 8 # as published by the Free Software Foundation; either version 9 # 3, or (at your option) any later version. 10 # 11 # Twister is distributed in the hope that it will be useful, 12 # but WITHOUT ANY WARRANTY; without even the implied warranty 13 # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 14 # the GNU General Public License for more details. 15 # 16 # You should have received a copy of the GNU General Public 17 # License along with Twister; see the file COPYING. If not, 18 # write to the Free Software Foundation, Inc., 51 Franklin 19 # Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 21 # @author Marcello Stanisci 22 # @author Christian Grothoff 23 # 24 # @file test_twister.sh 25 # 26 # @brief Twister testcases. 27 28 29 if ! which curl > /dev/null 30 then 31 echo "curl not found"; 32 exit 77 33 fi 34 35 TWISTER_URL_V4="http://localhost:8888/" 36 TWISTER_URL="http://[::1]:8888/" 37 38 # Launch the Web server. 39 ./test_twister_webserver & 40 web_server_pid=$! 41 42 echo "Webserver launched." 43 44 # Launch the Twister. 45 taler-twister-service -c ./test_twister.conf & 46 twister_service_pid=$! 47 48 echo "Twister launched." 49 50 sleep 1 51 if ! ps xo pid | grep -q ${twister_service_pid}; then 52 echo Twister did not start correctly 53 return 77 54 fi 55 56 # hack the response code. 57 taler-twister -c ./test_twister.conf --responsecode 202 58 59 status_code=$(curl -s ${TWISTER_URL} -o /dev/null \ 60 -w "%{http_code}") 61 62 # check status code was hacked 63 if ! test 202 = $status_code; then 64 echo "Response code has not been hacked." 65 kill $web_server_pid 66 kill $twister_service_pid 67 exit 1 68 fi 69 70 71 echo "--responsecode 202 passed". 72 73 # malform response. 74 taler-twister -c ./test_twister.conf --malform 75 malformed_body=$(curl -s ${TWISTER_URL}) 76 77 # check response body has been emptied 78 if test '{"hello":[{"this":"browser!"}],"when":"today"}' = \ 79 "$malformed_body"; then 80 printf "Response body (%s) has not been emptied as expected\n" \ 81 "$malformed_body" 82 kill $web_server_pid 83 kill $twister_service_pid 84 exit 1 85 fi 86 87 echo "--malform passed". 88 89 # flip string. 90 taler-twister -c ./test_twister.conf -f "when" 91 flip_body=$(curl -s ${TWISTER_URL}) 92 flip_field=$(echo $flip_body | tr -d '"}{' | awk -F, '{print $2}' | awk -F: '{print $2}') 93 94 # check if pointed object was flipped. 95 if test "$flip_field" = 'today'; then 96 printf "Response body (%s vs. %s) has not been flipped as expected\n" "$flip_body" "$flip_field" 97 kill $web_server_pid 98 kill $twister_service_pid 99 exit 1 100 fi 101 102 echo "field-flip passed". 103 104 # delete object. 105 taler-twister -c ./test_twister.conf -d "hello.0" 106 emptied_body=$(curl -s ${TWISTER_URL}) 107 108 # check if pointed object was deleted. 109 if ! test '{"hello":[],"when":"today"}' = "$emptied_body"; then 110 printf "Response body (%s) has not been emptied as expected\n" \ 111 "$emptied_body" 112 kill $web_server_pid 113 kill $twister_service_pid 114 exit 1 115 fi 116 117 echo "field-deletion passed". 118 119 # set boolean field 120 taler-twister -c ./test_twister.conf \ 121 -m "hello" \ 122 --value "true" 123 modobject_body=$(curl -s ${TWISTER_URL}) 124 125 if ! test \ 126 '{"hello":true,"when":"today"}' = "$modobject_body"; then 127 printf "Response body (%s) has not been modified as expected\n" \ 128 "$modobject_body" 129 kill $web_server_pid 130 kill $twister_service_pid 131 exit 1 132 fi 133 134 echo "field-modification with boolean value passed". 135 136 # set field 137 taler-twister -c ./test_twister.conf \ 138 -m "hello" \ 139 --value "fake" 140 modobject_body=$(curl -s ${TWISTER_URL}) 141 142 if ! test \ 143 '{"hello":"fake","when":"today"}' = "$modobject_body"; then 144 printf "Response body (%s) has not been modified as expected\n" \ 145 "$modobject_body" 146 kill $web_server_pid 147 kill $twister_service_pid 148 exit 1 149 fi 150 151 echo "field-modification with string passed". 152 153 # set header 154 taler-twister -c ./test_twister.conf \ 155 -H "Date" \ 156 --value "January 32nd" 157 modobject_body=$(curl -sI ${TWISTER_URL} | grep -Fi Date | tr -d '\r') 158 echo $modobject_body 159 160 if ! test \ 161 'Date: January 32nd' = "$modobject_body"; then 162 printf "Response header (%s) has not been modified as expected\n" \ 163 "$modobject_body" 164 kill $web_server_pid 165 kill $twister_service_pid 166 exit 1 167 fi 168 169 echo "download header-modification passed". 170 171 # check if cumulative mods work. 172 taler-twister -c ./test_twister.conf \ 173 -m "hello" -V "world" \ 174 --deleteobject "when" 175 cum_mods=$(curl -s ${TWISTER_URL}) 176 177 if ! test '{"hello":"world"}' = $cum_mods; then 178 printf "Response body (%s) has not been" \ 179 " cumulative-modified as expected\n" \ 180 "$cum_mods" 181 kill $web_server_pid 182 kill $twister_service_pid 183 exit 1 184 fi 185 186 # check if Twister decompresses. 187 status_code=$(curl \ 188 -s "${TWISTER_URL}deflate-test" \ 189 -o /dev/null \ 190 -H "Content-Encoding: deflate" \ 191 -H "Content-Type: application/json" \ 192 --data-binary @body.json.deflate \ 193 -w "%{http_code}") 194 195 # check status code is okay. 196 if ! test 200 = $status_code; then 197 echo "Compression failed (status == ${status_code})." 198 kill $web_server_pid 199 kill $twister_service_pid 200 exit 1 201 fi 202 203 echo "cumulative mods passed". 204 205 # Just upload a big blob; first with PUT then with POST. 206 dd if=/dev/urandom of=BIGBLOB count=2 bs=1MB 207 printf "{\"things\": \"%s\"}" $(base64 BIGBLOB | tr -d '\n') > BIGBLOB.json 208 209 status_code=$(curl \ 210 -s "${TWISTER_URL}BIGPUT" \ 211 -o /dev/null \ 212 -X PUT \ 213 -H "Content-Type: application/json" \ 214 -d@BIGBLOB.json \ 215 -w "%{http_code}") 216 217 ## check status code is okay. 218 if ! test 200 = $status_code; then 219 echo "PUTting big blob failed (status == ${status_code})." 220 kill $web_server_pid 221 kill $twister_service_pid 222 rm BIGBLOB* 223 exit 1 224 fi 225 echo "PUT big load passed". 226 227 status_code=$(curl \ 228 -s "${TWISTER_URL}BIGPOST" \ 229 -o /dev/null \ 230 -X POST \ 231 -H "Content-Type: application/json" \ 232 -d@BIGBLOB.json \ 233 -w "%{http_code}") 234 235 ## check status code is okay. 236 if ! test 200 = $status_code; then 237 echo "POSTing big blob failed (status == ${status_code})." 238 kill $web_server_pid 239 kill $twister_service_pid 240 rm BIGBLOB* 241 exit 1 242 fi 243 244 echo "POST big load passed". 245 246 rm BIGBLOB* 247 248 # shutdown twister and webserver 249 kill $web_server_pid 250 kill $twister_service_pid 251 252 exit 0