diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-09-02 14:10:54 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-09-02 14:10:58 +0200 |
commit | 4b8dc55c4330df6a3d2a552985afdd6a80737405 (patch) | |
tree | 3ca385ba66a0d39165765be0ca6ca13d415744e0 | |
parent | 98d9dfb8c8637b8902e8b7f249834f807fa3e322 (diff) | |
download | merchant-4b8dc55c4330df6a3d2a552985afdd6a80737405.tar.gz merchant-4b8dc55c4330df6a3d2a552985afdd6a80737405.tar.bz2 merchant-4b8dc55c4330df6a3d2a552985afdd6a80737405.zip |
fix internal APIs and implemnetation to match new UUID specification based on application-defined strings; implement test for order creation with locks (#6932)
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-orders.c | 25 | ||||
-rw-r--r-- | src/include/taler_merchant_service.h | 4 | ||||
-rw-r--r-- | src/lib/merchant_api_lock_product.c | 6 | ||||
-rw-r--r-- | src/lib/merchant_api_post_orders.c | 6 | ||||
-rwxr-xr-x | src/testing/test_merchant_product_creation.sh | 68 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_lock_product.c | 12 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_post_orders.c | 14 |
7 files changed, 88 insertions, 47 deletions
diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c index d6290eff..2706e511 100644 --- a/src/backend/taler-merchant-httpd_private-post-orders.c +++ b/src/backend/taler-merchant-httpd_private-post-orders.c @@ -1478,21 +1478,10 @@ TMH_private_post_orders (const struct TMH_RequestHandler *rh, json_array_size (uuid)); for (unsigned int i = 0; i<uuids_len; i++) { - const char *error_name; - unsigned int error_line; - const char *uuidsi; - struct GNUNET_JSON_Specification ispec[] = { - GNUNET_JSON_spec_string ("uuid", - &uuidsi), - GNUNET_JSON_spec_end () - }; + json_t *ui = json_array_get (uuid, + i); - ret = GNUNET_JSON_parse (json_array_get (uuid, - i), - ispec, - &error_name, - &error_line); - if (GNUNET_OK != ret) + if (! json_is_string (ui)) { GNUNET_break_op (0); GNUNET_array_grow (ips, @@ -1503,16 +1492,14 @@ TMH_private_post_orders (const struct TMH_RequestHandler *rh, 0); GNUNET_JSON_parse_free (spec); GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "UUID parsing failed at #%u: %s:%u\n", - i, - error_name, - error_line); + "UUID parsing failed at #%u\n", + i); return TALER_MHD_reply_with_error (connection, MHD_HTTP_BAD_REQUEST, TALER_EC_GENERIC_PARAMETER_MALFORMED, "lock_uuids"); } - TMH_uuid_from_string (uuidsi, + TMH_uuid_from_string (json_string_value (ui), &uuids[i]); } } diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h index cc44e660..cc3063f6 100644 --- a/src/include/taler_merchant_service.h +++ b/src/include/taler_merchant_service.h @@ -1213,7 +1213,7 @@ TALER_MERCHANT_product_lock ( struct GNUNET_CURL_Context *ctx, const char *backend_url, const char *product_id, - const struct GNUNET_Uuid *uuid, + const char *uuid, struct GNUNET_TIME_Relative duration, uint32_t quantity, TALER_MERCHANT_ProductLockCallback cb, @@ -1444,7 +1444,7 @@ TALER_MERCHANT_orders_post2 ( unsigned int inventory_products_length, const struct TALER_MERCHANT_InventoryProduct inventory_products[], unsigned int uuids_length, - const struct GNUNET_Uuid uuids[], + const char *uuids[], bool create_token, TALER_MERCHANT_PostOrdersCallback cb, void *cb_cls); diff --git a/src/lib/merchant_api_lock_product.c b/src/lib/merchant_api_lock_product.c index a3c345d5..3a3caaeb 100644 --- a/src/lib/merchant_api_lock_product.c +++ b/src/lib/merchant_api_lock_product.c @@ -159,7 +159,7 @@ TALER_MERCHANT_product_lock ( struct GNUNET_CURL_Context *ctx, const char *backend_url, const char *product_id, - const struct GNUNET_Uuid *uuid, + const char *uuid, struct GNUNET_TIME_Relative duration, uint32_t quantity, TALER_MERCHANT_ProductLockCallback cb, @@ -169,8 +169,8 @@ TALER_MERCHANT_product_lock ( json_t *req_obj; req_obj = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_data_auto ("lock_uuid", - uuid), + GNUNET_JSON_pack_string ("lock_uuid", + uuid), GNUNET_JSON_pack_time_rel ("duration", duration), GNUNET_JSON_pack_uint64 ("quantity", diff --git a/src/lib/merchant_api_post_orders.c b/src/lib/merchant_api_post_orders.c index b7e406f4..2cd16cba 100644 --- a/src/lib/merchant_api_post_orders.c +++ b/src/lib/merchant_api_post_orders.c @@ -247,7 +247,7 @@ TALER_MERCHANT_orders_post2 ( unsigned int inventory_products_length, const struct TALER_MERCHANT_InventoryProduct inventory_products[], unsigned int uuids_length, - const struct GNUNET_Uuid uuids[], + const char *uuids[], bool create_token, TALER_MERCHANT_PostOrdersCallback cb, void *cb_cls) @@ -310,9 +310,7 @@ TALER_MERCHANT_orders_post2 ( { json_t *u; - u = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_data_auto ("uuid", - &uuids[i])); + u = json_string (uuids[i]); GNUNET_assert (0 == json_array_append_new (ua, u)); diff --git a/src/testing/test_merchant_product_creation.sh b/src/testing/test_merchant_product_creation.sh index 938a13d3..78b95d4e 100755 --- a/src/testing/test_merchant_product_creation.sh +++ b/src/testing/test_merchant_product_creation.sh @@ -85,20 +85,47 @@ then cat $LAST_RESPONSE exit 1 fi - echo OK +MANAGED_PRODUCT_ID=$(echo $MANAGED_PRODUCT_TEMPLATE | jq -r '.product_id') + +echo -n "Locking inventory ..." + +STATUS=$(curl "http://localhost:9966/instances/default/private/products/${MANAGED_PRODUCT_ID}/lock" \ + -d '{"lock_uuid":"luck","duration":{"d_ms": 100000},"quantity":10}' \ + -w "%{http_code}" -s -o $LAST_RESPONSE) + +if [ "$STATUS" != "410" ] +then + echo 'should respond gone, lock failed. got:' $STATUS `cat $LAST_RESPONSE` + exit 1 +fi + +echo -n "." + +STATUS=$(curl "http://localhost:9966/instances/default/private/products/${MANAGED_PRODUCT_ID}/lock" \ + -d '{"lock_uuid":"luck","duration":{"d_ms": 100000},"quantity":1}' \ + -w "%{http_code}" -s -o $LAST_RESPONSE) + +if [ "$STATUS" != "204" ] +then + echo 'should respond ok, lock created. got:' $STATUS `cat $LAST_RESPONSE` + exit 1 +fi + +echo " OK" + + echo -n "Creating order to be paid..." -MANAGED_PRODUCT_ID=$(echo $MANAGED_PRODUCT_TEMPLATE | jq -r '.product_id') STATUS=$(curl 'http://localhost:9966/instances/default/private/orders' \ - -d '{"order":{"amount":"TESTKUDOS:1","summary":"payme"},"inventory_products":[{"product_id":"'$MANAGED_PRODUCT_ID'","quantity":1}]}' \ + -d '{"order":{"amount":"TESTKUDOS:1","summary":"payme"},"inventory_products":[{"product_id":"'${MANAGED_PRODUCT_ID}'","quantity":1}]}' \ -w "%{http_code}" -s -o $LAST_RESPONSE) if [ "$STATUS" != "200" ] then - echo 'should response ok, order created. got:' $STATUS `cat $LAST_RESPONSE` + echo 'should respond ok, order created. got:' $STATUS `cat $LAST_RESPONSE` exit 1 fi @@ -110,13 +137,38 @@ STATUS=$(curl "http://localhost:9966/instances/default/private/orders/${ORDER_ID if [ "$STATUS" != "200" ] then - echo 'should response ok, getting order info before claming it. got:' $STATUS `cat $LAST_RESPONSE` + echo 'should respond ok, getting order info before claming it. got:' $STATUS `cat $LAST_RESPONSE` exit 1 fi - PAY_URL=`jq -e -r .taler_pay_uri < $LAST_RESPONSE` -echo OK +echo -n "." + +STATUS=$(curl 'http://localhost:9966/instances/default/private/orders' \ + -d '{"order":{"amount":"TESTKUDOS:1","summary":"payme"},"inventory_products":[{"product_id":"'${MANAGED_PRODUCT_ID}'","quantity":1}]}' \ + -w "%{http_code}" -s -o $LAST_RESPONSE) + +if [ "$STATUS" != "410" ] +then + echo 'should respond out of stock (what remains is locked). got:' $STATUS `cat $LAST_RESPONSE` + exit 1 +fi + +echo -n "." + +# Using the 'luck' inventory lock, order creation should work. +STATUS=$(curl 'http://localhost:9966/instances/default/private/orders' \ + -d '{"order":{"amount":"TESTKUDOS:1","summary":"payme"},"lock_uuids":["luck"],"inventory_products":[{"product_id":"'$MANAGED_PRODUCT_ID'","quantity":1}]}' \ + -w "%{http_code}" -s -o $LAST_RESPONSE) + +if [ "$STATUS" != "200" ] +then + echo 'should respond ok, lock should apply. got:' $STATUS `cat $LAST_RESPONSE` + exit 1 +fi + + +echo " OK" echo -n "First withdraw wallet" rm $WALLET_DB @@ -146,7 +198,7 @@ STATUS=$(curl "http://localhost:9966/instances/default/private/orders/${ORDER_ID if [ "$STATUS" != "200" ] then - echo 'should response ok, after pay. got:' $STATUS `cat $LAST_RESPONSE` + echo 'should respond ok, after pay. got:' $STATUS `cat $LAST_RESPONSE` exit 1 fi diff --git a/src/testing/testing_api_cmd_lock_product.c b/src/testing/testing_api_cmd_lock_product.c index abb5920c..49f815d6 100644 --- a/src/testing/testing_api_cmd_lock_product.c +++ b/src/testing/testing_api_cmd_lock_product.c @@ -57,7 +57,7 @@ struct LockProductState /** * UUID that identifies the client holding the lock */ - struct GNUNET_Uuid uuid; + char *uuid; /** * duration how long should the lock be held @@ -138,7 +138,7 @@ lock_product_run (void *cls, pis->iph = TALER_MERCHANT_product_lock (is->ctx, pis->merchant_url, pis->product_id, - &pis->uuid, + pis->uuid, pis->duration, pis->quantity, &lock_product_cb, @@ -166,6 +166,7 @@ lock_product_cleanup (void *cls, "POST /product/$ID/lock operation did not complete\n"); TALER_MERCHANT_product_lock_cancel (pis->iph); } + GNUNET_free (pis->uuid); GNUNET_free (pis); } @@ -188,7 +189,7 @@ lock_product_traits (void *cls, struct LockProductState *lps = cls; struct TALER_TESTING_Trait traits[] = { - TALER_TESTING_make_trait_uuid (0, &lps->uuid), + TALER_TESTING_make_trait_string (0, lps->uuid), TALER_TESTING_trait_end () }; @@ -209,14 +210,17 @@ TALER_TESTING_cmd_merchant_lock_product ( unsigned int http_status) { struct LockProductState *pis; + struct GNUNET_Uuid uuid; pis = GNUNET_new (struct LockProductState); pis->merchant_url = merchant_url; pis->product_id = product_id; pis->http_status = http_status; GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, - &pis->uuid, + &uuid, sizeof (struct GNUNET_Uuid)); + pis->uuid = GNUNET_STRINGS_data_to_string_alloc (&uuid, + sizeof (uuid)); pis->duration = duration; pis->quantity = quantity; diff --git a/src/testing/testing_api_cmd_post_orders.c b/src/testing/testing_api_cmd_post_orders.c index 5b9e533f..f7c00388 100644 --- a/src/testing/testing_api_cmd_post_orders.c +++ b/src/testing/testing_api_cmd_post_orders.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2018 Taler Systems SA + Copyright (C) 2014-2021 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -439,7 +439,7 @@ orders_run2 (void *cls, char *token; struct TALER_MERCHANT_InventoryProduct *products = NULL; unsigned int products_length = 0; - struct GNUNET_Uuid *locks = NULL; + const char **locks = NULL; unsigned int locks_length = 0; ps->is = is; @@ -527,16 +527,16 @@ orders_run2 (void *cls, token = strtok (NULL, ";")) { const struct TALER_TESTING_Command *lock_cmd; - struct GNUNET_Uuid *uuid; + const char *uuid; lock_cmd = TALER_TESTING_interpreter_lookup_command ( is, token); if (GNUNET_OK != - TALER_TESTING_get_trait_uuid (lock_cmd, - 0, - &uuid)) + TALER_TESTING_get_trait_string (lock_cmd, + 0, + &uuid)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not fetch lock uuid\n"); @@ -546,7 +546,7 @@ orders_run2 (void *cls, GNUNET_array_append (locks, locks_length, - *uuid); + uuid); } ps->po = TALER_MERCHANT_orders_post2 (is->ctx, ps->merchant_url, |