summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mint-lib/mint_api_deposit.c3
-rw-r--r--src/mint-lib/test_mint_api.c60
-rw-r--r--src/mint/taler-mint-httpd_responses.c4
3 files changed, 62 insertions, 5 deletions
diff --git a/src/mint-lib/mint_api_deposit.c b/src/mint-lib/mint_api_deposit.c
index 589860c46..34915eaf1 100644
--- a/src/mint-lib/mint_api_deposit.c
+++ b/src/mint-lib/mint_api_deposit.c
@@ -392,6 +392,9 @@ handle_deposit_finished (void *cls,
break;
default:
/* unexpected response code */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u\n",
+ response_code);
GNUNET_break (0);
response_code = 0;
break;
diff --git a/src/mint-lib/test_mint_api.c b/src/mint-lib/test_mint_api.c
index c99b4be49..acbe441b5 100644
--- a/src/mint-lib/test_mint_api.c
+++ b/src/mint-lib/test_mint_api.c
@@ -503,6 +503,10 @@ withdraw_status_cb (void *cls,
cmd->details.withdraw_status.wsh = NULL;
if (cmd->expected_response_code != http_status)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u to command %s\n",
+ http_status,
+ cmd->label);
GNUNET_break (0);
fail (is);
return;
@@ -575,7 +579,7 @@ withdraw_status_cb (void *cls,
return;
}
}
- /* FIXME: support other status codes! */
+ break;
default:
/* Unsupported status code (by test harness) */
GNUNET_break (0);
@@ -608,6 +612,10 @@ withdraw_sign_cb (void *cls,
cmd->details.withdraw_sign.wsh = NULL;
if (cmd->expected_response_code != http_status)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u to command %s\n",
+ http_status,
+ cmd->label);
GNUNET_break (0);
fail (is);
return;
@@ -624,7 +632,9 @@ withdraw_sign_cb (void *cls,
cmd->details.withdraw_sign.sig.rsa_signature
= GNUNET_CRYPTO_rsa_signature_dup (sig->rsa_signature);
break;
- /* FIXME: support other status codes here */
+ case MHD_HTTP_PAYMENT_REQUIRED:
+ /* nothing to check */
+ break;
default:
/* Unsupported status code (by test harness) */
GNUNET_break (0);
@@ -656,7 +666,10 @@ deposit_cb (void *cls,
cmd->details.deposit.dh = NULL;
if (cmd->expected_response_code != http_status)
{
- GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u to command %s\n",
+ http_status,
+ cmd->label);
fail (is);
return;
}
@@ -1235,16 +1248,20 @@ run (void *cls,
.expected_response_code = MHD_HTTP_OK,
.details.admin_add_incoming.wire = "{ \"type\":\"TEST\", \"bank\":\"source bank\", \"account\":42 }",
.details.admin_add_incoming.amount = "EUR:5.01" },
+ /* Withdraw a 5 EUR coin, at fee of 1 ct */
{ .oc = OC_WITHDRAW_SIGN,
.label = "withdraw-coin-1",
.expected_response_code = MHD_HTTP_OK,
.details.withdraw_sign.reserve_reference = "create-reserve-1",
.details.withdraw_sign.amount = "EUR:5" },
+ /* Check that deposit and withdraw operation are in history, and
+ that the balance is now at zero */
{ .oc = OC_WITHDRAW_STATUS,
.label = "withdraw-status-1",
.expected_response_code = MHD_HTTP_OK,
.details.withdraw_status.reserve_reference = "create-reserve-1",
.details.withdraw_status.expected_balance = "EUR:0" },
+ /* Try to deposit the 5 EUR coin (in full) */
{ .oc = OC_DEPOSIT,
.label = "deposit-simple",
.expected_response_code = MHD_HTTP_OK,
@@ -1253,6 +1270,43 @@ run (void *cls,
.details.deposit.wire_details = "{ \"type\":\"TEST\", \"bank\":\"dest bank\", \"account\":42 }",
.details.deposit.contract = "{ \"items\"={ \"name\":\"ice cream\", \"value\":1 } }",
.details.deposit.transaction_id = 1 },
+
+ /* Try to overdraw funds ... */
+ { .oc = OC_WITHDRAW_SIGN,
+ .label = "withdraw-coin-2",
+ .expected_response_code = MHD_HTTP_PAYMENT_REQUIRED,
+ .details.withdraw_sign.reserve_reference = "create-reserve-1",
+ .details.withdraw_sign.amount = "EUR:5" },
+ /* Try to double-spend the 5 EUR coin with different wire details */
+ { .oc = OC_DEPOSIT,
+ .label = "deposit-double-1",
+ .expected_response_code = MHD_HTTP_FORBIDDEN,
+ .details.deposit.amount = "EUR:5",
+ .details.deposit.coin_ref = "withdraw-coin-1",
+ .details.deposit.wire_details = "{ \"type\":\"TEST\", \"bank\":\"dest bank\", \"account\":43 }",
+ .details.deposit.contract = "{ \"items\"={ \"name\":\"ice cream\", \"value\":1 } }",
+ .details.deposit.transaction_id = 1 },
+ /* Try to double-spend the 5 EUR coin at the same merchant (but different
+ transaction ID) */
+ { .oc = OC_DEPOSIT,
+ .label = "deposit-double-2",
+ .expected_response_code = MHD_HTTP_FORBIDDEN,
+ .details.deposit.amount = "EUR:5",
+ .details.deposit.coin_ref = "withdraw-coin-1",
+ .details.deposit.wire_details = "{ \"type\":\"TEST\", \"bank\":\"dest bank\", \"account\":42 }",
+ .details.deposit.contract = "{ \"items\"={ \"name\":\"ice cream\", \"value\":1 } }",
+ .details.deposit.transaction_id = 2 },
+ /* Try to double-spend the 5 EUR coin at the same merchant (but different
+ contract) */
+ { .oc = OC_DEPOSIT,
+ .label = "deposit-double-3",
+ .expected_response_code = MHD_HTTP_FORBIDDEN,
+ .details.deposit.amount = "EUR:5",
+ .details.deposit.coin_ref = "withdraw-coin-1",
+ .details.deposit.wire_details = "{ \"type\":\"TEST\", \"bank\":\"dest bank\", \"account\":42 }",
+ .details.deposit.contract = "{ \"items\"={ \"name\":\"ice cream\", \"value\":2 } }",
+ .details.deposit.transaction_id = 1 },
+
{ .oc = OC_END }
};
diff --git a/src/mint/taler-mint-httpd_responses.c b/src/mint/taler-mint-httpd_responses.c
index b5e3ea5c2..bbf35b8bd 100644
--- a/src/mint/taler-mint-httpd_responses.c
+++ b/src/mint/taler-mint-httpd_responses.c
@@ -451,7 +451,7 @@ compile_transaction_history (const struct TALER_MINTDB_TransactionList *tl)
GNUNET_assert (0);
}
json_array_append_new (history,
- json_pack ("{s:s, s:o}",
+ json_pack ("{s:s, s:o, s:o}",
"type", type,
"amount", TALER_json_from_amount (&value),
"signature", transaction));
@@ -477,7 +477,7 @@ TMH_RESPONSE_reply_deposit_insufficient_funds (struct MHD_Connection *connection
history = compile_transaction_history (tl);
return TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_PRECONDITION_FAILED,
+ MHD_HTTP_FORBIDDEN,
"{s:s, s:o}",
"error", "insufficient funds",
"history", history);