test_merchant_auth_legacy.sh (4081B)
1 #!/usr/bin/env bash 2 # This file is part of TALER 3 # Copyright (C) 2026 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 # Tests the deprecated "Bearer secret-token:$PASSWORD" authentication 20 # without STRICT_PROTOCOL_V19. Remove together with that fallback. 21 # 22 set -eu 23 24 . setup.sh 25 26 # The TAN helpers started by the merchant write into this directory. 27 TALER_MERCHANT_TEST_TAN_DIR=$(mktemp -d -p "${TMPDIR:-/tmp}" test_merchant_auth_legacy-tan-XXXXXX) 28 export TALER_MERCHANT_TEST_TAN_DIR 29 30 # Launch system. 31 setup \ 32 -c "test_merchant_auth_legacy.conf" \ 33 -m 34 LAST_RESPONSE=$(mktemp -p "${TMPDIR:-/tmp}" test_response.conf-XXXXXX) 35 36 37 echo -n "Configuring a merchant admin instance ..." 38 STATUS=$(curl -H "Content-Type: application/json" -X POST \ 39 http://localhost:9966/management/instances \ 40 -d '{"auth":{"method":"token","password":"super_secret"},"id":"admin","name":"default","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 50000000},"default_pay_delay":{"d_us": 60000000}}' \ 41 -w "%{http_code}" -s \ 42 -o "$LAST_RESPONSE") 43 if [ "$STATUS" != "204" ] 44 then 45 jq < "$LAST_RESPONSE" 46 exit_fail "Expected 204 No Content. Got: $STATUS" 47 fi 48 echo " OK" 49 50 51 echo -n "Accept the password as bearer token without MFA ..." 52 STATUS=$(curl \ 53 -H 'Authorization: Bearer secret-token:super_secret' \ 54 http://localhost:9966/private/products \ 55 -w "%{http_code}" -s \ 56 -o "$LAST_RESPONSE") 57 if [ "$STATUS" != "200" ] 58 then 59 jq < "$LAST_RESPONSE" 60 exit_fail "Expected 200 OK. Got: $STATUS" 61 fi 62 echo " OK" 63 64 65 echo -n "Self-provision an instance with MFA ..." 66 INSTANCE_BODY='{"auth":{"method":"token","password":"pass1234"},"id":"self","name":"default","phone_number":"+4171234","email":"self@example.com","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 50000000},"default_pay_delay":{"d_us": 60000000}}' 67 STATUS=$(curl -H "Content-Type: application/json" -X POST \ 68 http://localhost:9966/instances \ 69 -d "$INSTANCE_BODY" \ 70 -w "%{http_code}" -s \ 71 -o "$LAST_RESPONSE") 72 if [ "$STATUS" != "202" ] 73 then 74 jq < "$LAST_RESPONSE" 75 exit_fail "Expected 202 Accepted. Got: $STATUS" 76 fi 77 CHALLENGE_IDS=$(solve_response_challenges "$LAST_RESPONSE" \ 78 self@example.com +4171234) 79 STATUS=$(curl -H "Content-Type: application/json" -X POST \ 80 -H "Taler-Challenge-Ids: $CHALLENGE_IDS" \ 81 http://localhost:9966/instances \ 82 -d "$INSTANCE_BODY" \ 83 -w "%{http_code}" -s \ 84 -o "$LAST_RESPONSE") 85 if [ "$STATUS" != "204" ] 86 then 87 jq < "$LAST_RESPONSE" 88 exit_fail "Expected 204 No Content. Got: $STATUS" 89 fi 90 echo " OK" 91 92 93 echo -n "Refuse the password as bearer token with MFA ..." 94 STATUS=$(curl \ 95 -H 'Authorization: Bearer secret-token:pass1234' \ 96 http://localhost:9966/instances/self/private/products \ 97 -w "%{http_code}" -s \ 98 -o "$LAST_RESPONSE") 99 if [ "$STATUS" != "401" ] || 100 [ "$(jq -r .code < "$LAST_RESPONSE")" != "2015" ] 101 then 102 jq < "$LAST_RESPONSE" 103 exit_fail "Expected 401 with code 2015. Got: $STATUS" 104 fi 105 echo " OK" 106 107 108 echo -n "Accept a login token with MFA ..." 109 SELF_TOKEN=$(merchant_login_mfa self pass1234 self@example.com +4171234) 110 STATUS=$(curl \ 111 -H "Authorization: Bearer $SELF_TOKEN" \ 112 http://localhost:9966/instances/self/private/products \ 113 -w "%{http_code}" -s \ 114 -o "$LAST_RESPONSE") 115 if [ "$STATUS" != "200" ] 116 then 117 jq < "$LAST_RESPONSE" 118 exit_fail "Expected 200 OK. Got: $STATUS" 119 fi 120 echo " OK" 121 122 123 echo "TEST PASSED" 124 125 exit 0