diff options
Diffstat (limited to 'src/testing')
-rwxr-xr-x | src/testing/initialize_taler_system.sh | 13 | ||||
-rwxr-xr-x | src/testing/test_merchant_order_creation.sh | 121 |
2 files changed, 107 insertions, 27 deletions
diff --git a/src/testing/initialize_taler_system.sh b/src/testing/initialize_taler_system.sh index 277d55e6..c4127684 100755 --- a/src/testing/initialize_taler_system.sh +++ b/src/testing/initialize_taler_system.sh @@ -20,6 +20,9 @@ function exit_fail() { # Cleanup to run whenever we exit function cleanup() { + # kill main HTTP servers first + kill ${MERCHANT_HTTPD_PID:-X} &> /dev/null || true + kill ${EXCHANGE_HTTPD_PID:-X} &> /dev/null || true for n in `jobs -p` do kill $n 2> /dev/null || true @@ -108,10 +111,12 @@ echo " OK" # Launch services echo -n "Launching taler services ..." taler-bank-manage-testing $CONF postgres:///$TALER_DB serve > taler-bank.log 2> taler-bank.err & -taler-exchange-secmod-eddsa -c $CONF 2> taler-exchange-secmod-eddsa.log & -taler-exchange-secmod-rsa -c $CONF 2> taler-exchange-secmod-rsa.log & -taler-exchange-httpd -c $CONF 2> taler-exchange-httpd.log & -taler-merchant-httpd -c $CONF -L INFO 2> taler-merchant-httpd.log & +taler-exchange-secmod-eddsa -c $CONF -L DEBUG 2> taler-exchange-secmod-eddsa.log & +taler-exchange-secmod-rsa -c $CONF -L DEBUG 2> taler-exchange-secmod-rsa.log & +taler-exchange-httpd -c $CONF -L DEBUG 2> taler-exchange-httpd.log & +EXCHANGE_HTTPD_PID=$! +taler-merchant-httpd -c $CONF -L DEBUG 2> taler-merchant-httpd.log & +MERCHANT_HTTPD_PID=$! taler-exchange-wirewatch -c $CONF 2> taler-exchange-wirewatch.log & taler-auditor-httpd -L INFO -c $CONF 2> taler-auditor-httpd.log & diff --git a/src/testing/test_merchant_order_creation.sh b/src/testing/test_merchant_order_creation.sh index bbababf0..f596666d 100755 --- a/src/testing/test_merchant_order_creation.sh +++ b/src/testing/test_merchant_order_creation.sh @@ -234,11 +234,11 @@ TO_SLEEP=`echo $(( ($WIRE_DEADLINE /1000) - $NOW ))` echo waiting $TO_SLEEP secs for wire transfer echo -n "Perform wire transfers ..." -taler-exchange-aggregator -c $CONF -T ${TO_SLEEP}000000 -t -L INFO -taler-exchange-transfer -c $CONF -t -L INFO +taler-exchange-aggregator -c $CONF -T ${TO_SLEEP}000000 -t -L INFO &> aggregator.log +taler-exchange-transfer -c $CONF -t -L INFO &> transfer.log echo " DONE" -echo -n "Notifying merchant of wire transfer ..." +echo -n "Obtaining wire transfer details from bank..." # First, extract the wire transfer data from the bank. # As there is no "nice" API, we do this by dumping the @@ -260,20 +260,85 @@ then exit_fail "Wrong exchange URL in subject '$SUBJECT', expected $EXCHANGE_URL" fi +echo " OK" + set +e +export TARGET_PAYTO +export WURL +export WTID +export CREDIT_AMOUNT +export LAST_RESPONSE + +echo -n "Notifying merchant of bogus wire transfer ..." + STATUS=$(curl 'http://localhost:9966/instances/default/private/transfers' \ -d '{"credit_amount":"'$CREDIT_AMOUNT'1","wtid":"'$WTID'","payto_uri":"'$TARGET_PAYTO'","exchange_url":"'$WURL'"}' \ -m 3 \ -w "%{http_code}" -s -o $LAST_RESPONSE) -set -e +if [ "$STATUS" != "409" ] +then + jq . < $LAST_RESPONSE + exit_fail "Expected to fail since the amount is not valid. got: $STATUS" +fi + +echo "OK" +echo -n "Notifying merchant of bogus wire transfer AGAIN ..." + +STATUS=$(curl 'http://localhost:9966/instances/default/private/transfers' \ + -d '{"credit_amount":"'$CREDIT_AMOUNT'1","wtid":"'$WTID'","payto_uri":"'$TARGET_PAYTO'","exchange_url":"'$WURL'"}' \ + -m 3 \ + -w "%{http_code}" -s -o $LAST_RESPONSE) -if [ "$STATUS" != "000" ] +if [ "$STATUS" != "409" ] then + jq . < $LAST_RESPONSE exit_fail "Expected to fail since the amount is not valid. got: $STATUS" fi +echo " OK" +echo -n "Notifying merchant of correct wire transfer (conflicting with old data)..." + +STATUS=$(curl 'http://localhost:9966/instances/default/private/transfers' \ + -d '{"credit_amount":"'$CREDIT_AMOUNT'","wtid":"'$WTID'","payto_uri":"'$TARGET_PAYTO'","exchange_url":"'$WURL'"}' \ + -m 3 \ + -w "%{http_code}" -s -o $LAST_RESPONSE) + +if [ "$STATUS" != "409" ] +then + jq . < $LAST_RESPONSE + exit_fail "Expected response conflict, after providing conflicting transfer data. got: $STATUS" +fi + +echo " OK" + +echo -n "Deleting bogus wire transfer ..." + +TID=`curl -s http://localhost:9966/instances/default/private/transfers | jq -r .transfers[0].transfer_serial_id` +STATUS=$(curl -H "Content-Type: application/json" -X DELETE \ + "http://localhost:9966/instances/default/private/transfers/$TID" \ + -w "%{http_code}" -s -o $LAST_RESPONSE) + +if [ "$STATUS" != "204" ] +then + jq . < $LAST_RESPONSE + exit_fail "Expected response 204 No Content, after deleting valid TID. got: $STATUS" +fi + +STATUS=$(curl -H "Content-Type: application/json" -X DELETE \ + "http://localhost:9966/instances/default/private/transfers/$TID" \ + -w "%{http_code}" -s -o $LAST_RESPONSE) +if [ "$STATUS" != "404" ] +then + jq . < $LAST_RESPONSE + exit_fail "Expected response 404 Not found, after deleting TID again. got: $STATUS" +fi + +echo " OK" + +echo -n "Notifying merchant of correct wire transfer (now working)..." + STATUS=$(curl 'http://localhost:9966/instances/default/private/transfers' \ -d '{"credit_amount":"'$CREDIT_AMOUNT'","wtid":"'$WTID'","payto_uri":"'$TARGET_PAYTO'","exchange_url":"'$WURL'"}' \ -m 3 \ @@ -281,10 +346,14 @@ STATUS=$(curl 'http://localhost:9966/instances/default/private/transfers' \ if [ "$STATUS" != "200" ] then - echo `cat $LAST_RESPONSE` + jq . < $LAST_RESPONSE exit_fail "Expected response ok, after providing transfer data. got: $STATUS" fi +echo " OK" +echo -n "Testing idempotence ..." +set -e + # Test idempotence: do it again! STATUS=$(curl 'http://localhost:9966/instances/default/private/transfers' \ @@ -293,10 +362,12 @@ STATUS=$(curl 'http://localhost:9966/instances/default/private/transfers' \ if [ "$STATUS" != "200" ] then - echo `cat $LAST_RESPONSE` + jq . < $LAST_RESPONSE exit_fail "Expected response ok, after providing transfer data. got: $STATUS" fi +echo " OK" +echo -n "Sending bogus WTID ..." # # CHECK TRANSFER API # @@ -305,44 +376,44 @@ STATUS=$(curl 'http://localhost:9966/instances/default/private/transfers' \ -d '{"credit_amount":"'$CREDIT_AMOUNT'","wtid":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","payto_uri":"'$TARGET_PAYTO'","exchange_url":"'$WURL'"}' \ -w "%{http_code}" -s -o $LAST_RESPONSE) -jq . < $LAST_RESPONSE - if [ "$STATUS" != "502" ] then - echo `cat $LAST_RESPONSE` + jq . < $LAST_RESPONSE exit_fail "Expected response invalid since the WTID is fake. got: $STATUS" fi +echo "OK" +echo -n "Fetching wire transfers ..." + STATUS=$(curl 'http://localhost:9966/instances/default/private/transfers' \ -w "%{http_code}" -s -o $LAST_RESPONSE) -jq . < $LAST_RESPONSE - if [ "$STATUS" != "200" ] then - echo `cat $LAST_RESPONSE` - exit_fail "Expected response ok. got: $STATUS" + jq . < $LAST_RESPONSE + exit_fail "Expected response 200 Ok. got: $STATUS" fi TRANSFERS_LIST_SIZE=`jq -r '.transfers | length' < $LAST_RESPONSE` if [ "$TRANSFERS_LIST_SIZE" != "2" ] then - echo `cat $LAST_RESPONSE` + jq . < $LAST_RESPONSE exit_fail "Expected response ok. got: $STATUS" fi +echo "OK" +echo -n "Fetching wire transfer details of bogus WTID ..." + # Test for #6854: use a bogus WTID, causing the exchange to fail to # find the WTID. STATUS=$(curl 'http://localhost:9966/instances/default/private/transfers' \ -d '{"credit_amount":"'$CREDIT_AMOUNT'","wtid":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","payto_uri":"'$TARGET_PAYTO'","exchange_url":"'$WURL'"}' \ -w "%{http_code}" -s -o $LAST_RESPONSE) -jq . < $LAST_RESPONSE - if [ "$STATUS" != "502" ] then - echo `cat $LAST_RESPONSE` + jq . < $LAST_RESPONSE exit_fail "Expected response invalid since the WTID is fake. got: $STATUS" fi @@ -353,8 +424,11 @@ echo -n "Checking order status ..." STATUS=$(curl "http://localhost:9966/instances/default/private/orders/${ORDER_ID}?transfer=YES" \ -w "%{http_code}" -s -o $LAST_RESPONSE) + + if [ "$STATUS" != "200" ] then + jq . < $LAST_RESPONSE exit_fail 'should response ok, after order inquiry. got:' $STATUS `cat $LAST_RESPONSE` exit 1 fi @@ -364,13 +438,12 @@ DEPOSIT_TOTAL=`jq -r .deposit_total < $LAST_RESPONSE` if [ "$DEPOSIT_TOTAL" == "TESTKUDOS:0" ] then echo 'deposit total is zero, expected greater than zero. got:' $DEPOSIT_TOTAL `cat $LAST_RESPONSE` - bash exit 1 fi echo " OK" -echo Removing password from account 43 +echo -n "Removing password from account 43 ..." taler-bank-manage -c $CONF --with-db postgres:///$TALER_DB django changepassword_unsafe 43 x >/dev/null 2>/dev/null ACCOUNT_PASSWORD="43:x" @@ -381,7 +454,8 @@ STATUS=$(curl "http://$ACCOUNT_PASSWORD@$BANK_HOST/accounts/43" \ if [ "$STATUS" != "200" ] then - echo 'should response ok, getting account status. got:' $STATUS `cat $LAST_RESPONSE` + jq . < $LAST_RESPONSE + echo "Expected response 200 Ok, getting account status. Got: $STATUS" exit 1 fi @@ -389,10 +463,11 @@ BALANCE=`jq -r .balance.amount < $LAST_RESPONSE` if [ "$BALANCE" == "TESTKUDOS:0" ] then - echo 'Wire transfer did not happen. Got:' $BALANCE `cat $LAST_RESPONSE` + jq . < $LAST_RESPONSE + echo "Wire transfer did not happen. Got: $BALANCE" exit 1 fi - +echo " OK" exit 0 |