summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2019-01-31 17:44:13 +0100
committerMarcello Stanisci <stanisci.m@gmail.com>2019-01-31 17:44:13 +0100
commit9bf941792d5d093a51d811f5e2595ca5b718cdb0 (patch)
tree3a288e7e86874f4e85728f0d9056d72ee652ffbe /src
parentdbffac740680e26e6a310ec7100e6bc0ae45af61 (diff)
downloadmerchant-9bf941792d5d093a51d811f5e2595ca5b718cdb0.tar.gz
merchant-9bf941792d5d093a51d811f5e2595ca5b718cdb0.tar.bz2
merchant-9bf941792d5d093a51d811f5e2595ca5b718cdb0.zip
/proposal API disambiguation.
The order object gives the client TWO ways to specify the merchant instance: one is at the object top-level, and the other one is within the "merchant" sub-object. This change makes sure that the top-level instance indication and the one internal to the merchant sub-object refer always to the same instance. Note: when the top-level indication is missing, then the instance is set to "default", and the merchant sub- object must likewise specify a "default" instance.
Diffstat (limited to 'src')
-rw-r--r--src/backend/taler-merchant-httpd_proposal.c45
-rw-r--r--src/backend/taler-merchant-httpd_track-transaction.c45
-rw-r--r--src/lib/test_merchant_api.c22
-rw-r--r--src/lib/test_merchant_api_twisted.c1
-rw-r--r--src/lib/testing_api_cmd_proposal.c5
5 files changed, 85 insertions, 33 deletions
diff --git a/src/backend/taler-merchant-httpd_proposal.c b/src/backend/taler-merchant-httpd_proposal.c
index b2dc610f..9703bde9 100644
--- a/src/backend/taler-merchant-httpd_proposal.c
+++ b/src/backend/taler-merchant-httpd_proposal.c
@@ -310,7 +310,6 @@ proposal_put (struct MHD_Connection *connection,
instance = json_string_value (json_object_get (order,
"instance"));
-
if (NULL == instance)
{
TALER_LOG_DEBUG ("Giving 'default' instance\n");
@@ -411,12 +410,6 @@ proposal_put (struct MHD_Connection *connection,
} /* needed to synthesize merchant info */
} /* scope of 'mi' */
- /* "instance" information does not belong with the proposal,
- instances are internal to the backend, so remove here
- (if present) */
- json_object_del (order,
- "instance");
-
/* extract fields we need to sign separately */
res = TMH_PARSE_json_data (connection,
order,
@@ -448,33 +441,43 @@ proposal_put (struct MHD_Connection *connection,
mi = TMH_lookup_instance_json (merchant);
+ if (NULL == mi)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Not able to find the specified instance\n");
+ GNUNET_JSON_parse_free (spec);
+ return TMH_RESPONSE_reply_not_found
+ (connection,
+ TALER_EC_CONTRACT_INSTANCE_UNKNOWN,
+ "Unknown instance (order:merchant:instance) given");
+ }
+
/* The outer instance field, and the one included
* in the merchant object are different */
if (0 != strcmp (mi->id,
instance))
{
TALER_LOG_ERROR
- ("Inconsistent instance specified by merchant\n");
+ ("Inconsistent instance specified"
+ " by merchant ('%s' vs '%s')\n",
+ instance,
+ mi->id);
+
+ TALER_LOG_DEBUG ("Dump wrong order: %s\n",
+ json_dumps (order,
+ JSON_INDENT (1)));
+
return TMH_RESPONSE_reply_not_found
(connection,
TALER_EC_CONTRACT_INSTANCE_INCONSISTENT,
"Inconsistent instance given");
}
- if (NULL == mi)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Not able to find the specified instance\n");
- GNUNET_JSON_parse_free (spec);
- return TMH_RESPONSE_reply_not_found
- (connection,
- TALER_EC_CONTRACT_INSTANCE_UNKNOWN,
- "Unknown instance (order:merchant:instance) given");
- }
/* add fields to the contract that the backend should provide */
json_object_set (order,
"exchanges",
trusted_exchanges);
+
json_object_set (order,
"auditors",
j_auditors);
@@ -507,6 +510,7 @@ proposal_put (struct MHD_Connection *connection,
"Inserting order '%s' for instance '%s'\n",
order_id,
mi->id);
+
for (unsigned int i=0;i<MAX_RETRIES;i++)
{
qs = db->insert_order (db->cls,
@@ -529,6 +533,7 @@ proposal_put (struct MHD_Connection *connection,
"db error: could not check for existing order"
" due to repeated soft transaction failure");
}
+
{
/* Hard error could be constraint violation,
check if order already exists */
@@ -556,7 +561,8 @@ proposal_put (struct MHD_Connection *connection,
JSON_COMPACT);
GNUNET_log
(GNUNET_ERROR_TYPE_ERROR,
- _("Order ID `%s' already exists with proposal `%s'\n"),
+ _("Order ID `%s' already exists"
+ " with proposal `%s'\n"),
order_id,
js);
free (js);
@@ -573,6 +579,7 @@ proposal_put (struct MHD_Connection *connection,
return rv;
}
}
+
/* Other hard transaction error (disk full, etc.) */
GNUNET_JSON_parse_free (spec);
return TMH_RESPONSE_reply_internal_error
diff --git a/src/backend/taler-merchant-httpd_track-transaction.c b/src/backend/taler-merchant-httpd_track-transaction.c
index 44466913..d059c0d4 100644
--- a/src/backend/taler-merchant-httpd_track-transaction.c
+++ b/src/backend/taler-merchant-httpd_track-transaction.c
@@ -605,21 +605,36 @@ wtid_cb (void *cls,
enum GNUNET_DB_QueryStatus qs;
tcc->dwh = NULL;
+
if (MHD_HTTP_OK != http_status)
{
- /* Transaction not resolved for one of the coins, report error!
- We keep the status code for #MHD_HTTP_ACCEPTED, but box all the
- others (as #MHD_HTTP_ACCEPTED is not an error). */
+ if (MHD_HTTP_ACCEPTED == http_status)
+ {
+ resume_track_transaction_with_response
+ (tcc->tctx,
+ MHD_HTTP_ACCEPTED,
+ /* Return verbatim what the exchange said. */
+ TMH_RESPONSE_make_json (json));
+
+ return;
+ }
+
+ /* Transaction not resolved for one of the
+ coins, report error! */
resume_track_transaction_with_response
(tcc->tctx,
- (MHD_HTTP_ACCEPTED == http_status)
- ? MHD_HTTP_ACCEPTED
- : MHD_HTTP_FAILED_DEPENDENCY,
- TMH_RESPONSE_make_json_pack ("{s:I, s:I, s:I, s:O}",
- "code", (json_int_t) TALER_EC_TRACK_TRANSACTION_COIN_TRACE_ERROR,
- "exchange-http-status", (json_int_t) http_status,
- "exchange-code", (json_int_t) ec,
- "details", json));
+ MHD_HTTP_FAILED_DEPENDENCY,
+ TMH_RESPONSE_make_json_pack
+ ("{s:I, s:I, s:I, s:O}",
+ "code",
+ (json_int_t) TALER_EC_TRACK_TRANSACTION_COIN_TRACE_ERROR,
+ "exchange-http-status",
+ (json_int_t) http_status,
+ "exchange-code",
+ (json_int_t) ec,
+ "details",
+ json));
+
return;
}
tctx->current_wtid = *wtid;
@@ -635,15 +650,17 @@ wtid_cb (void *cls,
&pcc);
if (0 > qs)
{
- /* Simple select queries should not cause serialization issues */
+ /* Simple select queries should not
+ cause serialization issues */
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR != qs);
/* Always report on hard error as well to enable diagnostics */
GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
resume_track_transaction_with_response
(tcc->tctx,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TMH_RESPONSE_make_error (TALER_EC_TRACK_TRANSACTION_DB_FETCH_FAILED,
- "Fail to query database about proofs"));
+ TMH_RESPONSE_make_error
+ (TALER_EC_TRACK_TRANSACTION_DB_FETCH_FAILED,
+ "Fail to query database about proofs"));
return;
}
diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c
index 83025518..1f74b302 100644
--- a/src/lib/test_merchant_api.c
+++ b/src/lib/test_merchant_api.c
@@ -3311,14 +3311,36 @@ interpreter_run (void *cls)
{
json_t *merchant;
+ TALER_LOG_DEBUG ("/proposal: explicit set of merchant:instance to '%s'\n",
+ instance);
+
merchant = json_object ();
+
json_object_set_new (merchant,
"instance",
json_string (instance));
+
json_object_set_new (order,
"merchant",
merchant);
+
+ /* When a instance other than the default is used, we're
+ forced to specify the outer 'instance' field too, otherwise
+ we'll hit a 2001 "inconsistent instance" error. */
+ if (0 != strcmp ("default",
+ instance))
+ {
+ json_object_set_new (order,
+ "instance",
+ json_string (instance));
+
+ }
}
+
+ TALER_LOG_DEBUG ("PUTting order: %s\n",
+ json_dumps (order,
+ JSON_INDENT (1)));
+
cmd->details.proposal.po = TALER_MERCHANT_order_put (ctx,
MERCHANT_URL,
order,
diff --git a/src/lib/test_merchant_api_twisted.c b/src/lib/test_merchant_api_twisted.c
index 0c22c0a5..0335153b 100644
--- a/src/lib/test_merchant_api_twisted.c
+++ b/src/lib/test_merchant_api_twisted.c
@@ -504,6 +504,7 @@ run (void *cls,
\"refund_deadline\":\"\\/Date(2)\\/\",\
\"pay_deadline\":\"\\/Date(1)\\/\",\
\"wire_transfer_delay\":\"\\/Delay(30000)\\/\",\
+ \"instance\":\"tor\",\
\"amount\":\
{\"currency\":\"EUR\",\
\"value\":5,\
diff --git a/src/lib/testing_api_cmd_proposal.c b/src/lib/testing_api_cmd_proposal.c
index 8fc52d9f..bceecc17 100644
--- a/src/lib/testing_api_cmd_proposal.c
+++ b/src/lib/testing_api_cmd_proposal.c
@@ -272,7 +272,12 @@ proposal_cb (void *cls,
ps->po = NULL;
if (ps->http_status != http_status)
+ {
+ TALER_LOG_ERROR ("Given vs expected: %u vs %u\n",
+ http_status,
+ ps->http_status);
TALER_TESTING_FAIL (ps->is);
+ }
if (0 == ps->http_status)
{