diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-06-16 22:14:35 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-06-16 22:14:35 +0200 |
commit | 23b4c5eb9d830fa272c8011b62ac20ef7749f246 (patch) | |
tree | 84526f5861abed96e18d0fd32a6b740a7615c75b /src/testing/test_merchant_order_creation.sh | |
parent | 1fa773793b24285205818c21c70fb72cd63fe6ba (diff) | |
download | merchant-23b4c5eb9d830fa272c8011b62ac20ef7749f246.tar.gz merchant-23b4c5eb9d830fa272c8011b62ac20ef7749f246.tar.bz2 merchant-23b4c5eb9d830fa272c8011b62ac20ef7749f246.zip |
fixing #6903
Diffstat (limited to 'src/testing/test_merchant_order_creation.sh')
-rwxr-xr-x | src/testing/test_merchant_order_creation.sh | 121 |
1 files changed, 98 insertions, 23 deletions
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 |