summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcello Stanisci <marcello.stanisci@inria.fr>2017-02-10 17:33:04 +0100
committerMarcello Stanisci <marcello.stanisci@inria.fr>2017-02-10 17:33:04 +0100
commit3e4ae933093b6161aa4f7c6ec21f3210f4f23945 (patch)
tree4d2070cd704a74e3dd3026e5491cd4793c289cfa /src
parent60c5ee76aebfda9c378a4d9fe81544ba0ec5b214 (diff)
downloadmerchant-3e4ae933093b6161aa4f7c6ec21f3210f4f23945.tar.gz
merchant-3e4ae933093b6161aa4f7c6ec21f3210f4f23945.tar.bz2
merchant-3e4ae933093b6161aa4f7c6ec21f3210f4f23945.zip
Fix track API tests.
Diffstat (limited to 'src')
-rw-r--r--src/backend/taler-merchant-httpd_proposal.c17
-rw-r--r--src/backend/taler-merchant-httpd_track-transaction.c13
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c21
-rw-r--r--src/backenddb/test_merchantdb.c4
-rw-r--r--src/include/taler_merchant_service.h1
-rw-r--r--src/include/taler_merchantdb_plugin.h6
-rw-r--r--src/lib/merchant_api_proposal.c6
-rw-r--r--src/lib/test_merchant_api.c22
8 files changed, 66 insertions, 24 deletions
diff --git a/src/backend/taler-merchant-httpd_proposal.c b/src/backend/taler-merchant-httpd_proposal.c
index 6e45b2db..0ee23c8f 100644
--- a/src/backend/taler-merchant-httpd_proposal.c
+++ b/src/backend/taler-merchant-httpd_proposal.c
@@ -292,6 +292,7 @@ MH_handler_proposal_put (struct TMH_RequestHandler *rh,
if (GNUNET_OK !=
db->insert_proposal_data (db->cls,
&h_oid,
+ &mi->pubkey,
order))
return TMH_RESPONSE_reply_internal_error (connection,
TALER_EC_PROPOSAL_STORE_DB_ERROR,
@@ -329,9 +330,22 @@ MH_handler_proposal_lookup (struct TMH_RequestHandler *rh,
size_t *upload_data_size)
{
const char *order_id;
+ const char *instance;
struct GNUNET_HashCode h_oid;
int res;
json_t *proposal_data;
+ struct MerchantInstance *mi;
+
+ instance = MHD_lookup_connection_value (connection,
+ MHD_GET_ARGUMENT_KIND,
+ "instance");
+ if (NULL == instance)
+ return TMH_RESPONSE_reply_arg_missing (connection,
+ TALER_EC_PARAMETER_MISSING,
+ "instance");
+
+ mi = TMH_lookup_instance (instance);
+ GNUNET_assert (NULL != mi);
order_id = MHD_lookup_connection_value (connection,
MHD_GET_ARGUMENT_KIND,
@@ -346,7 +360,8 @@ MH_handler_proposal_lookup (struct TMH_RequestHandler *rh,
res = db->find_proposal_data (db->cls,
&proposal_data,
- &h_oid);
+ &h_oid,
+ &mi->pubkey);
if (GNUNET_NO == res)
return TMH_RESPONSE_reply_not_found (connection,
TALER_EC_PROPOSAL_LOOKUP_NOT_FOUND,
diff --git a/src/backend/taler-merchant-httpd_track-transaction.c b/src/backend/taler-merchant-httpd_track-transaction.c
index 0e48b3c6..608c3eb9 100644
--- a/src/backend/taler-merchant-httpd_track-transaction.c
+++ b/src/backend/taler-merchant-httpd_track-transaction.c
@@ -907,17 +907,21 @@ MH_handler_track_transaction (struct TMH_RequestHandler *rh,
"instance");
if (NULL == instance)
instance = "default";
+
GNUNET_CRYPTO_hash (instance,
strlen (instance),
&h_instance);
+
GNUNET_CRYPTO_hash (order_id,
strlen (order_id),
&h_order_id);
-
-
tctx->mi = GNUNET_CONTAINER_multihashmap_get (by_id_map,
&h_instance);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Tracking on behalf of instance '%s'\n",
+ instance);
+
if (NULL == tctx->mi)
return TMH_RESPONSE_reply_not_found (connection,
TALER_EC_TRACK_TRANSACTION_INSTANCE_UNKNOWN,
@@ -925,7 +929,8 @@ MH_handler_track_transaction (struct TMH_RequestHandler *rh,
if (GNUNET_YES != db->find_proposal_data (db->cls,
&proposal_data,
- &h_order_id))
+ &h_order_id,
+ &tctx->mi->pubkey))
return TMH_RESPONSE_reply_not_found (connection,
TALER_EC_PROPOSAL_LOOKUP_NOT_FOUND,
@@ -944,6 +949,8 @@ MH_handler_track_transaction (struct TMH_RequestHandler *rh,
tctx);
if (GNUNET_NO == ret)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "h_proposal_data not found\n");
return TMH_RESPONSE_reply_not_found (connection,
TALER_EC_TRACK_TRANSACTION_TRANSACTION_UNKNOWN,
"h_proposal_data is unknown");
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index 6a8bb46b..1c479029 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -165,8 +165,9 @@ postgres_initialize (void *cls)
PG_EXEC (pg,
"CREATE TABLE IF NOT EXISTS merchant_proposal_data ("
"h_order_id BYTEA NOT NULL"
+ ",merchant_pub BYTEA NOT NULL"
",proposal_data BYTEA NOT NULL"
- ",PRIMARY KEY (h_order_id)"
+ ",PRIMARY KEY (h_order_id, merchant_pub)"
");");
PG_EXEC (pg,
@@ -279,17 +280,19 @@ postgres_initialize (void *cls)
"insert_proposal_data",
"INSERT INTO merchant_proposal_data"
"(h_order_id"
+ ",merchant_pub"
",proposal_data)"
" VALUES "
- "($1, $2)",
- 2);
+ "($1, $2, $3)",
+ 3);
PG_PREPARE (pg,
"find_proposal_data",
"SELECT proposal_data FROM merchant_proposal_data"
" WHERE"
- " h_order_id=$1",
- 1);
+ " h_order_id=$1"
+ " AND merchant_pub=$2",
+ 2);
PG_PREPARE (pg,
"find_transactions_by_date",
@@ -406,7 +409,8 @@ postgres_initialize (void *cls)
static int
postgres_find_proposal_data (void *cls,
json_t **proposal_data,
- struct GNUNET_HashCode *h_transaction_id)
+ const struct GNUNET_HashCode *h_transaction_id,
+ const struct TALER_MerchantPublicKeyP *merchant_pub)
{
struct PostgresClosure *pg = cls;
PGresult *result;
@@ -414,6 +418,7 @@ postgres_find_proposal_data (void *cls,
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (h_transaction_id),
+ GNUNET_PQ_query_param_auto_from_type (merchant_pub),
GNUNET_PQ_query_param_end
};
@@ -461,7 +466,8 @@ postgres_find_proposal_data (void *cls,
*/
static int
postgres_insert_proposal_data (void *cls,
- struct GNUNET_HashCode *h_transaction_id,
+ const struct GNUNET_HashCode *h_transaction_id,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
const json_t *proposal_data)
{
struct PostgresClosure *pg = cls;
@@ -470,6 +476,7 @@ postgres_insert_proposal_data (void *cls,
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (h_transaction_id),
+ GNUNET_PQ_query_param_auto_from_type (merchant_pub),
TALER_PQ_query_param_json (proposal_data),
GNUNET_PQ_query_param_end
};
diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index b74549d4..c8366f34 100644
--- a/src/backenddb/test_merchantdb.c
+++ b/src/backenddb/test_merchantdb.c
@@ -372,6 +372,7 @@ run (void *cls)
FAILIF (GNUNET_OK !=
plugin->insert_proposal_data (plugin->cls,
&h_transaction_id,
+ &merchant_pub,
proposal_data));
json_t *out;
@@ -379,7 +380,8 @@ run (void *cls)
FAILIF (GNUNET_OK !=
plugin->find_proposal_data (plugin->cls,
&out, // plain data
- &h_transaction_id));
+ &h_transaction_id,
+ &merchant_pub));
FAILIF (GNUNET_OK !=
plugin->store_transaction (plugin->cls,
diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h
index 61919d09..6c549c8d 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -123,6 +123,7 @@ struct TALER_MERCHANT_ProposalLookupOperation *
TALER_MERCHANT_proposal_lookup (struct GNUNET_CURL_Context *ctx,
const char *backend_uri,
const char *transaction_id,
+ const char *instance,
TALER_MERCHANT_ProposalLookupOperationCallback plo_cb,
void *plo_cb_cls);
diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h
index 06f1c565..33102a03 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -158,7 +158,8 @@ struct TALER_MERCHANTDB_Plugin
*/
int
(*insert_proposal_data) (void *cls,
- struct GNUNET_HashCode *h_transaction_id,
+ const struct GNUNET_HashCode *h_transaction_id,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
const json_t *proposal_data);
@@ -176,7 +177,8 @@ struct TALER_MERCHANTDB_Plugin
int
(*find_proposal_data) (void *cls,
json_t **proposal_data,
- struct GNUNET_HashCode *h_transaction_id);
+ const struct GNUNET_HashCode *h_transaction_id,
+ const struct TALER_MerchantPublicKeyP *merchant_pub);
/**
diff --git a/src/lib/merchant_api_proposal.c b/src/lib/merchant_api_proposal.c
index 60b38d93..c3e58735 100644
--- a/src/lib/merchant_api_proposal.c
+++ b/src/lib/merchant_api_proposal.c
@@ -288,6 +288,7 @@ struct TALER_MERCHANT_ProposalLookupOperation *
TALER_MERCHANT_proposal_lookup (struct GNUNET_CURL_Context *ctx,
const char *backend_uri,
const char *order_id,
+ const char *instance,
TALER_MERCHANT_ProposalLookupOperationCallback plo_cb,
void *plo_cb_cls)
{
@@ -300,9 +301,10 @@ TALER_MERCHANT_proposal_lookup (struct GNUNET_CURL_Context *ctx,
plo->cb_cls = plo_cb_cls;
GNUNET_asprintf (&plo->url,
- "%s/proposal?order_id=%s",
+ "%s/proposal?order_id=%s&instance=%s",
backend_uri,
- order_id);
+ order_id,
+ instance);
eh = curl_easy_init ();
if (CURLE_OK != curl_easy_setopt (eh,
CURLOPT_URL,
diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c
index a69e4c9a..0a7856ca 100644
--- a/src/lib/test_merchant_api.c
+++ b/src/lib/test_merchant_api.c
@@ -1046,6 +1046,9 @@ proposal_cb (void *cls,
cmd->details.proposal.proposal_data = json_incref ((json_t *) proposal_data);
cmd->details.proposal.merchant_sig = *sig;
cmd->details.proposal.hash = *hash;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Hashed proposal, '%s'\n",
+ GNUNET_h2s (hash));
break;
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1357,6 +1360,8 @@ track_transaction_cb (void *cls,
struct TALER_Amount ea;
struct TALER_Amount coin_contribution;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Successful /track/tracking\n");
if (1 != num_transfers)
{
GNUNET_break (0);
@@ -1511,7 +1516,7 @@ interpreter_run (void *cls)
is->ip = 0;
instance_idx++;
instance = instances[instance_idx];
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Switching instance: '%s'\n",
instance);
@@ -1535,6 +1540,7 @@ interpreter_run (void *cls)
= TALER_MERCHANT_proposal_lookup (ctx,
MERCHANT_URI,
order_id,
+ instance,
proposal_lookup_cb,
is)));
}
@@ -1762,9 +1768,6 @@ interpreter_run (void *cls)
cmd->details.pay.contract_ref);
GNUNET_assert (NULL != ref);
merchant_sig = ref->details.proposal.merchant_sig;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Depositing I on '%s'\n",
- GNUNET_h2s (&ref->details.proposal.hash));
GNUNET_assert (NULL != ref->details.proposal.proposal_data);
{
/* Get information that need to be replied in the deposit permission */
@@ -1840,10 +1843,6 @@ interpreter_run (void *cls)
}
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Depositing II on '%s'\n",
- GNUNET_h2s (&ref->details.proposal.hash));
-
cmd->details.pay.ph
= TALER_MERCHANT_pay_wallet (ctx,
MERCHANT_URI,
@@ -2380,6 +2379,13 @@ run (void *cls)
{ .oc = OC_CHECK_BANK_TRANSFERS_EMPTY,
.label = "check_bank_empty" },
+ { .oc = OC_TRACK_TRANSACTION,
+ .label = "track-transaction-1",
+ .expected_response_code = MHD_HTTP_OK,
+ .details.track_transaction.expected_transfer_ref = "check_bank_transfer-499c",
+ .details.track_transaction.pay_ref = "deposit-simple"
+ },
+
/* Trace the WTID back to the original transaction */
{ .oc = OC_TRACK_TRANSFER,
.label = "track-transfer-1",