summaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-07-08 16:38:55 -0400
committerJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-07-08 16:38:55 -0400
commit071554a7ac031cc859355b5ee353a708c0c5cea5 (patch)
tree1a1474f59e0645669f56018abb9f3f487230247f /src/testing
parenta5e33f1a6d3f865a7c169783c63007cfdd3c30eb (diff)
downloadmerchant-071554a7ac031cc859355b5ee353a708c0c5cea5.tar.gz
merchant-071554a7ac031cc859355b5ee353a708c0c5cea5.tar.bz2
merchant-071554a7ac031cc859355b5ee353a708c0c5cea5.zip
removed more old code, more tests for post order, some twister tests for merchant-exchange requests
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/test_merchant_api.c140
-rw-r--r--src/testing/test_merchant_api_twisted.c46
-rw-r--r--src/testing/testing_api_cmd_post_orders.c108
3 files changed, 186 insertions, 108 deletions
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index ca4a4472..10a378e8 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -89,11 +89,6 @@ static char *merchant_url;
static struct GNUNET_OS_Process *merchantd;
/**
- * Map for #intern()
- */
-static struct GNUNET_CONTAINER_MultiHashMap *interned_strings;
-
-/**
* Account number of the exchange at the bank.
*/
#define EXCHANGE_ACCOUNT_NAME "2"
@@ -157,70 +152,6 @@ cmd_transfer_to_exchange (const char *label,
}
-static const char *
-intern (const char *str)
-{
- struct GNUNET_HashCode hash;
- const char *hs;
-
- if (NULL == interned_strings)
- interned_strings = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
- GNUNET_assert (NULL != interned_strings);
- GNUNET_CRYPTO_hash (str, strlen (str), &hash);
- hs = GNUNET_CONTAINER_multihashmap_get (interned_strings, &hash);
- if (NULL != hs)
- return hs;
- hs = GNUNET_strdup (str);
- GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (
- interned_strings,
- &hash,
- (void *) hs,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- return hs;
-}
-
-
-#define BUF_SZ 512
-
-static const char *
-merchant_url_internal (const char *instance_id)
-{
- char buf[BUF_SZ];
-
- if (NULL == instance_id)
- GNUNET_snprintf (buf,
- BUF_SZ,
- "%s",
- merchant_url);
- else
- GNUNET_snprintf (buf,
- BUF_SZ,
- "%sinstances/%s/",
- merchant_url,
- instance_id);
- return intern (buf);
-}
-
-
-static const char *
-merchant_url_external (const char *instance_id)
-{
- char buf[BUF_SZ];
- if (NULL == instance_id)
- GNUNET_snprintf (buf,
- BUF_SZ,
- "%spublic/",
- merchant_url);
- else
- GNUNET_snprintf (buf,
- BUF_SZ,
- "%spublic/instances/%s/",
- merchant_url,
- instance_id);
- return intern (buf);
-}
-
-
/**
* Main function that will tell the interpreter what commands to
* run.
@@ -310,31 +241,6 @@ run (void *cls,
false,
false,
MHD_HTTP_OK),
-#if 0
- TALER_TESTING_cmd_check_payment ("check-payment-1",
- merchant_url,
- MHD_HTTP_OK,
- "create-proposal-1",
- GNUNET_NO),
- TALER_TESTING_cmd_poll_payment_start ("poll-payment-1",
- merchant_url,
- "create-proposal-1",
- NULL,
- GNUNET_TIME_UNIT_MILLISECONDS),
- TALER_TESTING_cmd_poll_payment_conclude ("poll-payment-conclude-1",
- MHD_HTTP_OK,
- "poll-payment-1",
- GNUNET_NO),
- TALER_TESTING_cmd_poll_payment_start ("poll-payment-2",
- merchant_url,
- "create-proposal-1",
- NULL,
- GNUNET_TIME_UNIT_MINUTES),
- TALER_TESTING_cmd_check_payment_start ("check-payment-2",
- merchant_url,
- "create-proposal-1",
- GNUNET_TIME_UNIT_MINUTES),
-#endif
TALER_TESTING_cmd_poll_order_start ("poll-order-merchant-1-start",
merchant_url,
"1",
@@ -361,20 +267,6 @@ run (void *cls,
true,
false,
MHD_HTTP_OK),
-#if 0
- TALER_TESTING_cmd_poll_payment_conclude ("poll-payment-conclude-2",
- MHD_HTTP_OK,
- "poll-payment-2",
- GNUNET_YES),
- TALER_TESTING_cmd_check_payment_conclude ("check-payment-conclude-2",
- MHD_HTTP_OK,
- "check-payment-2",
- GNUNET_YES),
- TALER_TESTING_cmd_merchant_order_abort ("pay-abort-2",
- merchant_url,
- "deposit-simple",
- MHD_HTTP_FORBIDDEN),
-#endif
TALER_TESTING_cmd_merchant_pay_order ("replay-simple",
merchant_url,
MHD_HTTP_OK,
@@ -412,6 +304,38 @@ run (void *cls,
false,
NULL,
MHD_HTTP_OK),
+ TALER_TESTING_cmd_merchant_post_products ("post-products-p3",
+ merchant_url,
+ "product-3",
+ "a product",
+ "EUR:1",
+ MHD_HTTP_NO_CONTENT),
+ TALER_TESTING_cmd_merchant_post_orders2 ("create-proposal-p3-wm-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}\"} ] }",
+ "unsupported-wire-method"),
+ TALER_TESTING_cmd_merchant_post_orders2 ("create-proposal-p3",
+ merchant_url,
+ MHD_HTTP_OK,
+ "{\"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"),
TALER_TESTING_cmd_merchant_delete_order ("delete-order-1",
merchant_url,
"1",
diff --git a/src/testing/test_merchant_api_twisted.c b/src/testing/test_merchant_api_twisted.c
index d07c2edb..8f94ac17 100644
--- a/src/testing/test_merchant_api_twisted.c
+++ b/src/testing/test_merchant_api_twisted.c
@@ -339,6 +339,52 @@ run (void *cls,
MHD_HTTP_NO_CONTENT),
TALER_TESTING_cmd_batch ("pay",
pay),
+ /* Malform the response from the exchange. */
+ /**
+ * Move money to the exchange's bank account.
+ */
+ CMD_TRANSFER_TO_EXCHANGE ("create-reserve-1",
+ "EUR:10.02"),
+ /**
+ * Make a reserve exist,
+ * according to the previous
+ * transfer.
+ *///
+ CMD_EXEC_WIREWATCH ("wirewatch-1"),
+ TALER_TESTING_cmd_check_bank_admin_transfer ("check_bank_transfer-2",
+ "EUR:10.02",
+ payer_payto,
+ exchange_payto,
+ "create-reserve-1"),
+ TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-1",
+ "create-reserve-1",
+ "EUR:5",
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-2",
+ "create-reserve-1",
+ "EUR:5",
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_merchant_post_orders ("create-proposal-1",
+ merchant_url,
+ MHD_HTTP_OK,
+ "{\"max_fee\":\"EUR:0.5\",\
+ \"order_id\":\"1\",\
+ \"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}\"} ] }"),
+ TALER_TESTING_cmd_malform_response ("malform-exchange-reponse-1",
+ PROXY_EXCHANGE_CONFIG_FILE),
+ TALER_TESTING_cmd_merchant_pay_order ("deposit-simple",
+ merchant_url,
+ MHD_HTTP_FAILED_DEPENDENCY,
+ "create-proposal-1",
+ "withdraw-coin-1",
+ "EUR:5",
+ "EUR:4.99"),
TALER_TESTING_cmd_end ()
};
diff --git a/src/testing/testing_api_cmd_post_orders.c b/src/testing/testing_api_cmd_post_orders.c
index 0a1db61d..243dbca3 100644
--- a/src/testing/testing_api_cmd_post_orders.c
+++ b/src/testing/testing_api_cmd_post_orders.c
@@ -96,6 +96,11 @@ struct OrdersState
* Merchant public key.
*/
struct TALER_MerchantPublicKeyP merchant_pub;
+
+ /**
+ * The payment target for the order
+ */
+ const char *payment_target;
};
@@ -320,6 +325,70 @@ orders_run (void *cls,
/**
+ * Run a "orders" CMD.
+ *
+ * @param cls closure.
+ * @param cmd command currently being run.
+ * @param is interpreter state.
+ */
+static void
+orders_run2 (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct OrdersState *ps = cls;
+ json_t *order;
+ json_error_t error;
+
+ ps->is = is;
+ order = json_loads (ps->order,
+ JSON_REJECT_DUPLICATES,
+ &error);
+ if (NULL == order)
+ {
+ // human error here.
+ GNUNET_break (0);
+ fprintf (stderr, "%s\n", error.text);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+
+ if (NULL == json_object_get (order,
+ "order_id"))
+ {
+ struct GNUNET_TIME_Absolute now;
+ char *order_id;
+
+ // FIXME: should probably use get_monotone() to ensure uniqueness!
+ now = GNUNET_TIME_absolute_get ();
+ order_id = GNUNET_STRINGS_data_to_string_alloc
+ (&now.abs_value_us,
+ sizeof (now.abs_value_us));
+ json_object_set_new (order,
+ "order_id",
+ json_string (order_id));
+ GNUNET_free (order_id);
+ }
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ &ps->nonce,
+ sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
+ ps->po = TALER_MERCHANT_orders_post2 (is->ctx,
+ ps->merchant_url,
+ order,
+ GNUNET_TIME_UNIT_ZERO,
+ ps->payment_target,
+ 0,
+ NULL,
+ 0,
+ NULL,
+ &order_cb,
+ ps);
+ json_decref (order);
+ GNUNET_assert (NULL != ps->po);
+}
+
+
+/**
* Free the state of a "orders" CMD, and possibly
* cancel it if it did not complete.
*
@@ -392,3 +461,42 @@ TALER_TESTING_cmd_merchant_post_orders (const char *label,
return cmd;
}
}
+
+
+/**
+ * Make the "proposal" command.
+ *
+ * @param label command label
+ * @param merchant_url base URL of the merchant serving
+ * the proposal request.
+ * @param http_status expected HTTP status.
+ * @param order the order to PUT to the merchant.
+ * @param payment_target payment target for the order.
+ * @return the command
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_post_orders2 (const char *label,
+ const char *merchant_url,
+ unsigned int http_status,
+ const char *order,
+ const char *payment_target)
+{
+ struct OrdersState *ps;
+
+ ps = GNUNET_new (struct OrdersState);
+ ps->order = order;
+ ps->http_status = http_status;
+ ps->merchant_url = merchant_url;
+ ps->payment_target = payment_target;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = ps,
+ .label = label,
+ .run = &orders_run2,
+ .cleanup = &orders_cleanup,
+ .traits = &orders_traits
+ };
+
+ return cmd;
+ }
+}