From 6737ee287534892ead4bfa6cea599886705b7afa Mon Sep 17 00:00:00 2001 From: Jonathan Buchanan Date: Thu, 9 Jul 2020 15:47:45 -0400 Subject: test post orders with products and lock uuids --- src/testing/test_merchant_api.c | 29 +++++++- src/testing/testing_api_cmd_lock_product.c | 32 ++++++++- src/testing/testing_api_cmd_post_orders.c | 103 +++++++++++++++++++++++++++-- 3 files changed, 156 insertions(+), 8 deletions(-) (limited to 'src/testing') diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c index 10a378e8..33de86ed 100644 --- a/src/testing/test_merchant_api.c +++ b/src/testing/test_merchant_api.c @@ -310,6 +310,12 @@ run (void *cls, "a product", "EUR:1", MHD_HTTP_NO_CONTENT), + TALER_TESTING_cmd_merchant_lock_product ("lock-product-p3", + merchant_url, + "product-3", + GNUNET_TIME_UNIT_MINUTES, + 2, + MHD_HTTP_NO_CONTENT), TALER_TESTING_cmd_merchant_post_orders2 ("create-proposal-p3-wm-nx", merchant_url, MHD_HTTP_NOT_FOUND, @@ -322,7 +328,24 @@ run (void *cls, \"fulfillment_url\": \"https://example.com/\",\ \"products\": [ {\"description\":\"ice cream\",\ \"value\":\"{EUR:5}\"} ] }", - "unsupported-wire-method"), + "unsupported-wire-method", + "product-3/2", + ""), + TALER_TESTING_cmd_merchant_post_orders2 ("create-proposal-p3-pd-nx", + merchant_url, + MHD_HTTP_NOT_FOUND, + "{\"max_fee\":\"EUR:0.5\",\ + \"order_id\":\"order-p3\",\ + \"refund_deadline\": {\"t_ms\": 0},\ + \"pay_deadline\": {\"t_ms\": \"never\" },\ + \"amount\":\"EUR:5.0\",\ + \"summary\": \"merchant-lib testcase\",\ + \"fulfillment_url\": \"https://example.com/\",\ + \"products\": [ {\"description\":\"ice cream\",\ + \"value\":\"{EUR:5}\"} ] }", + "x-taler-bank", + "unknown-product/2", + ""), TALER_TESTING_cmd_merchant_post_orders2 ("create-proposal-p3", merchant_url, MHD_HTTP_OK, @@ -335,7 +358,9 @@ run (void *cls, \"fulfillment_url\": \"https://example.com/\",\ \"products\": [ {\"description\":\"ice cream\",\ \"value\":\"{EUR:5}\"} ] }", - "x-taler-bank"), + "x-taler-bank", + "product-3/3", + "lock-product-p3"), TALER_TESTING_cmd_merchant_delete_order ("delete-order-1", merchant_url, "1", diff --git a/src/testing/testing_api_cmd_lock_product.c b/src/testing/testing_api_cmd_lock_product.c index 0389e9c0..4a05e823 100644 --- a/src/testing/testing_api_cmd_lock_product.c +++ b/src/testing/testing_api_cmd_lock_product.c @@ -163,6 +163,35 @@ lock_product_cleanup (void *cls, } +/** + * Offer internal data to other commands. + * + * @param cls closure + * @param ret[out] result (could be anything) + * @param trait name of the trait + * @param index index number of the object to extract. + * @return #GNUNET_OK on success + */ +static int +lock_product_traits (void *cls, + const void **ret, + const char *trait, + unsigned int index) +{ + struct LockProductState *lps = cls; + + struct TALER_TESTING_Trait traits[] = { + TALER_TESTING_make_trait_uuid (0, &lps->uuid), + TALER_TESTING_trait_end () + }; + + return TALER_TESTING_get_trait (traits, + ret, + trait, + index); +} + + /** * Define a "LOCK /products/$ID" CMD. * @@ -201,7 +230,8 @@ TALER_TESTING_cmd_merchant_lock_product ( .cls = pis, .label = label, .run = &lock_product_run, - .cleanup = &lock_product_cleanup + .cleanup = &lock_product_cleanup, + .traits = &lock_product_traits }; return cmd; diff --git a/src/testing/testing_api_cmd_post_orders.c b/src/testing/testing_api_cmd_post_orders.c index 243dbca3..0e4f47af 100644 --- a/src/testing/testing_api_cmd_post_orders.c +++ b/src/testing/testing_api_cmd_post_orders.c @@ -101,6 +101,16 @@ struct OrdersState * The payment target for the order */ const char *payment_target; + + /** + * The products the order is purchasing. + */ + const char *products; + + /** + * The locks that the order should release. + */ + const char *locks; }; @@ -340,6 +350,15 @@ orders_run2 (void *cls, json_t *order; json_error_t error; + char *products_string = GNUNET_strdup (ps->products); + char *locks_string = GNUNET_strdup (ps->locks); + char *token; + + struct TALER_MERCHANT_InventoryProduct *products = NULL; + unsigned int products_length = 0; + struct GNUNET_Uuid *locks = NULL; + unsigned int locks_length = 0; + ps->is = is; order = json_loads (ps->order, JSON_REJECT_DUPLICATES, @@ -372,18 +391,83 @@ orders_run2 (void *cls, GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, &ps->nonce, sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); + for (token = strtok (products_string, ";"); + NULL != token; + token = strtok (NULL, ";")) + { + char *ctok; + struct TALER_MERCHANT_InventoryProduct pd; + + /* Token syntax is "[product_id]/[quantity]" */ + ctok = strchr (token, '/'); + if (NULL != ctok) + { + *ctok = '\0'; + ctok++; + if (1 != sscanf (ctok, + "%u", + &pd.quantity)) + { + GNUNET_break (0); + break; + } + } + else + { + pd.quantity = 1; + } + pd.product_id = token; + + GNUNET_array_append (products, + products_length, + pd); + } + for (token = strtok (locks_string, ";"); + NULL != token; + token = strtok (NULL, ";")) + { + const struct TALER_TESTING_Command *lock_cmd; + struct GNUNET_Uuid *uuid; + + lock_cmd = TALER_TESTING_interpreter_lookup_command ( + is, + token); + + if (GNUNET_OK != + TALER_TESTING_get_trait_uuid (lock_cmd, + 0, + &uuid)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not fetch lock uuid\n"); + TALER_TESTING_interpreter_fail (is); + return; + } + + GNUNET_array_append (locks, + locks_length, + *uuid); + } ps->po = TALER_MERCHANT_orders_post2 (is->ctx, ps->merchant_url, order, GNUNET_TIME_UNIT_ZERO, ps->payment_target, - 0, - NULL, - 0, - NULL, + products_length, + products, + locks_length, + locks, &order_cb, ps); json_decref (order); + GNUNET_free (products_string); + GNUNET_free (locks_string); + GNUNET_array_grow (products, + products_length, + 0); + GNUNET_array_grow (locks, + locks_length, + 0); GNUNET_assert (NULL != ps->po); } @@ -472,6 +556,11 @@ TALER_TESTING_cmd_merchant_post_orders (const char *label, * @param http_status expected HTTP status. * @param order the order to PUT to the merchant. * @param payment_target payment target for the order. + * @param products a string indicating the products this order will be + * purchasing. Should be formatted as + * "[product_id]/[quantity];...". + * @param locks a string of references to lock product commands that should + * be formatted as "[lock_1];[lock_2];...". * @return the command */ struct TALER_TESTING_Command @@ -479,7 +568,9 @@ TALER_TESTING_cmd_merchant_post_orders2 (const char *label, const char *merchant_url, unsigned int http_status, const char *order, - const char *payment_target) + const char *payment_target, + const char *products, + const char *locks) { struct OrdersState *ps; @@ -488,6 +579,8 @@ TALER_TESTING_cmd_merchant_post_orders2 (const char *label, ps->http_status = http_status; ps->merchant_url = merchant_url; ps->payment_target = payment_target; + ps->products = products; + ps->locks = locks; { struct TALER_TESTING_Command cmd = { .cls = ps, -- cgit v1.2.3