test.sh (2967B)
1 #!/bin/bash 2 # Minimal script for testing, creates a first template 3 # that would work in combination with 'test.conf'. 4 # Run after starting taler-merchant-httpd and 5 # *before* starting paivana-httpd. 6 # 7 # This is a developer convenience, not part of `make check' -- 8 # nothing in meson.build refers to it, and it needs a merchant 9 # backend already listening on localhost:9966. 10 11 # Report the failure and exit non-zero. (The comment here used to 12 # claim this was a "skip", which is a different exit status and not 13 # what the body does: a merchant that will not take these calls is a 14 # real failure.) 15 function exit_fail() { 16 echo "$@" >&2 17 exit 1 18 } 19 20 for tool in curl jq; 21 do 22 if ! command -v "$tool" >/dev/null 2>&1; 23 then 24 exit_fail "$tool is required but not installed" 25 fi 26 done 27 28 LAST_RESPONSE=$(mktemp /tmp/last-response-XXXXXX.json) 29 # ...and is removed again however we leave, including through 30 # exit_fail, which used to leave one behind on every run. 31 trap 'rm -f "$LAST_RESPONSE"' EXIT 32 33 echo -n "Configuring merchant instance ..." 34 35 STATUS=$(curl -H "Content-Type: application/json" -X POST \ 36 -H 'Authorization: Bearer secret-token:sandbox' \ 37 http://localhost:9966/management/instances \ 38 -d '{"auth":{"method":"external"},"id":"admin","name":"default","user_type":"business","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 50000000000},"default_pay_delay":{"d_us": 60000000000}}' \ 39 -w "%{http_code}" \ 40 -s \ 41 -o "$LAST_RESPONSE") 42 43 if [ "$STATUS" != "204" ] 44 then 45 jq < "$LAST_RESPONSE" 46 exit_fail "Expected '204 No content' response. Got instead $STATUS" 47 fi 48 echo "OK" 49 50 echo -n "Configuring merchant bank account ..." 51 52 PAYTO="payto://x-taler-bank/bank.demo.taler.net/fortythree?receiver-name=43" 53 # add bank account address 54 STATUS=$(curl -H "Content-Type: application/json" \ 55 -X POST \ 56 -H 'Authorization: Bearer secret-token:sandbox' \ 57 http://localhost:9966/private/accounts \ 58 -d '{"payto_uri":"'"$PAYTO"'"}' \ 59 -w "%{http_code}" \ 60 -s \ 61 -o "$LAST_RESPONSE") 62 63 if [ "$STATUS" != "200" ] 64 then 65 jq < "$LAST_RESPONSE" 66 exit_fail "Expected '200 OK' response. Got instead $STATUS" 67 fi 68 echo "Ok" 69 70 echo -n "Creating Paivana template..." 71 TID="paivana" 72 STATUS=$(curl -H "Content-Type: application/json" \ 73 -X POST \ 74 'http://localhost:9966/private/templates' \ 75 -H 'Authorization: Bearer secret-token:sandbox' \ 76 -d '{"template_id":"paivana","template_description":"A Paivana template","template_contract":{"template_type":"paivana","summary":"The summary","website_regex":".*","choices":[{"amount":"KUDOS:1"}]}}' \ 77 -w "%{http_code}" \ 78 -s \ 79 -o "$LAST_RESPONSE") 80 81 if [ "$STATUS" != "204" ] 82 then 83 jq < "$LAST_RESPONSE" 84 exit_fail "Expected 204, template created. got: $STATUS" 85 fi 86 87 echo "OK"