diff options
author | priscilla <priscilla.huang@efrei.net> | 2022-12-29 07:14:09 -0500 |
---|---|---|
committer | priscilla <priscilla.huang@efrei.net> | 2022-12-29 07:14:34 -0500 |
commit | 689bbc7a201067815cb0975703422854099d19ba (patch) | |
tree | d00d3bc13681f299fc28c9d9bcf595484b36c05d /src | |
parent | 99db83bca3b5dbe1399a642eb4192546bbfd24df (diff) |
using templates testing
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/taler-merchant-httpd.c | 10 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_post-using-templates.c | 3 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_post-using-templates.h | 5 | ||||
-rw-r--r-- | src/backenddb/Makefile.am | 2 | ||||
-rw-r--r-- | src/backenddb/merchant-0004.sql | 24 | ||||
-rw-r--r-- | src/include/taler_merchant_service.h | 1 | ||||
-rw-r--r-- | src/include/taler_merchant_testing_lib.h | 46 | ||||
-rw-r--r-- | src/lib/merchant_api_post_using_templates.c | 15 | ||||
-rw-r--r-- | src/testing/Makefile.am | 1 | ||||
-rw-r--r-- | src/testing/test_merchant_api.c | 26 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_post_using_templates.c | 117 | ||||
-rw-r--r-- | src/testing/testing_api_helpers.c | 1 |
12 files changed, 226 insertions, 25 deletions
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c index 01a515b3..9366c1bf 100644 --- a/src/backend/taler-merchant-httpd.c +++ b/src/backend/taler-merchant-httpd.c @@ -77,6 +77,7 @@ #include "taler-merchant-httpd_post-orders-ID-claim.h" #include "taler-merchant-httpd_post-orders-ID-paid.h" #include "taler-merchant-httpd_post-orders-ID-pay.h" +#include "taler-merchant-httpd_post-using-templates.h" #include "taler-merchant-httpd_post-orders-ID-refund.h" #include "taler-merchant-httpd_post-tips-ID-pickup.h" #include "taler-merchant-httpd_reserves.h" @@ -1149,6 +1150,15 @@ url_handler (void *cls, .have_id_segment = true, .handler = &TMH_return_static }, + /* POST /templates/$ID: */ + { + .url_prefix = "/templates/", + .method = MHD_HTTP_METHOD_POST, + .have_id_segment = true, + .allow_deleted_instance = true, + .handler = &TMH_post_using_templates_ID, + .max_upload = 1024 * 1024 + }, { .url_prefix = "*", .method = MHD_HTTP_METHOD_OPTIONS, diff --git a/src/backend/taler-merchant-httpd_post-using-templates.c b/src/backend/taler-merchant-httpd_post-using-templates.c index 239549c0..75f489dd 100644 --- a/src/backend/taler-merchant-httpd_post-using-templates.c +++ b/src/backend/taler-merchant-httpd_post-using-templates.c @@ -35,7 +35,8 @@ MHD_RESULT -TMH_post_using_templates_ID (struct MHD_Connection *connection, +TMH_post_using_templates_ID (const struct TMH_RequestHandler *rh, + struct MHD_Connection *connection, struct TMH_HandlerContext *hc) { struct TMH_MerchantInstance *mi = hc->instance; diff --git a/src/backend/taler-merchant-httpd_post-using-templates.h b/src/backend/taler-merchant-httpd_post-using-templates.h index 57ca6aa8..7d875bc6 100644 --- a/src/backend/taler-merchant-httpd_post-using-templates.h +++ b/src/backend/taler-merchant-httpd_post-using-templates.h @@ -31,8 +31,9 @@ * @return MHD result code */ MHD_RESULT -TMH_post_using_templates_ID (struct MHD_Connection *connection, - struct TMH_HandlerContext *hc); +TMH_post_using_templates_ID (const struct TMH_RequestHandler *rh, + struct MHD_Connection *connection, + struct TMH_HandlerContext *hc); #endif diff --git a/src/backenddb/Makefile.am b/src/backenddb/Makefile.am index a8fefb40..f35cc4d9 100644 --- a/src/backenddb/Makefile.am +++ b/src/backenddb/Makefile.am @@ -43,7 +43,7 @@ libtalermerchantdb_la_LIBADD = \ -ltalerpq \ -lgnunetutil \ -lltdl \ - $(XLIB) + $(XLIB) libtalermerchantdb_la_LDFLAGS = \ $(POSTGRESQL_LDFLAGS) \ diff --git a/src/backenddb/merchant-0004.sql b/src/backenddb/merchant-0004.sql index 26440816..cd7ecece 100644 --- a/src/backenddb/merchant-0004.sql +++ b/src/backenddb/merchant-0004.sql @@ -47,6 +47,21 @@ COMMENT ON COLUMN merchant_template.image COMMENT ON COLUMN merchant_template.template_contract IS 'The template contract will contains some additional information.'; +/* +CREATE TABLE IF NOT EXISTS merchant_using_template + (template_serial BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY + ,merchant_serial BIGINT NOT NULL + REFERENCES merchant_instances (nerchant_serial) ON DELETE CASCADE + ,summary VERCHAR NOT + ,amount_val INT8 NOT NULL + ,amount_frac INT4 NOT NULL + ,UNIQUE (merchant_serial, template_id) + COMMENT ON TABLE merchant_using_template + IS 'template used by the curstomer (may be incomplete, frontend can override)'; + COMMENT ON COLUMN merchant_usign_template.summary + IS 'Human-readable summary'; +COMMENT ON COLUMN merchant_using_template.amount_val + IS 'Overall amoount that need to pay';*/ CREATE TABLE IF NOT EXISTS merchant_webhook (webhook_serial BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY @@ -73,7 +88,7 @@ COMMENT ON COLUMN merchant_webhook.header_template COMMENT ON COLUMN merchant_webhook.body_template IS 'Template for the body of the webhook, to be modified based on trigger data'; - +/* CREATE TABLE IF NOT EXISTS merchant_pending_webhooks (webhook_pending_serial BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY ,merchant_serial BIGINT NOT NULL @@ -92,7 +107,7 @@ COMMENT ON TABLE merchant_pending_webhooks IS 'webhooks that still need to be executed by the merchant'; COMMENT ON COLUMN merchant_pending_webhooks.url IS 'URL to make the request to'; -COMMENT ON COLUMN merchant_pending_webhooks.webhook_id +COMMENT ON COLUMN merchant_pending_webhooks.webhook_serial IS 'Reference to the configured webhook template'; COMMENT ON COLUMN merchant_pending_webhooks.retries IS 'How often have we tried this request so far'; @@ -100,10 +115,11 @@ COMMENT ON COLUMN merchant_pending_webhooks.next_attempt IS 'Time when we should make the next request to the webhook'; COMMENT ON COLUMN merchant_pending_webhooks.http_method IS 'http method use for the webhook'; -COMMENT ON COLUMN merchant_pending_webhooks.header_template +COMMENT ON COLUMN merchant_pending_webhooks.header IS 'Header of the webhook'; -COMMENT ON COLUMN merchant_pending_webhooks.body_template +COMMENT ON COLUMN merchant_pending_webhooks.body IS 'Body of the webhook'; +*/ COMMIT; diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h index f6cedcd4..a544380c 100644 --- a/src/include/taler_merchant_service.h +++ b/src/include/taler_merchant_service.h @@ -4396,6 +4396,7 @@ struct TALER_MERCHANT_UsingTemplatesPostHandle * TALER_MERCHANT_using_templates_post ( struct GNUNET_CURL_Context *ctx, const char *backend_url, + const char *template_id, const char *summary, const struct TALER_Amount *amount, TALER_MERCHANT_UsingTemplatesPostCallback cb, diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h index 8baad7a2..d820d1af 100644 --- a/src/include/taler_merchant_testing_lib.h +++ b/src/include/taler_merchant_testing_lib.h @@ -1490,7 +1490,6 @@ TALER_TESTING_cmd_merchant_kyc_get (const char *label, /* ****** Templates ******* */ - /** * Define a "POST /templates" CMD. * @@ -1534,6 +1533,7 @@ TALER_TESTING_cmd_merchant_post_templates (const char *label, unsigned int http_status); + /** * Define a "PATCH /templates/$ID" CMD. * @@ -1614,6 +1614,45 @@ TALER_TESTING_cmd_merchant_delete_template (const char *label, const char *template_id, unsigned int http_status); +/** + * Define a "POST /using-templates" CMD. + * + * @param label command label. + * @param merchant_url base URL of the merchant serving the + * POST /using-templates request. + * @param summary given by the customer to know what they did pay + * @param amount given by the customer to pay + * @param http_status expected HTTP response code. + * @return the command. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_merchant_post_using_templates2 ( + const char *label, + const char *merchant_url, + const char *summary, + const char *amount, + unsigned int http_status); + + +/** + * Define a "POST /using-templates" CMD, simple version + * + * @param label command label. + * @param merchant_url base URL of the merchant serving the + * POST /using-templates request. + * @param summary given by the customer to know what they did pay + * @param amount given by the customer to pay + * @param http_status expected HTTP response code. + * @return the command. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_merchant_post_using_templates (const char *label, + const char *merchant_url, + const char *summary, + const char *amount, + unsigned int http_status); + + /* ****** Webhooks ******* */ @@ -1750,6 +1789,8 @@ TALER_TESTING_cmd_merchant_delete_webhook (const char *label, + + /* ****** Specific traits supported by this component ******* */ @@ -1800,7 +1841,8 @@ TALER_TESTING_cmd_merchant_delete_webhook (const char *label, op (webhook_id, const char *) \ op (http_method, const char *) \ op (header_template, const char *) \ - op (body_template, const char *) + op (body_template, const char *) \ + op (summary, const char *) /** diff --git a/src/lib/merchant_api_post_using_templates.c b/src/lib/merchant_api_post_using_templates.c index 9a4aa93d..1985fba1 100644 --- a/src/lib/merchant_api_post_using_templates.c +++ b/src/lib/merchant_api_post_using_templates.c @@ -158,6 +158,7 @@ struct TALER_MERCHANT_UsingTemplatesPostHandle * TALER_MERCHANT_using_templates_post ( struct GNUNET_CURL_Context *ctx, const char *backend_url, + const char *template_id, const char *summary, const struct TALER_Amount *amount, TALER_MERCHANT_UsingTemplatesPostCallback cb, @@ -177,9 +178,17 @@ TALER_MERCHANT_using_templates_post ( utph->ctx = ctx; utph->cb = cb; utph->cb_cls = cb_cls; - utph->url = TALER_url_join (backend_url, - "/templates", - NULL); + { + char *path; + + GNUNET_asprintf (&path, + "templates/%s", + template_id); + utph->url = TALER_url_join (backend_url, + path, + NULL); + GNUNET_free (path); + } if (NULL == utph->url) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index af98f4e1..159b922e 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am @@ -63,6 +63,7 @@ libtalermerchanttesting_la_SOURCES = \ testing_api_cmd_post_reserves.c \ testing_api_cmd_post_transfers.c \ testing_api_cmd_post_templates.c \ + testing_api_cmd_post_using_templates.c \ testing_api_cmd_post_webhooks.c \ testing_api_cmd_patch_instance.c \ testing_api_cmd_patch_product.c \ diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c index f6fb28a3..a4a6dfd9 100644 --- a/src/testing/test_merchant_api.c +++ b/src/testing/test_merchant_api.c @@ -1441,6 +1441,30 @@ run (void *cls, TALER_TESTING_cmd_end () }; + struct TALER_TESTING_Command using_templates[] = { + TALER_TESTING_cmd_merchant_post_using_templates ("post-templates-t1", + merchant_url, + "template-1", + "EUR:10", + MHD_HTTP_NO_CONTENT), + TALER_TESTING_cmd_merchant_post_using_templates ("post-templates-t1-idem", + merchant_url, + "template-1", + "EUR:10", + MHD_HTTP_NO_CONTENT), + TALER_TESTING_cmd_merchant_post_using_templates ("post-templates-t1-non-idem", + merchant_url, + "template-1", + "EUR:5", + MHD_HTTP_CONFLICT), + TALER_TESTING_cmd_merchant_post_using_templates ("post-templates-t2", + merchant_url, + "template-2", + "EUR:10", + MHD_HTTP_NO_CONTENT), + TALER_TESTING_cmd_end () + }; + struct TALER_TESTING_Command commands[] = { /* general setup */ TALER_TESTING_cmd_auditor_add ("add-auditor-OK", @@ -1795,6 +1819,8 @@ run (void *cls, templates), TALER_TESTING_cmd_batch ("webhooks", webhooks), + TALER_TESTING_cmd_batch ("using_templates", + using_templates), /** * End the suite. */ diff --git a/src/testing/testing_api_cmd_post_using_templates.c b/src/testing/testing_api_cmd_post_using_templates.c index d286364c..6b97aa36 100644 --- a/src/testing/testing_api_cmd_post_using_templates.c +++ b/src/testing/testing_api_cmd_post_using_templates.c @@ -124,14 +124,59 @@ post_using_templates_run (void *cls, struct TALER_TESTING_Interpreter *is) { struct PostUsingTemplatesState *tis = cls; + const char *template_id; tis->is = is; - tis->iph = TALER_MERCHANT_templates_post (is->ctx, - tis->merchant_url, - tis->summary, - tis->amount, - &post_using_templates_cb, - tis); + + const json_t *contract_terms; + const char *error_name; + unsigned int error_line; + const char **proposal_reference; + + if (NULL== cmd) + TALER_TESTING_FAIL (is); + { + + if (GNUNET_OK != + TALER_TESTING_get_trait_contract_terms (cmd, + &contract_terms)) + TALER_TESTING_FAIL (is); + { + /* Get information that needs to be put verbatim in the + * deposit permission */ + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_string ("template_id", + &template_id), + GNUNET_JSON_spec_end () + }; + + if (GNUNET_OK != + GNUNET_JSON_parse (contract_terms, + spec, + &error_name, + &error_line)) + { + char *js; + js = json_dumps (contract_terms, + JSON_INDENT (1)); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Parser failed on %s:%u for input `%s'\n", + error_name, + error_line, + js); + free (js); + TALER_TESTING_FAIL (is); + } + } + } + + tis->iph = TALER_MERCHANT_using_templates_post (is->ctx, + tis->merchant_url, + template_id, + tis->summary, + &tis->amount, + &post_using_templates_cb, + tis); GNUNET_assert (NULL != tis->iph); } @@ -153,7 +198,7 @@ post_using_templates_traits (void *cls, { struct PostUsingTemplatesState *pts = cls; struct TALER_TESTING_Trait traits[] = { - TALER_TESTING_make_trait_sumamry (&pts->summary), + TALER_TESTING_make_trait_summary (&pts->summary), TALER_TESTING_make_trait_amount (&pts->amount), TALER_TESTING_trait_end (), }; @@ -176,15 +221,63 @@ static void post_using_templates_cleanup (void *cls, const struct TALER_TESTING_Command *cmd) { - struct PostTemplatesState *tis = cls; + struct PostUsingTemplatesState *tis = cls; if (NULL != tis->iph) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "POST /templates operation did not complete\n"); - TALER_MERCHANT_templates_post_cancel (tis->iph); + "POST /using-templates operation did not complete\n"); + TALER_MERCHANT_using_templates_post_cancel (tis->iph); } - GNUNET_free (tis->image); - json_decref (tis->template_contract); GNUNET_free (tis); } + + +struct TALER_TESTING_Command +TALER_TESTING_cmd_merchant_post_using_templates2 ( + const char *label, + const char *merchant_url, + const char *summary, + const char *amount, + unsigned int http_status) +{ + struct PostUsingTemplatesState *tis; + + tis = GNUNET_new (struct PostUsingTemplatesState); + tis->merchant_url = merchant_url; + tis->http_status = http_status; + tis->summary = summary; + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount (amount, + &tis->amount)); + + { + struct TALER_TESTING_Command cmd = { + .cls = tis, + .label = label, + .run = &post_using_templates_run, + .cleanup = &post_using_templates_cleanup, + .traits = &post_using_templates_traits + }; + + return cmd; + } +} + +struct TALER_TESTING_Command +TALER_TESTING_cmd_merchant_post_using_templates (const char *label, + const char *merchant_url, + const char *summary, + const char *amount, + unsigned int http_status) +{ + return TALER_TESTING_cmd_merchant_post_using_templates2 ( + label, + merchant_url, + summary, + amount, + http_status); +} + + +/* end of testing_api_cmd_post_using_templates.c */ diff --git a/src/testing/testing_api_helpers.c b/src/testing/testing_api_helpers.c index 659bb694..ea7f2dea 100644 --- a/src/testing/testing_api_helpers.c +++ b/src/testing/testing_api_helpers.c @@ -1,3 +1,4 @@ + /* This file is part of TALER Copyright (C) 2014-2018 Taler Systems SA |