merchant

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

commit 3f7dc1464ccfa875e49481990bc74e6c1ff9f07a
parent 1d39ca797e0276dcaae7eb8c202a652df3b34c03
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date:   Sat, 22 Mar 2025 22:21:29 +0100

various oversights fixed

Diffstat:
Msrc/backend/taler-merchant-httpd.c | 24+++++++++++++++---------
Msrc/testing/test_merchant_instance_response.sh | 50++++++++++++++++++++++++++++++++++++++++----------
2 files changed, 55 insertions(+), 19 deletions(-)

diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c @@ -251,6 +251,7 @@ TMH_check_auth_instance (const char *token, char *tmp; const char *instance_name; const char *password; + const char *target_instance = "default"; enum GNUNET_GenericReturnValue ret; if (0 == GNUNET_STRINGS_base64_decode (token, @@ -271,8 +272,11 @@ TMH_check_auth_instance (const char *token, GNUNET_free (tmp); return GNUNET_SYSERR; } - if (0 != strncmp (instance_name, instance->settings.id, - strlen (instance->settings.id))) + + if (NULL != instance->settings.id) + target_instance = instance->settings.id; + if (0 != strncmp (instance_name, target_instance, + strlen (target_instance))) { GNUNET_free (tmp); return GNUNET_SYSERR; @@ -1885,7 +1889,7 @@ url_handler (void *cls, { const char *auth; bool auth_ok; - bool is_basic_auth; + bool is_basic_auth = false; bool auth_malformed = false; /* PATCHing an instance can alternatively be checked against @@ -1915,10 +1919,12 @@ url_handler (void *cls, purged) AND no override credentials, THEN we accept anything (no access control), as we then also have no data to protect. */ // FIXME this must somehow carry over to tokens - auth_ok = ( (0 == - GNUNET_CONTAINER_multihashmap_size (TMH_by_id_map)) && - (NULL == TMH_default_auth) ); - if (is_basic_auth) + if ( (0 == GNUNET_CONTAINER_multihashmap_size (TMH_by_id_map)) && + (NULL == TMH_default_auth) ) + { + hc->auth_scope = TMH_AS_ALL; + } + else if (is_basic_auth) { /* Handle token endpoint slightly differently: Only allow * instance password (Basic auth) OR @@ -1938,11 +1944,11 @@ url_handler (void *cls, } /* Check against selected instance, if we have one */ if (NULL != hc->instance) - auth_ok |= (GNUNET_OK == + auth_ok = (GNUNET_OK == TMH_check_auth_instance (auth, hc->instance)); else /* Are the credentials provided OK for CLI override? */ - auth_ok |= (use_default && + auth_ok = (use_default && (NULL != TMH_default_auth) && (NULL != auth) && (! auth_malformed) && diff --git a/src/testing/test_merchant_instance_response.sh b/src/testing/test_merchant_instance_response.sh @@ -20,8 +20,9 @@ . setup.sh # Launch only the merchant. -setup -c test_template.conf -m +setup -c test_template.conf -m -v +LAST_RESPONSE=$(mktemp -p "${TMPDIR:-/tmp}" test_response.conf-XXXXXX) STATUS=$(curl -H "Content-Type: application/json" -X OPTIONS \ http://localhost:9966/private/products \ @@ -33,7 +34,6 @@ then fi STATUS=$(curl -H "Content-Type: application/json" -X GET \ - -H 'Authorization: Bearer secret-token:super_secret' \ http://localhost:9966/private/products \ -w "%{http_code}" -s -o /dev/null) @@ -43,9 +43,8 @@ then fi STATUS=$(curl -H "Content-Type: application/json" -X POST \ - -H 'Authorization: Bearer secret-token:super_secret' \ http://localhost:9966/management/instances \ - -d '{"auth":{"method":"token","token":"secret-token: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}}' \ + -d '{"auth":{"method":"token","token":"other_secret"},"id":"default","admin":"default","user_type":"business","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 3600000000},"default_pay_delay":{"d_us": 3600000000}}' \ -w "%{http_code}" -s -o /dev/null) if [ "$STATUS" != "204" ] @@ -62,8 +61,24 @@ then exit_fail "Expected 401 without the token for the list of product when the admin instance was created. got: $STATUS" fi +BASIC_AUTH=$(echo -n default:other_secret | base64) + +STATUS=$(curl -H "Content-Type: application/json" -X POST \ + -H "Authorization: Basic $BASIC_AUTH" \ + http://localhost:9966/private/token \ + -d '{"scope":"write"}' \ + -w "%{http_code}" -s -o $LAST_RESPONSE) + + +if [ "$STATUS" != "200" ] +then + exit_fail "Expected 200 OK. Got: $STATUS" +fi + +TOKEN=$(jq -e -r .token < $LAST_RESPONSE) + STATUS=$(curl -H "Content-Type: application/json" -X GET \ - -H 'Authorization: Bearer secret-token:other_secret' \ + -H "Authorization: Bearer $TOKEN" \ http://localhost:9966/private/products \ -w "%{http_code}" -s -o /dev/null) @@ -73,9 +88,9 @@ then fi STATUS=$(curl -H "Content-Type: application/json" -X POST \ - -H 'Authorization: Bearer secret-token:other_secret' \ + -H "Authorization: Bearer $TOKEN" \ http://localhost:9966/private/auth \ - -d '{"method":"token","token":"secret-token:zxc"}' \ + -d '{"method":"token","token":"zxc"}' \ -w "%{http_code}" -s -o /dev/null) if [ "$STATUS" != "204" ] @@ -95,7 +110,7 @@ then fi STATUS=$(curl -H "Content-Type: application/json" -X DELETE \ - -H 'Authorization: Bearer secret-token:other_secret' \ + -H "Authorization: Bearer $TOKEN" \ "http://localhost:9966/private" \ -w "%{http_code}" -s -o /dev/null) @@ -104,8 +119,23 @@ then exit_fail "Expected 401 using old token, when purging the instance. got: $STATUS" fi +BASIC_AUTH=$(echo -n default:zxc | base64) + +STATUS=$(curl -H "Content-Type: application/json" -X POST \ + -H "Authorization: Basic $BASIC_AUTH" \ + http://localhost:9966/private/token \ + -d '{"scope":"write"}' \ + -w "%{http_code}" -s -o $LAST_RESPONSE) + + +if [ "$STATUS" != "200" ] +then + exit_fail "Expected 200 OK. Got: $STATUS" +fi + +TOKEN=$(jq -e -r .token < $LAST_RESPONSE) STATUS=$(curl -H "Content-Type: application/json" -X DELETE \ - -H 'Authorization: Bearer secret-token:zxc' \ + -H "Authorization: Bearer $TOKEN" \ "http://localhost:9966/private" \ -w "%{http_code}" -s -o /dev/null) @@ -115,7 +145,7 @@ then fi STATUS=$(curl -H "Content-Type: application/json" -X GET \ - -H 'Authorization: Bearer secret-token:zxc' \ + -H "Authorization: Bearer $TOKEN" \ http://localhost:9966/private/products \ -w "%{http_code}" -s -o /dev/null)