diff options
author | priscilla <priscilla.huang@efrei.net> | 2023-02-13 09:07:16 -0500 |
---|---|---|
committer | priscilla <priscilla.huang@efrei.net> | 2023-02-13 09:07:36 -0500 |
commit | 98dfff89fd22c616813bb8c82d62553dd8a26d5d (patch) | |
tree | 0536e866d68e7b71281943cbc57ae04ef528f7bc /src | |
parent | 5f1f5fc8ff2db2c5a7b4b96c9b22bbd666448f06 (diff) | |
download | merchant-98dfff89fd22c616813bb8c82d62553dd8a26d5d.tar.gz merchant-98dfff89fd22c616813bb8c82d62553dd8a26d5d.tar.bz2 merchant-98dfff89fd22c616813bb8c82d62553dd8a26d5d.zip |
stashing my changes for pull
Diffstat (limited to 'src')
-rw-r--r-- | src/include/taler_merchant_testing_lib.h | 16 | ||||
-rw-r--r-- | src/testing/Makefile.am | 2 | ||||
-rw-r--r-- | src/testing/test_merchant_api.c | 9 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_post_webhooks.c | 6 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_testserver.c | 175 |
5 files changed, 89 insertions, 119 deletions
diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h index 9ac15909..771def10 100644 --- a/src/include/taler_merchant_testing_lib.h +++ b/src/include/taler_merchant_testing_lib.h @@ -1793,6 +1793,8 @@ TALER_TESTING_cmd_testserver (const char *label, * This function is used to check the web server * * @param label command label + * @param ref_operation reference to command to the previous set server status operation. + * @param index index to know which web server we check. * @param url of the webhook * @param http_method of the webhook * @param header of the webhook @@ -1801,12 +1803,8 @@ TALER_TESTING_cmd_testserver (const char *label, */ struct TALER_TESTING_Command TALER_TESTING_cmd_checkserver (const char *label, - char *url, - char *http_method, - char *header, - char *body, - uint16_t port); - + const char *ref_operation, + unsigned int index); /* ****** Specific traits supported by this component ******* */ @@ -1854,8 +1852,8 @@ TALER_TESTING_cmd_checkserver (const char *label, op (template_id, const char *) \ op (template_contract, const json_t) \ op (event_type, const char *) \ - op (url, const char *) \ op (webhook_id, const char *) \ + op (url, const char *) \ op (http_method, const char *) \ op (header_template, const char *) \ op (body_template, const char *) \ @@ -1872,6 +1870,10 @@ TALER_TESTING_cmd_checkserver (const char *label, op (paths, const char *) \ op (payto_uris, const char *) \ op (amounts, const struct TALER_Amount) \ + op (urls, char *) \ + op (http_methods, char *) \ + op (http_header, char *) \ + op (http_body, void *) \ op (planchet_secrets, const struct TALER_PlanchetMasterSecretP) diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index 74a818b7..7caaa7ea 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am @@ -70,7 +70,6 @@ libtalermerchanttesting_la_SOURCES = \ testing_api_cmd_patch_template.c \ testing_api_cmd_patch_webhook.c \ testing_api_cmd_refund_order.c \ - \ testing_api_cmd_tip_authorize.c \ testing_api_cmd_tip_pickup.c \ testing_api_cmd_wallet_get_order.c \ @@ -78,6 +77,7 @@ libtalermerchanttesting_la_SOURCES = \ testing_api_cmd_wallet_post_orders_refund.c \ testing_api_cmd_webhook.c \ testing_api_cmd_testserver.c \ + testing_api_cmd_checkserver.c \ testing_api_helpers.c \ testing_api_traits.c diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c index 1d8a4d96..7200e86b 100644 --- a/src/testing/test_merchant_api.c +++ b/src/testing/test_merchant_api.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2022 Taler Systems SA + Copyright (C) 2014-2023 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 @@ -438,11 +438,8 @@ run (void *cls, /* Check webhook did anything: have a command that inspects traits of the testserver and check if the traits have the right values set! */ TALER_TESTING_cmd_checkserver ("check-http-server-for-webhooks", - "http://localhost:12345/", - "POST", - "Authorization: EFEHYJS", - "5.0 EUR", - 12345), + "launch-http-server-for-webhooks", + 0), /* Here we expect to run into a timeout, as we do not pay this one */ TALER_TESTING_cmd_wallet_poll_order_conclude2 ("poll-order-1x-conclude", MHD_HTTP_PAYMENT_REQUIRED, diff --git a/src/testing/testing_api_cmd_post_webhooks.c b/src/testing/testing_api_cmd_post_webhooks.c index 2a16a990..099ea755 100644 --- a/src/testing/testing_api_cmd_post_webhooks.c +++ b/src/testing/testing_api_cmd_post_webhooks.c @@ -268,10 +268,10 @@ TALER_TESTING_cmd_merchant_post_webhooks (const char *label, merchant_url, webhook_id, event_type, - "http://localhost:12345/", + "https://google.com/", "POST", - "Authorization: EFEHYJS", - "{{amount.val}}.{{amount.frac}} {{amount.currency}}", + "Taler-test-header: EFEHYJS-Bakery", + "5.0 EUR", http_status); } diff --git a/src/testing/testing_api_cmd_testserver.c b/src/testing/testing_api_cmd_testserver.c index 77f0e692..7992c6f1 100644 --- a/src/testing/testing_api_cmd_testserver.c +++ b/src/testing/testing_api_cmd_testserver.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2021 Taler Systems SA + Copyright (C) 2023 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 @@ -47,57 +47,43 @@ struct TestserverState */ uint16_t port; - // FIXME: record URL, HTTP method, HTTP headers, HTTP body here! + struct RequestCtx **rcs; + + unsigned int rcs_length; +}; + + +struct RequestCtx +{ /** * URL where we are redirect. */ - const char *url; + char *url; /** * http method of the webhook. */ - const char *http_method; + char *http_method; /** * header of the webhook. */ - const char *header; + char *header; /** * body of the webhook. */ - const char *body; - // => expose as trait -}; + void *body; + /** + * size of the body + */ + size_t body_size; -struct RequestCtx -{ - struct MHD_PostProcessor *pp; + bool done; }; -static MHD_RESULT -handle_post (void *cls, - enum MHD_ValueKind kind, - const char *key, - const char *filename, - const char *content_type, - const char *transfer_encoding, - const char *data, - uint64_t off, - size_t size) -{ - (void) kind; - (void) filename; - (void) content_type; - (void) transfer_encoding; - (void) off; - - return MHD_YES; -} - - /** * A client has requested the given url using the given method * (#MHD_HTTP_METHOD_GET, #MHD_HTTP_METHOD_PUT, @@ -148,11 +134,31 @@ handler_cb (void *cls, size_t *upload_data_size, void **con_cls) { + struct TestserverState *ts = cls; struct RequestCtx *rc = *con_cls; json_t *body; - (void) cls; (void) version; + if (NULL == rc) + { + const char *hdr; + rc= GNUNET_new (struct RequestCtx); + *con_cls = rc; + rc->http_method = GNUNET_strdup (method); + hdr = MHD_lookup_connection_value (connection, + MHD_HEADER_KIND, + "Taler-test-header"); + if (NULL != hdr) + rc->header = GNUNET_strdup (hdr); + GNUNET_array_append (ts->rcs, + ts->rcs_length, + rc); + fprintf (stderr, + "Webhook called server at %s with header %s\n", + url, + hdr); + return MHD_YES; + } if (0 == strcasecmp (method, MHD_HTTP_METHOD_GET)) { @@ -170,27 +176,12 @@ handler_cb (void *cls, GNUNET_break (0); return MHD_NO; } - if (NULL == rc) - { - rc = GNUNET_new (struct RequestCtx); - *con_cls = rc; - rc->pp = MHD_create_post_processor (connection, - 12345, - &handle_post, - rc); - return MHD_YES; - } if (0 != *upload_data_size) { - MHD_RESULT ret; - - ret = MHD_post_process (rc->pp, - upload_data, - *upload_data_size); + rc->body = &upload_data; *upload_data_size = 0; - return ret; + return MHD_YES; } - body = GNUNET_JSON_PACK ( GNUNET_JSON_pack_string ("something", "good")); @@ -213,7 +204,7 @@ cleanup (void *cls, (void) toe; if (NULL == rc) return; - GNUNET_free (rc); + rc->done = true; } @@ -262,6 +253,18 @@ testserver_cleanup (void *cls, struct TestserverState *ser = cls; (void) cmd; + for (unsigned int i=0;i<ser->rcs_length;i++) + { + struct RequestCtx *rc = ser->rcs[i]; + + GNUNET_free (rc->url); + GNUNET_free (rc->http_method); + GNUNET_free (rc->header); + GNUNET_free (rc); + } + GNUNET_array_grow (ser->rcs, + ser->rcs_length, + 0); if (NULL != ser->mhd) { MHD_stop_daemon (ser->mhd); @@ -278,73 +281,39 @@ traits_testserver (void *cls, unsigned int index) { struct TestserverState *ser = cls; - struct TALER_TESTING_Trait traits[] = { - TALER_TESTING_make_trait_url (&ser->url), - TALER_TESTING_make_trait_http_method (&ser->http_method), - TALER_TESTING_make_trait_header_template (&ser->header), - TALER_TESTING_make_trait_body_template (&ser->body), - TALER_TESTING_trait_end (), - }; - - return TALER_TESTING_get_trait (traits, - ret, - trait, - index); -} -/** - * This function is used to start the web server. - * - * @param label command label - * @param port is the port of the web server - */ -struct TALER_TESTING_Command -TALER_TESTING_cmd_testserver (const char *label, - uint16_t port) -{ - struct TestserverState *ser; + if (index >= ser->rcs_length) + return MHD_NO; - ser = GNUNET_new (struct TestserverState); - ser->port = port; { - struct TALER_TESTING_Command cmd = { - .cls = ser, - .label = label, - .run = &testserver_run, - .cleanup = &testserver_cleanup, - .traits = &traits_testserver + struct RequestCtx *rc = ser->rcs[index]; + struct TALER_TESTING_Trait traits[] = { + TALER_TESTING_make_trait_urls (index, &rc->url), + TALER_TESTING_make_trait_http_methods (index, &rc->http_method), + TALER_TESTING_make_trait_http_header (index, &rc->header), + TALER_TESTING_make_trait_http_body (index, &rc->body), + TALER_TESTING_trait_end (), }; - - return cmd; + return TALER_TESTING_get_trait (traits, + ret, + trait, + index); } } - /** - * This function is used to check the web server + * This function is used to start the web server. * * @param label command label - * @param url of the webhook - * @param http_method of the webhook - * @param header of the webhook - * @param body of the webhook * @param port is the port of the web server */ struct TALER_TESTING_Command -TALER_TESTING_cmd_checkserver (const char *label, - char *url, - char *http_method, - char *header, - char *body, - uint16_t port) +TALER_TESTING_cmd_testserver (const char *label, + uint16_t port) { struct TestserverState *ser; ser = GNUNET_new (struct TestserverState); - ser->url = url; - ser->http_method = http_method; - ser->header = header; - ser->body = body; ser->port = port; { struct TALER_TESTING_Command cmd = { @@ -352,6 +321,7 @@ TALER_TESTING_cmd_checkserver (const char *label, .label = label, .run = &testserver_run, .cleanup = &testserver_cleanup, + .traits = &traits_testserver }; return cmd; @@ -359,4 +329,5 @@ TALER_TESTING_cmd_checkserver (const char *label, } -/* end of testing_api_cmd_testserver.c */ +/* end of testing_api_cmd_checkserver.c */ + |