test_merchant_accounts.sh (9631B)
1 #!/usr/bin/env 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 # Cleanup to run whenever we exit 21 function my_cleanup() 22 { 23 for n in $(jobs -p) 24 do 25 kill "$n" 2> /dev/null || true 26 done 27 wait 28 if [ -n "${LAST_RESPONSE+x}" ] 29 then 30 rm -f "${LAST_RESPONSE}" 31 fi 32 } 33 34 . setup.sh 35 36 setup -c test_template.conf -m 37 CONF="test_template.conf.edited" 38 LAST_RESPONSE=$(mktemp -p "${TMPDIR:-/tmp}" test_response.conf-XXXXXX) 39 40 echo -n "Configuring 'admin' instance ..." >&2 41 42 STATUS=$(curl -H "Content-Type: application/json" -X POST \ 43 http://localhost:9966/management/instances \ 44 -d '{"auth":{"method":"token","password":"secret-token:new_value"},"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}}' \ 45 -w "%{http_code}" -s -o "$LAST_RESPONSE") 46 47 if [ "$STATUS" != "204" ] 48 then 49 cat "$LAST_RESPONSE" >&2 50 exit_fail "Expected 204, instance created. got: $STATUS" >&2 51 fi 52 53 echo "OK" >&2 54 55 ## 56 # Test deleting and creating the account again. 57 # it should bring the account active again 58 ## 59 60 echo -n "creating first account ..." >&2 61 62 STATUS=$(curl -H "Content-Type: application/json" -X POST \ 63 -H 'Authorization: Bearer secret-token:new_value' \ 64 http://localhost:9966/private/accounts \ 65 -d '{"payto_uri":"payto://x-taler-bank/localhost:8082/43?receiver-name=user43"}' \ 66 -w "%{http_code}" -s -o "$LAST_RESPONSE") 67 68 69 if [ "$STATUS" != "200" ] 70 then 71 cat "$LAST_RESPONSE" >&2 72 exit_fail "Expected 200 OK. Got: $STATUS" 73 fi 74 75 echo "OK" >&2 76 77 78 ACCOUNT_ID=$(jq -r .h_wire $LAST_RESPONSE) 79 80 STATUS=$(curl -H "Content-Type: application/json" -X GET \ 81 -H 'Authorization: Bearer secret-token:new_value' \ 82 http://localhost:9966/private/accounts/$ACCOUNT_ID \ 83 -w "%{http_code}" -s -o "$LAST_RESPONSE") 84 85 if [ "$STATUS" != "200" ] 86 then 87 cat "$LAST_RESPONSE" >&2 88 exit_fail "Expected 200 OK. Got: $STATUS" 89 fi 90 91 ACTIVE=$(jq -r .active $LAST_RESPONSE) 92 93 if [ "$ACTIVE" != "true" ] 94 then 95 cat "$LAST_RESPONSE" >&2 96 exit_fail "Expected account active." 97 fi 98 99 echo -n "deleting account ..." >&2 100 101 STATUS=$(curl -H "Content-Type: application/json" -X DELETE \ 102 -H 'Authorization: Bearer secret-token:new_value' \ 103 http://localhost:9966/private/accounts/$ACCOUNT_ID \ 104 -w "%{http_code}" -s -o "$LAST_RESPONSE") 105 106 if [ "$STATUS" != "204" ] 107 then 108 cat "$LAST_RESPONSE" >&2 109 exit_fail "Expected 204 OK. Got: $STATUS" 110 fi 111 112 echo "OK" >&2 113 114 echo -n "creating same account again to make it active ..." >&2 115 116 STATUS=$(curl -H "Content-Type: application/json" -X POST \ 117 -H 'Authorization: Bearer secret-token:new_value' \ 118 http://localhost:9966/private/accounts \ 119 -d '{"payto_uri":"payto://x-taler-bank/localhost:8082/43?receiver-name=user43"}' \ 120 -w "%{http_code}" -s -o "$LAST_RESPONSE") 121 122 123 if [ "$STATUS" != "200" ] 124 then 125 cat "$LAST_RESPONSE" >&2 126 exit_fail "Expected 200 OK. Got: $STATUS" 127 fi 128 129 STATUS=$(curl -H "Content-Type: application/json" -X GET \ 130 -H 'Authorization: Bearer secret-token:new_value' \ 131 http://localhost:9966/private/accounts/$ACCOUNT_ID \ 132 -w "%{http_code}" -s -o "$LAST_RESPONSE") 133 134 ACTIVE=$(jq -r .active $LAST_RESPONSE) 135 136 if [ "$ACTIVE" != "true" ] 137 then 138 cat "$LAST_RESPONSE" >&2 139 exit_fail "Expected account active." 140 fi 141 142 echo "OK" >&2 143 144 ## 145 # Using different name should conflict with previous account. 146 ## 147 148 ACCOUNT_ID=$(jq -r .h_wire $LAST_RESPONSE) 149 150 echo -n "creating same account with different name ..." >&2 151 152 STATUS=$(curl -H "Content-Type: application/json" -X POST \ 153 -H 'Authorization: Bearer secret-token:new_value' \ 154 http://localhost:9966/private/accounts \ 155 -d '{"payto_uri":"payto://x-taler-bank/localhost:8082/43?receiver-name=not-user-43"}' \ 156 -w "%{http_code}" -s -o "$LAST_RESPONSE") 157 158 159 if [ "$STATUS" != "409" ] 160 then 161 cat "$LAST_RESPONSE" >&2 162 exit_fail "Expected 409 Conflict. Got: $STATUS" 163 fi 164 165 STATUS=$(curl -H "Content-Type: application/json" -X GET \ 166 -H 'Authorization: Bearer secret-token:new_value' \ 167 http://localhost:9966/private/accounts/$ACCOUNT_ID \ 168 -w "%{http_code}" -s -o "$LAST_RESPONSE") 169 170 ACTIVE=$(jq -r .active $LAST_RESPONSE) 171 172 if [ "$ACTIVE" != "true" ] 173 then 174 cat "$LAST_RESPONSE" >&2 175 exit_fail "Expected account active." 176 fi 177 178 echo "OK" >&2 179 180 181 182 echo -n "deleting the account ..." >&2 183 184 STATUS=$(curl -H "Content-Type: application/json" -X DELETE \ 185 -H 'Authorization: Bearer secret-token:new_value' \ 186 http://localhost:9966/private/accounts/$ACCOUNT_ID \ 187 -w "%{http_code}" -s ) 188 189 if [ "$STATUS" != "204" ] 190 then 191 cat "$LAST_RESPONSE" >&2 192 exit_fail "Expected 204 OK. Got: $STATUS" 193 fi 194 195 echo "OK" >&2 196 197 echo -n "now make it active again ..." >&2 198 199 STATUS=$(curl -H "Content-Type: application/json" -X POST \ 200 -H 'Authorization: Bearer secret-token:new_value' \ 201 http://localhost:9966/private/accounts \ 202 -d '{"payto_uri":"payto://x-taler-bank/localhost:8082/43?receiver-name=not-user-43"}' \ 203 -w "%{http_code}" -s -o "$LAST_RESPONSE") 204 205 206 if [ "$STATUS" != "200" ] 207 then 208 cat "$LAST_RESPONSE" >&2 209 exit_fail "Expected 200 OK. Got: $STATUS" 210 fi 211 212 ACCOUNT_ID=$(jq -r .h_wire $LAST_RESPONSE) 213 214 STATUS=$(curl -H "Content-Type: application/json" -X GET \ 215 -H 'Authorization: Bearer secret-token:new_value' \ 216 http://localhost:9966/private/accounts/$ACCOUNT_ID \ 217 -w "%{http_code}" -s -o "$LAST_RESPONSE") 218 219 ACTIVE=$(jq -r .active $LAST_RESPONSE) 220 221 if [ "$ACTIVE" != "true" ] 222 then 223 cat "$LAST_RESPONSE" >&2 224 exit_fail "Expected account active." 225 fi 226 227 228 echo " OK" >&2 229 230 ## 231 # Activating the account again with different values should not break. 232 ## 233 234 echo -n "creating second account ..." >&2 235 236 STATUS=$(curl -H "Content-Type: application/json" -X POST \ 237 -H 'Authorization: Bearer secret-token:new_value' \ 238 http://localhost:9966/private/accounts \ 239 -d '{"payto_uri":"payto://x-taler-bank/localhost:8082/12?receiver-name=user12"}' \ 240 -w "%{http_code}" -s -o "$LAST_RESPONSE") 241 242 243 if [ "$STATUS" != "200" ] 244 then 245 cat "$LAST_RESPONSE" >&2 246 exit_fail "Expected 200 OK. Got: $STATUS" 247 fi 248 249 echo "OK" >&2 250 251 252 ACCOUNT_ID=$(jq -r .h_wire $LAST_RESPONSE) 253 254 STATUS=$(curl -H "Content-Type: application/json" -X GET \ 255 -H 'Authorization: Bearer secret-token:new_value' \ 256 http://localhost:9966/private/accounts/$ACCOUNT_ID \ 257 -w "%{http_code}" -s -o "$LAST_RESPONSE") 258 259 if [ "$STATUS" != "200" ] 260 then 261 cat "$LAST_RESPONSE" >&2 262 exit_fail "Expected 200 OK. Got: $STATUS" 263 fi 264 265 ACTIVE=$(jq -r .active $LAST_RESPONSE) 266 267 if [ "$ACTIVE" != "true" ] 268 then 269 cat "$LAST_RESPONSE" >&2 270 exit_fail "Expected account active." 271 fi 272 273 echo -n "deleting second account ..." >&2 274 275 STATUS=$(curl -H "Content-Type: application/json" -X DELETE \ 276 -H 'Authorization: Bearer secret-token:new_value' \ 277 http://localhost:9966/private/accounts/$ACCOUNT_ID \ 278 -w "%{http_code}" -s ) 279 280 if [ "$STATUS" != "204" ] 281 then 282 cat "$LAST_RESPONSE" >&2 283 exit_fail "Expected 204 OK. Got: $STATUS" 284 fi 285 286 echo "OK" >&2 287 288 echo -n "make it active with different facade ..." >&2 289 290 STATUS=$(curl -H "Content-Type: application/json" -X POST \ 291 -H 'Authorization: Bearer secret-token:new_value' \ 292 http://localhost:9966/private/accounts \ 293 -d '{"payto_uri":"payto://x-taler-bank/localhost:8082/12?receiver-name=user12", "credit_facade_credentials":{"type":"none"},"credit_facade_url":"http://asd.com/"}' \ 294 -w "%{http_code}" -s -o "$LAST_RESPONSE") 295 296 297 if [ "$STATUS" != "200" ] 298 then 299 cat "$LAST_RESPONSE" >&2 300 exit_fail "Expected 200 OK. Got: $STATUS" 301 fi 302 303 STATUS=$(curl -H "Content-Type: application/json" -X GET \ 304 -H 'Authorization: Bearer secret-token:new_value' \ 305 http://localhost:9966/private/accounts/$ACCOUNT_ID \ 306 -w "%{http_code}" -s -o "$LAST_RESPONSE") 307 308 ACTIVE=$(jq -r .active "$LAST_RESPONSE") 309 310 if [ "$ACTIVE" != "true" ] 311 then 312 cat "$LAST_RESPONSE" >&2 313 exit_fail "Expected account active." 314 fi 315 316 FACADE=$(jq -r .credit_facade_url "$LAST_RESPONSE") 317 318 if [ "$FACADE" != "http://asd.com/" ] 319 then 320 cat "$LAST_RESPONSE" >&2 321 exit_fail "Expected account with facade http://asd.com/." 322 fi 323 324 echo "OK" >&2 325 326 ## 327 # Still, the previous activation should only work if the account is deactivated, the same as if the account was deleted. 328 # Trying to create when there is already an active account but with different values should return Conflict 409. 329 ## 330 331 echo -n "should validate conflict ..." >&2 332 333 STATUS=$(curl -H "Content-Type: application/json" -X POST \ 334 -H 'Authorization: Bearer secret-token:new_value' \ 335 http://localhost:9966/private/accounts \ 336 -d '{"payto_uri":"payto://x-taler-bank/localhost:8082/12?receiver-name=user12", "credit_facade_credentials":{"type":"none"},"credit_facade_url":"http://invalid.com/"}' \ 337 -w "%{http_code}" -s -o "$LAST_RESPONSE") 338 339 340 if [ "$STATUS" != "409" ] 341 then 342 cat "$LAST_RESPONSE" >&2 343 exit_fail "Expected 409 Conflict. Got: $STATUS" 344 fi 345 346 echo "OK" >&2 347 348 echo "Test PASSED" 349 350 exit 0