exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

test_taler_exchange_httpd.sh (3025B)


      1 #!/usr/bin/env bash
      2 #
      3 # This file is part of TALER
      4 # Copyright (C) 2015-2020, 2023 Taler Systems SA
      5 #
      6 #  TALER is free software; you can redistribute it and/or modify it under the
      7 #  terms of the GNU Affero General Public License as published by the Free Software
      8 #  Foundation; either version 3, or (at your option) any later version.
      9 #
     10 #  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     11 #  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     12 #  A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
     13 #
     14 #  You should have received a copy of the GNU Affero General Public License along with
     15 #  TALER; see the file COPYING.  If not, If not, see <http://www.gnu.org/licenses/>
     16 #
     17 #
     18 # This script uses 'curl' to POST various ill-formed requests to the
     19 # taler-exchange-httpd.  Basically, the goal is to make sure that the
     20 # HTTP server survives (and produces the 'correct' error code).
     21 #
     22 #
     23 # Clear environment from variables that override config.
     24 unset XDG_DATA_HOME
     25 unset XDG_CONFIG_HOME
     26 
     27 set -eu
     28 #
     29 echo -n "Launching exchange ..."
     30 PREFIX=
     31 # Uncomment this line to run with valgrind...
     32 #PREFIX="valgrind --leak-check=yes --track-fds=yes --error-exitcode=1 --log-file=valgrind.%p"
     33 
     34 # Setup database
     35 taler-exchange-dbinit -c test_taler_exchange_httpd.conf &> /dev/null || exit 77
     36 # Run Exchange HTTPD (in background)
     37 $PREFIX taler-exchange-httpd -c test_taler_exchange_httpd.conf 2> test-exchange.log &
     38 EPID=$!
     39 # Give HTTP time to start
     40 
     41 for n in `seq 1 100`
     42 do
     43     echo -n "."
     44     sleep 0.1
     45     OK=1
     46     wget http://localhost:8081/seed -o /dev/null -O /dev/null >/dev/null && break
     47     OK=0
     48 done
     49 if [ 1 != $OK ]
     50 then
     51     echo "Failed to launch exchange"
     52     kill -TERM $!
     53     wait $!
     54     echo Process status: $?
     55     exit 77
     56 fi
     57 echo " DONE"
     58 
     59 # Finally run test...
     60 echo -n "Running tests ..."
     61 # We read the JSON snippets to POST from test_taler_exchange_httpd.post
     62 cat test_taler_exchange_httpd.post | grep -v ^\# | awk '{ print "curl -d \47"  $2 "\47 http://localhost:8081" $1 }' | bash &> /dev/null
     63 echo -n .
     64 # We read the JSON snippets to GET from test_taler_exchange_httpd.get
     65 cat test_taler_exchange_httpd.get | grep -v ^\# | awk '{ print "curl http://localhost:8081" $1 }' | bash &> /dev/null
     66 echo -n .
     67 # Also try them with various headers: Language
     68 cat test_taler_exchange_httpd.get | grep -v ^\# | awk '{ print "curl -H \"Accept-Language: fr,en;q=0.4,de\" http://localhost:8081" $1 }' | bash &> /dev/null
     69 echo -n .
     70 # Also try them with various headers: Accept encoding (wildcard #1)
     71 cat test_taler_exchange_httpd.get | grep -v ^\# | awk '{ print "curl -H \"Accept: text/*\" http://localhost:8081" $1 }' | bash &> /dev/null
     72 echo -n .
     73 # Also try them with various headers: Accept encoding (wildcard #2)
     74 cat test_taler_exchange_httpd.get | grep -v ^\# | awk '{ print "curl -H \"Accept: */plain\" http://localhost:8081" $1 }' | bash &> /dev/null
     75 
     76 echo " DONE"
     77 kill -TERM "${EPID}"
     78 wait $!
     79 # Return status code from exchange for this script
     80 exit $?