merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

test_merchant_accounts.sh (8938B)


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