aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-06-19 02:30:17 -0400
committerJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-06-19 02:30:17 -0400
commite35244074480faa18f6370e4d5b800ed35d8ef94 (patch)
tree5a5493a1899ee2ba33077d837966bd288c76f088
parent566408fa02acf56bbf6063c6d17d739e491e27f2 (diff)
stricter tests for query reserve(s) methods
-rw-r--r--src/backend/taler-merchant-httpd_private-get-reserves-ID.c2
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c3
-rw-r--r--src/include/taler_merchant_testing_lib.h36
-rw-r--r--src/lib/merchant_api_get_reserve.c4
-rw-r--r--src/testing/test_merchant_api.c15
-rw-r--r--src/testing/testing_api_cmd_get_reserve.c114
-rw-r--r--src/testing/testing_api_cmd_get_reserves.c102
7 files changed, 272 insertions, 4 deletions
diff --git a/src/backend/taler-merchant-httpd_private-get-reserves-ID.c b/src/backend/taler-merchant-httpd_private-get-reserves-ID.c
index 2d789d0a..7e7c14a9 100644
--- a/src/backend/taler-merchant-httpd_private-get-reserves-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-reserves-ID.c
@@ -94,7 +94,7 @@ handle_reserve_details (void *cls,
GNUNET_assert (0 ==
json_array_append_new (
tips_json,
- json_pack ("{s:o,s:o,s:I}",
+ json_pack ("{s:o,s:o,s:s}",
"tip_id",
GNUNET_JSON_from_data_auto (
&tips[i].tip_id),
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index 7188839e..f218e438 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -4512,7 +4512,8 @@ postgres_lookup_reserve (void *cls,
{
struct PostgresClosure *pg = cls;
struct LookupTipsContext ltc = {
- .pg = pg
+ .pg = pg,
+ .qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
};
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_string (instance_id),
diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h
index 85cd73ef..02df16c7 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -612,6 +612,25 @@ TALER_TESTING_cmd_merchant_get_reserve (const char *label,
/**
+ * Define a "GET reserve" CMD.
+ *
+ * @param label command label.
+ * @param merchant_url base URL of the merchant serving the request.
+ * @param http_status expected HTTP response code.
+ * @param reserve_reference reference to a "POST /reserves" that provides the
+ * information we are expecting.
+ * @param tip_refs a NULL-terminated list of references to tips
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_get_reserve_with_tips (const char *label,
+ const char *merchant_url,
+ unsigned int http_status,
+ const char *reserve_reference,
+ const char *tip_refs[]);
+
+
+/**
* Define a "GET /reserves" CMD
*
* @param label command label.
@@ -625,6 +644,23 @@ TALER_TESTING_cmd_merchant_get_reserves (const char *label,
/**
+ * Define a "GET /reserves" CMD
+ *
+ * @param label command label.
+ * @param merchant_url url to the merchant.
+ * @param reserve_refs a NULL-terminated list of references to
+ * commands that created reserves.
+ * @param http_status expected HTTP response code.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_get_reserves_with_reserves (const char *label,
+ const char *merchant_url,
+ const char *reserve_refs
+ [],
+ unsigned int
+ http_status);
+
+/**
* Define a "DELETE reserve" CMD.
*
* @param label command label.
diff --git a/src/lib/merchant_api_get_reserve.c b/src/lib/merchant_api_get_reserve.c
index d9f4a270..f92f37f9 100644
--- a/src/lib/merchant_api_get_reserve.c
+++ b/src/lib/merchant_api_get_reserve.c
@@ -155,10 +155,10 @@ handle_reserve_get_finished (void *cls,
json_array_foreach (tips, i, tip) {
struct TALER_MERCHANT_TipDetails *td = &tds[i];
struct GNUNET_JSON_Specification ispec[] = {
- TALER_JSON_spec_amount ("amount",
- &td->amount),
GNUNET_JSON_spec_fixed_auto ("tip_id",
&td->tip_id),
+ TALER_JSON_spec_amount ("total_amount",
+ &td->amount),
GNUNET_JSON_spec_string ("reason",
&td->reason),
GNUNET_JSON_spec_end ()
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index 8663b2e3..8920a2a4 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -49,12 +49,17 @@
*/
#define EXCHANGE_URL "http://localhost:8081/"
+static const char *tip_refs[] = {"authorize-tip-1", "authorize-tip-2", NULL};
+
static const char *pickup_amounts_1[] = {"EUR:5", NULL};
static const char *pickup_amounts_2[] = {"EUR:0.01", NULL};
static const char *pickup_refs[] = {"pickup-tip-1", "pickup-tip-4", NULL};
+static const char *reserve_refs[] = {"create-reserve-tip-1",
+ "create-reserve-tip-2", NULL};
+
/**
* Payto URI of the customer (payer).
*/
@@ -683,6 +688,11 @@ run (void *cls,
merchant_url,
MHD_HTTP_OK,
"create-reserve-tip-1"),
+ TALER_TESTING_cmd_merchant_get_reserve_with_tips ("get-reserve-2",
+ merchant_url,
+ MHD_HTTP_OK,
+ "create-reserve-tip-1",
+ tip_refs),
TALER_TESTING_cmd_tip_pickup ("pickup-tip-1",
merchant_url,
MHD_HTTP_OK,
@@ -763,6 +773,11 @@ run (void *cls,
pickup_amounts_1,
TALER_EC_TIP_PICKUP_TIP_ID_UNKNOWN),
+ TALER_TESTING_cmd_merchant_get_reserves_with_reserves ("get-reserves-2",
+ merchant_url,
+ reserve_refs,
+ MHD_HTTP_OK),
+
TALER_TESTING_cmd_merchant_delete_reserve ("delete-reserve-tip-1",
merchant_url,
"create-reserve-tip-1",
diff --git a/src/testing/testing_api_cmd_get_reserve.c b/src/testing/testing_api_cmd_get_reserve.c
index 2a685ae4..8a26a9a9 100644
--- a/src/testing/testing_api_cmd_get_reserve.c
+++ b/src/testing/testing_api_cmd_get_reserve.c
@@ -60,6 +60,11 @@ struct GetReserveState
* Fetch tips
*/
bool fetch_tips;
+
+ /**
+ * The list of references to tips.
+ */
+ const char **tip_refs;
};
@@ -112,6 +117,76 @@ get_reserve_cb (void *cls,
return;
}
}
+ for (unsigned int i = 0; i < tips_length; ++i)
+ {
+ const struct TALER_TESTING_Command *tip_cmd;
+ if (NULL == grs->tip_refs[i])
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Number of tips authorized does not match\n");
+ TALER_TESTING_interpreter_fail (grs->is);
+ return;
+ }
+
+ tip_cmd = TALER_TESTING_interpreter_lookup_command (grs->is,
+ grs->tip_refs[i]);
+ {
+ const struct GNUNET_HashCode *tip_id;
+
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_tip_id (tip_cmd,
+ 0,
+ &tip_id))
+ TALER_TESTING_interpreter_fail (grs->is);
+
+ if (0 != GNUNET_memcmp (&tips[i].tip_id,
+ tip_id))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Reserve tip id does not match\n");
+ TALER_TESTING_interpreter_fail (grs->is);
+ return;
+ }
+ }
+ {
+ const struct TALER_Amount *total_amount;
+
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_amount_obj (tip_cmd,
+ 0,
+ &total_amount))
+ TALER_TESTING_interpreter_fail (grs->is);
+
+ if ((GNUNET_OK != TALER_amount_cmp_currency (&tips[i].amount,
+ total_amount)) ||
+ (0 != TALER_amount_cmp (&tips[i].amount,
+ total_amount)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Reserve tip amount does not match\n");
+ TALER_TESTING_interpreter_fail (grs->is);
+ return;
+ }
+ }
+ {
+ const char *reason;
+
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_string (tip_cmd,
+ 0,
+ &reason))
+ TALER_TESTING_interpreter_fail (grs->is);
+
+ if (0 != strcmp (tips[i].reason,
+ reason))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Reserve tip reason does not match\n");
+ TALER_TESTING_interpreter_fail (grs->is);
+ return;
+ }
+ }
+ }
break;
default:
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -217,4 +292,43 @@ TALER_TESTING_cmd_merchant_get_reserve (const char *label,
}
+/**
+ * Define a "GET reserve" CMD.
+ *
+ * @param label command label.
+ * @param merchant_url base URL of the merchant serving the request.
+ * @param http_status expected HTTP response code.
+ * @param reserve_reference reference to a "POST /reserves" that provides the
+ * information we are expecting.
+ * @param tip_refs a NULL-terminated list of references to tips
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_get_reserve_with_tips (const char *label,
+ const char *merchant_url,
+ unsigned int http_status,
+ const char *reserve_reference,
+ const char *tip_refs[])
+{
+ struct GetReserveState *grs;
+
+ grs = GNUNET_new (struct GetReserveState);
+ grs->merchant_url = merchant_url;
+ grs->http_status = http_status;
+ grs->reserve_reference = reserve_reference;
+ grs->fetch_tips = true;
+ grs->tip_refs = tip_refs;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = grs,
+ .label = label,
+ .run = &get_reserve_run,
+ .cleanup = &get_reserve_cleanup
+ };
+
+ return cmd;
+ }
+}
+
+
/* end of testing_api_cmd_get_reserve.c */
diff --git a/src/testing/testing_api_cmd_get_reserves.c b/src/testing/testing_api_cmd_get_reserves.c
index b9909cad..068d7e6e 100644
--- a/src/testing/testing_api_cmd_get_reserves.c
+++ b/src/testing/testing_api_cmd_get_reserves.c
@@ -45,6 +45,16 @@ struct GetReservesState
struct TALER_TESTING_Interpreter *is;
/**
+ * Whether to compare the reserves that were found.
+ */
+ bool cmp_reserves;
+
+ /**
+ * A list of reserves to compare with.
+ */
+ const char **reserve_refs;
+
+ /**
* Base URL of the merchant serving the request.
*/
const char *merchant_url;
@@ -80,6 +90,61 @@ get_reserves_cb (void *cls,
{
case MHD_HTTP_OK:
// FIXME: check if the data returned matches that from the POST / PATCH
+ if (! grs->cmp_reserves)
+ break;
+ for (unsigned int i = 0; i < reserves_length; ++i)
+ {
+ if (NULL == grs->reserve_refs[i])
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Number of reserves found does not match\n");
+ TALER_TESTING_interpreter_fail (grs->is);
+ return;
+ }
+
+ const struct TALER_TESTING_Command *reserve_cmd;
+
+ reserve_cmd = TALER_TESTING_interpreter_lookup_command (
+ grs->is,
+ grs->reserve_refs[i]);
+ {
+ const struct TALER_ReservePublicKeyP *reserve_pub;
+
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_reserve_pub (reserve_cmd,
+ 0,
+ &reserve_pub))
+ TALER_TESTING_interpreter_fail (grs->is);
+ if (0 != GNUNET_memcmp (&reserves[i].reserve_pub,
+ reserve_pub))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Reserve public key does not match\n");
+ TALER_TESTING_interpreter_fail (grs->is);
+ return;
+ }
+ }
+ {
+ const struct TALER_Amount *initial;
+
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_amount_obj (reserve_cmd,
+ 0,
+ &initial))
+ TALER_TESTING_interpreter_fail (grs->is);
+ if ((GNUNET_OK != TALER_amount_cmp_currency (
+ &reserves[i].merchant_initial_amount,
+ initial)) ||
+ (0 != TALER_amount_cmp (&reserves[i].merchant_initial_amount,
+ initial)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Reserve initial amount does not match\n");
+ TALER_TESTING_interpreter_fail (grs->is);
+ return;
+ }
+ }
+ }
break;
default:
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -155,6 +220,43 @@ TALER_TESTING_cmd_merchant_get_reserves (const char *label,
grs = GNUNET_new (struct GetReservesState);
grs->merchant_url = merchant_url;
+ grs->cmp_reserves = false;
+ grs->http_status = http_status;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = grs,
+ .label = label,
+ .run = &get_reserves_run,
+ .cleanup = &get_reserves_cleanup
+ };
+
+ return cmd;
+ }
+}
+
+
+/**
+ * Define a "GET /reserves" CMD
+ *
+ * @param label command label.
+ * @param merchant_url url to the merchant.
+ * @param reserve_refs a NULL-terminated list of references to
+ * commands that created reserves.
+ * @param http_status expected HTTP response code.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_get_reserves_with_reserves (const char *label,
+ const char *merchant_url,
+ const char *reserve_refs
+ [],
+ unsigned int http_status)
+{
+ struct GetReservesState *grs;
+
+ grs = GNUNET_new (struct GetReservesState);
+ grs->merchant_url = merchant_url;
+ grs->cmp_reserves = true;
+ grs->reserve_refs = reserve_refs;
grs->http_status = http_status;
{
struct TALER_TESTING_Command cmd = {