test_merchant_instance_response.sh (5130B)
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 20 . setup.sh 21 22 # Launch only the merchant. 23 setup -c test_template.conf -m 24 25 LAST_RESPONSE=$(mktemp -p "${TMPDIR:-/tmp}" test_response.conf-XXXXXX) 26 27 STATUS=$(curl -H "Content-Type: application/json" -X OPTIONS \ 28 http://localhost:9966/private/products \ 29 -w "%{http_code}" -s -o /dev/null) 30 31 if [ "$STATUS" != "204" ] 32 then 33 exit_fail "Expected 204 when admin instance does not exist yet. got: $STATUS" 34 fi 35 36 STATUS=$(curl -H "Content-Type: application/json" -X GET \ 37 http://localhost:9966/private/products \ 38 -w "%{http_code}" -s -o /dev/null) 39 40 if [ "$STATUS" != "404" ] 41 then 42 exit_fail "Expected 404 when the admin instance is not yet created. got: $STATUS" 43 fi 44 45 STATUS=$(curl -H "Content-Type: application/json" -X POST \ 46 http://localhost:9966/management/instances \ 47 -d '{"auth":{"method":"token","password":"other_secret"},"id":"admin","name":"default","user_type":"business","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 3600000000},"default_pay_delay":{"d_us": 3600000000}}' \ 48 -w "%{http_code}" -s -o /dev/null) 49 50 if [ "$STATUS" != "204" ] 51 then 52 exit_fail "Expected 204, instance created. got: $STATUS" 53 fi 54 55 STATUS=$(curl -H "Content-Type: application/json" -X GET \ 56 http://localhost:9966/private/products \ 57 -w "%{http_code}" -s -o /dev/null) 58 59 if [ "$STATUS" != "401" ] 60 then 61 exit_fail "Expected 401 without the token for the list of product when the admin instance was created. got: $STATUS" 62 fi 63 64 BASIC_AUTH=$(echo -n admin:other_secret | base64) 65 66 STATUS=$(curl -H "Content-Type: application/json" -X POST \ 67 -H "Authorization: Basic $BASIC_AUTH" \ 68 http://localhost:9966/private/token \ 69 -d '{"scope":"write"}' \ 70 -w "%{http_code}" -s -o $LAST_RESPONSE) 71 72 73 if [ "$STATUS" != "200" ] 74 then 75 exit_fail "Expected 200 OK. Got: $STATUS" 76 fi 77 78 TOKEN=$(jq -e -r .access_token < $LAST_RESPONSE) 79 80 STATUS=$(curl -H "Content-Type: application/json" -X GET \ 81 -H "Authorization: Bearer $TOKEN" \ 82 http://localhost:9966/private/products \ 83 -w "%{http_code}" -s -o /dev/null) 84 85 if [ "$STATUS" != "200" ] 86 then 87 exit_fail "Expected 200 for the list of product when the admin instance was created. got: $STATUS" 88 fi 89 90 STATUS=$(curl -H "Content-Type: application/json" -X POST \ 91 -H "Authorization: Bearer $TOKEN" \ 92 http://localhost:9966/private/auth \ 93 -d '{"method":"token","password":"zxc"}' \ 94 -w "%{http_code}" -s -o /dev/null) 95 96 if [ "$STATUS" != "204" ] 97 then 98 exit_fail "Expected 204, instance auth token changed. got: $STATUS" 99 fi 100 101 102 STATUS=$(curl -H "Content-Type: application/json" -X DELETE \ 103 "http://localhost:9966/private" \ 104 -w "%{http_code}" -s -o /dev/null) 105 106 107 if [ "$STATUS" != "401" ] 108 then 109 exit_fail "Expected 401 without the token, when purging the instance. got: $STATUS" 110 fi 111 112 # FIXME: what we probably want here is that when changing the instance authentication 113 # settings all tokens are invalidated. We would have to add another DB operation 114 # for that. For now, we simply check here that we cannot get a new token with the 115 # old password. 116 STATUS=$(curl -H "Content-Type: application/json" -X POST \ 117 -H "Authorization: Basic $BASIC_AUTH" \ 118 http://localhost:9966/private/token \ 119 -d '{"scope":"write"}' \ 120 -w "%{http_code}" -s -o $LAST_RESPONSE) 121 122 123 if [ "$STATUS" != "401" ] 124 then 125 exit_fail "Expected 401 with old password. Got: $STATUS" 126 fi 127 128 BASIC_AUTH=$(echo -n admin:zxc | base64) 129 130 STATUS=$(curl -H "Content-Type: application/json" -X POST \ 131 -H "Authorization: Basic $BASIC_AUTH" \ 132 http://localhost:9966/private/token \ 133 -d '{"scope":"write"}' \ 134 -w "%{http_code}" -s -o $LAST_RESPONSE) 135 136 137 if [ "$STATUS" != "200" ] 138 then 139 exit_fail "Expected 200 OK. Got: $STATUS" 140 fi 141 142 TOKEN=$(jq -e -r .access_token < $LAST_RESPONSE) 143 144 STATUS=$(curl -H "Content-Type: application/json" -X DELETE \ 145 -H "Authorization: Bearer $TOKEN" \ 146 "http://localhost:9966/private" \ 147 -w "%{http_code}" -s -o /dev/null) 148 149 if [ "$STATUS" != "204" ] 150 then 151 exit_fail "Expected 204 when purging the instance. got: $STATUS" 152 fi 153 154 STATUS=$(curl -H "Content-Type: application/json" -X GET \ 155 -H "Authorization: Bearer $TOKEN" \ 156 http://localhost:9966/private/products \ 157 -w "%{http_code}" -s -o /dev/null) 158 159 if [ "$STATUS" != "404" ] 160 then 161 exit_fail "Expected 404 when trying to list the product and the admin instance was deleted. got: $STATUS" 162 fi 163 164 echo "Test PASSED" 165 166 exit 0