diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-12-29 14:47:17 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-12-29 14:47:17 +0100 |
commit | 2c19f6a6fb180f059fcaeb193dd387c4d6af21b1 (patch) | |
tree | d7fdd874e84950510f5a7a698007023ed46d80ea /src/lib | |
parent | 689bbc7a201067815cb0975703422854099d19ba (diff) | |
download | merchant-2c19f6a6fb180f059fcaeb193dd387c4d6af21b1.tar.gz merchant-2c19f6a6fb180f059fcaeb193dd387c4d6af21b1.tar.bz2 merchant-2c19f6a6fb180f059fcaeb193dd387c4d6af21b1.zip |
-towards fixing the template tests
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/merchant_api_get_template.c | 12 | ||||
-rw-r--r-- | src/lib/merchant_api_post_orders.c | 4 | ||||
-rw-r--r-- | src/lib/merchant_api_post_templates.c | 54 | ||||
-rw-r--r-- | src/lib/merchant_api_post_using_templates.c | 12 |
4 files changed, 69 insertions, 13 deletions
diff --git a/src/lib/merchant_api_get_template.c b/src/lib/merchant_api_get_template.c index 23c35d8b..bced4097 100644 --- a/src/lib/merchant_api_get_template.c +++ b/src/lib/merchant_api_get_template.c @@ -74,8 +74,8 @@ struct TALER_MERCHANT_TemplateGetHandle */ static void handle_get_template_finished (void *cls, - long response_code, - const void *response) + long response_code, + const void *response) { struct TALER_MERCHANT_TemplateGetHandle *tgh = cls; const json_t *json = response; @@ -93,14 +93,16 @@ handle_get_template_finished (void *cls, case MHD_HTTP_OK: { const char *template_description; - const char *image; + const char *image = NULL; json_t *template_contract; bool rst_ok = true; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_string ("template_description", &template_description), - GNUNET_JSON_spec_string ("image", - &image), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_string ("image", + &image), + NULL), GNUNET_JSON_spec_json ("template_contract", &template_contract), GNUNET_JSON_spec_end () diff --git a/src/lib/merchant_api_post_orders.c b/src/lib/merchant_api_post_orders.c index c4ccea36..bb11f31c 100644 --- a/src/lib/merchant_api_post_orders.c +++ b/src/lib/merchant_api_post_orders.c @@ -95,6 +95,8 @@ handle_post_order_finished (void *cls, struct TALER_ClaimTokenP token; po->job = NULL; + // to_be_written_new_function (po->cb, po->cb_cls, response_code, json); + // roughly from here switch (response_code) { case 0: @@ -214,6 +216,8 @@ handle_post_order_finished (void *cls, } po->cb (po->cb_cls, &por); + // end of new function + TALER_MERCHANT_orders_post_cancel (po); } diff --git a/src/lib/merchant_api_post_templates.c b/src/lib/merchant_api_post_templates.c index 300039a4..eb6c0d20 100644 --- a/src/lib/merchant_api_post_templates.c +++ b/src/lib/merchant_api_post_templates.c @@ -81,8 +81,8 @@ struct TALER_MERCHANT_TemplatesPostHandle */ static void handle_post_templates_finished (void *cls, - long response_code, - const void *response) + long response_code, + const void *response) { struct TALER_MERCHANT_TemplatesPostHandle *tph = cls; const json_t *json = response; @@ -152,6 +152,46 @@ handle_post_templates_finished (void *cls, } +static bool +test_template_contract_valid (const json_t *template_contract) +{ + const char *summary; + struct TALER_Amount amount = { .value = 0}; + uint32_t minimum_age = 0; + struct GNUNET_TIME_Relative pay_duration = { 0 }; + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_string ("summary", + &summary), + NULL), + GNUNET_JSON_spec_mark_optional ( + TALER_JSON_spec_amount_any ("amount", + &amount), + NULL), + GNUNET_JSON_spec_uint32 ("minimum_age", + &minimum_age), + GNUNET_JSON_spec_relative_time ("pay_duration", + &pay_duration), + GNUNET_JSON_spec_end () + }; + const char *ename; + unsigned int eline; + + if (GNUNET_OK != + GNUNET_JSON_parse (template_contract, + spec, + &ename, + &eline)) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Invalid template_contract for field %s\n", + ename); + return false; + } + return true; +} + + struct TALER_MERCHANT_TemplatesPostHandle * TALER_MERCHANT_templates_post ( struct GNUNET_CURL_Context *ctx, @@ -166,13 +206,19 @@ TALER_MERCHANT_templates_post ( struct TALER_MERCHANT_TemplatesPostHandle *tph; json_t *req_obj; + if (! test_template_contract_valid (template_contract)) + { + GNUNET_break (0); + return NULL; + } req_obj = GNUNET_JSON_PACK ( GNUNET_JSON_pack_string ("template_id", template_id), GNUNET_JSON_pack_string ("template_description", template_description), - GNUNET_JSON_pack_string ("image", - image), + GNUNET_JSON_pack_allow_null ( + GNUNET_JSON_pack_string ("image", + image)), GNUNET_JSON_pack_object_incref ("template_contract", (json_t *) template_contract)); tph = GNUNET_new (struct TALER_MERCHANT_TemplatesPostHandle); diff --git a/src/lib/merchant_api_post_using_templates.c b/src/lib/merchant_api_post_using_templates.c index 1985fba1..ded88e75 100644 --- a/src/lib/merchant_api_post_using_templates.c +++ b/src/lib/merchant_api_post_using_templates.c @@ -91,6 +91,8 @@ handle_post_using_templates_finished (void *cls, }; utph->job = NULL; + // to_be_written_new_function (utph->cb, utph->cb_cls, response_code, json); + // start of code to be removed GNUNET_log (GNUNET_ERROR_TYPE_INFO, "POST /using-templates completed with response code %u\n", (unsigned int) response_code); @@ -150,6 +152,8 @@ handle_post_using_templates_finished (void *cls, } /* end of the switch */ utph->cb (utph->cb_cls, &hr); + // end of code to be removed + TALER_MERCHANT_using_templates_post_cancel (utph); } @@ -207,10 +211,10 @@ TALER_MERCHANT_using_templates_post ( req_obj)); json_decref (req_obj); utph->job = GNUNET_CURL_job_add2 (ctx, - eh, - utph->post_ctx.headers, - &handle_post_using_templates_finished, - utph); + eh, + utph->post_ctx.headers, + &handle_post_using_templates_finished, + utph); GNUNET_assert (NULL != utph->job); } return utph; |