test-sanctions.sh (2723B)
1 #!/bin/bash 2 # This file is part of TALER 3 # Copyright (C) 2014-2023 Taler Systems SA 4 # 5 # TALER is free software; you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as 7 # published by the Free Software Foundation; either version 3, or 8 # (at your option) any later version. 9 # 10 # TALER is distributed in the hope that it will be useful, but 11 # WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public 16 # License along with TALER; see the file COPYING. If not, see 17 # <http://www.gnu.org/licenses/> 18 # 19 set -eu 20 21 # Exit, with status code "skip" (no 'real' failure) 22 function exit_skip() { 23 echo "SKIPPING: $1" 24 exit 77 25 } 26 27 # Cleanup to run whenever we exit 28 function my_cleanup() 29 { 30 for n in $(jobs -p) 31 do 32 kill "$n" 2> /dev/null || true 33 done 34 wait 35 if [ -n "${LAST_RESPONSE+x}" ] 36 then 37 rm -f "${LAST_RESPONSE}" 38 fi 39 } 40 41 echo -n "Testing for robocop " 42 robocop -h > /dev/null 2> /dev/null || exit_skip "robocop required" 43 echo "FOUND" 44 45 . setup.sh 46 47 48 setup -c test_sanctions.conf \ 49 -e \ 50 -u "exchange-account-exchange" 51 52 53 CONF="test_sanctions.conf.edited" 54 LAST_RESPONSE=$(mktemp -p "${TMPDIR:-/tmp}" test_response.conf-XXXXXX) 55 56 KYC_URL=$(taler-exchange-kyc-trigger -c "$CONF" -b EUR:5 | tail -n1 | awk '{print $4}') 57 58 echo $KYC_URL 59 60 KYC_ACCESS=$(echo "$KYC_URL" | tr / ' ' | awk '{print $4}') 61 62 echo $KYC_ACCESS 63 64 echo -n "Creating order to test auth is ok..." >&2 65 STATUS=$(curl -H "Content-Type: application/json" \ 66 "http://localhost:8081/kyc-info/$KYC_ACCESS" \ 67 -w "%{http_code}" -s -o "$LAST_RESPONSE") 68 69 if [ "$STATUS" != "200" ] 70 then 71 cat "$LAST_RESPONSE" >&2 72 exit_fail "Expected 200, KYC information returned. got: $STATUS" 73 fi 74 75 ID=$(jq -r .requirements[0].id < "$LAST_RESPONSE") 76 77 echo -n "Submitting KYC form..." >&2 78 STATUS=$(curl -H "Content-Type: application/json" -X POST \ 79 "http://localhost:8081/kyc-upload/$ID" \ 80 -d '{"FULL_NAME":"Bob","DATE_OF_BIRTH":"5.7.1980"}' \ 81 -w "%{http_code}" -s -o "$LAST_RESPONSE") 82 echo $STATUS 83 84 if [ "$STATUS" != "204" ] 85 then 86 cat "$LAST_RESPONSE" >&2 87 exit_fail "Expected 204, KYC data submitted. got: $STATUS" 88 fi 89 90 taler-exchange-sanctionscheck \ 91 -L INFO \ 92 -c test_sanctions.conf.edited \ 93 --reset \ 94 --test 95 96 PROP=$(echo 'SELECT jproperties FROM exchange.legitimization_outcomes WHERE is_active;' | psql talercheck -Aqt) 97 98 MATCH=$(echo "$PROP" | jq -r .SANCTION_LIST_BEST_MATCH) 99 100 if [ "$MATCH" != "1" ] 101 then 102 exit_fail "Sanction checker failed to find Bob" 103 fi 104 105 echo "Test PASSED" 106 107 exit 0