diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-05-04 06:10:41 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-05-04 06:10:41 +0200 |
commit | 455368147695d6f84bdfb814794483d4a0464e56 (patch) | |
tree | a66b9e479ff1548884f611df653b0ed7a9cd0514 | |
parent | 910e01d1c154390a7e724703bdd9a14046245d2c (diff) |
fix issues in tracking API and tracking API test, resolves #4399
-rw-r--r-- | src/exchange-lib/exchange_api_wire_deposits.c | 12 | ||||
-rw-r--r-- | src/exchange-lib/test_exchange_api.c | 113 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_responses.c | 12 |
3 files changed, 99 insertions, 38 deletions
diff --git a/src/exchange-lib/exchange_api_wire_deposits.c b/src/exchange-lib/exchange_api_wire_deposits.c index bcb29e872..446ac0037 100644 --- a/src/exchange-lib/exchange_api_wire_deposits.c +++ b/src/exchange-lib/exchange_api_wire_deposits.c @@ -96,12 +96,12 @@ handle_wire_deposits_finished (void *cls, struct TALER_ExchangePublicKeyP exchange_pub; struct TALER_ExchangeSignatureP exchange_sig; struct GNUNET_JSON_Specification spec[] = { + TALER_JSON_spec_amount ("total", &total_amount), + GNUNET_JSON_spec_fixed_auto ("merchant_pub", &merchant_pub), GNUNET_JSON_spec_fixed_auto ("H_wire", &h_wire), - GNUNET_JSON_spec_fixed_auto ("exchange_pub", &exchange_pub), + GNUNET_JSON_spec_json ("deposits", &details_j), GNUNET_JSON_spec_fixed_auto ("exchange_sig", &exchange_sig), - GNUNET_JSON_spec_fixed_auto ("merchant_pub", &merchant_pub), - TALER_JSON_spec_amount ("total_amount", &total_amount), - GNUNET_JSON_spec_json ("details", &details_j), + GNUNET_JSON_spec_fixed_auto ("exchange_pub", &exchange_pub), GNUNET_JSON_spec_end() }; @@ -129,10 +129,10 @@ handle_wire_deposits_finished (void *cls, struct json_t *detail_j = json_array_get (details_j, i); struct GNUNET_JSON_Specification spec_detail[] = { GNUNET_JSON_spec_fixed_auto ("H_contract", &detail->h_contract), - TALER_JSON_spec_amount ("deposit_value", &detail->coin_value), - TALER_JSON_spec_amount ("deposit_fee", &detail->coin_fee), GNUNET_JSON_spec_uint64 ("transaction_id", &detail->transaction_id), GNUNET_JSON_spec_fixed_auto ("coin_pub", &detail->coin_pub), + TALER_JSON_spec_amount ("deposit_value", &detail->coin_value), + TALER_JSON_spec_amount ("deposit_fee", &detail->coin_fee), GNUNET_JSON_spec_end() }; diff --git a/src/exchange-lib/test_exchange_api.c b/src/exchange-lib/test_exchange_api.c index d05c54a80..05d18633f 100644 --- a/src/exchange-lib/test_exchange_api.c +++ b/src/exchange-lib/test_exchange_api.c @@ -514,8 +514,13 @@ struct Command struct TALER_EXCHANGE_WireDepositsHandle *wdh; /** - * Reference to a /deposit/wtid command. If set, we use the - * WTID from that command. + * Reference to a command providing a WTID. If set, we use the + * WTID from that command. The command can be either an + * #OC_DEPOSIT_WTID or an #OC_CHECK_BANK_TRANSFER. In the + * case of the bank transfer, we check that the total amount + * claimed by the exchange matches the total amount transferred + * by the bank. In the case of a /deposit/wtid, we check + * that the wire details match. */ const char *wtid_ref; @@ -524,6 +529,13 @@ struct Command */ struct TALER_WireTransferIdentifierRawP wtid; + /** + * What is the expected total amount? Only used if + * @e expected_response_code was #MHD_HTTP_OK. + */ + const char *total_amount_expected; + + /* TODO: may want to add list of deposits we expected to see aggregated here in the future. */ @@ -550,12 +562,6 @@ struct Command const char *bank_transfer_ref; /** - * What is the expected total amount? Only used if - * @e expected_response_code was #MHD_HTTP_OK. - */ - struct TALER_Amount total_amount_expected; - - /** * Wire transfer identifier, set if #MHD_HTTP_OK was the response code. */ struct TALER_WireTransferIdentifierRawP wtid; @@ -1362,6 +1368,7 @@ wire_deposits_cb (void *cls, struct InterpreterState *is = cls; struct Command *cmd = &is->commands[is->ip]; const struct Command *ref; + struct TALER_Amount expected_amount; cmd->details.wire_deposits.wdh = NULL; if (cmd->expected_response_code != http_status) @@ -1377,11 +1384,16 @@ wire_deposits_cb (void *cls, switch (http_status) { case MHD_HTTP_OK: - ref = find_command (is, - cmd->details.wire_deposits.wtid_ref); - GNUNET_assert (NULL != ref); + if (GNUNET_OK != + TALER_string_to_amount (cmd->details.wire_deposits.total_amount_expected, + &expected_amount)) + { + GNUNET_break (0); + fail (is); + return; + } if (0 != TALER_amount_cmp (total_amount, - &ref->details.deposit_wtid.total_amount_expected)) + &expected_amount)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Total amount missmatch to command %s\n", @@ -1391,28 +1403,65 @@ wire_deposits_cb (void *cls, fail (is); return; } - if (NULL != ref->details.deposit_wtid.deposit_ref) + ref = find_command (is, + cmd->details.wire_deposits.wtid_ref); + GNUNET_assert (NULL != ref); + switch (ref->oc) { - const struct Command *dep; - struct GNUNET_HashCode hw; - - dep = find_command (is, - ref->details.deposit_wtid.deposit_ref); - GNUNET_assert (NULL != dep); - GNUNET_CRYPTO_hash (dep->details.deposit.wire_details, - strlen (dep->details.deposit.wire_details), - &hw); - if (0 != memcmp (&hw, - h_wire, - sizeof (struct GNUNET_HashCode))) + case OC_DEPOSIT_WTID: + if (NULL != ref->details.deposit_wtid.deposit_ref) + { + const struct Command *dep; + struct GNUNET_HashCode hw; + json_t *wire; + + dep = find_command (is, + ref->details.deposit_wtid.deposit_ref); + GNUNET_assert (NULL != dep); + wire = json_loads (dep->details.deposit.wire_details, + JSON_REJECT_DUPLICATES, + NULL); + TALER_JSON_hash (wire, + &hw); + json_decref (wire); + if (0 != memcmp (&hw, + h_wire, + sizeof (struct GNUNET_HashCode))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Wire hash missmatch to command %s\n", + cmd->label); + json_dumpf (json, stderr, 0); + fail (is); + return; + } + } + break; + case OC_CHECK_BANK_TRANSFER: + if (GNUNET_OK != + TALER_string_to_amount (ref->details.check_bank_transfer.amount, + &expected_amount)) + { + GNUNET_break (0); + fail (is); + return; + } + if (0 != TALER_amount_cmp (total_amount, + &expected_amount)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Wire hash missmatch to command %s\n", + "Total amount missmatch to command %s\n", + http_status, cmd->label); json_dumpf (json, stderr, 0); fail (is); return; } + break; + default: + GNUNET_break (0); + fail (is); + return; } break; default: @@ -2680,6 +2729,18 @@ run (void *cls) .details.deposit_wtid.deposit_ref = "deposit-simple", .details.deposit_wtid.bank_transfer_ref = "check_bank_transfer-499c" }, + { .oc = OC_WIRE_DEPOSITS, + .label = "wire-deposits-sucess-bank", + .expected_response_code = MHD_HTTP_OK, + .details.wire_deposits.wtid_ref = "check_bank_transfer-99c1", + .details.wire_deposits.total_amount_expected = "EUR:0.99" }, + + { .oc = OC_WIRE_DEPOSITS, + .label = "wire-deposits-sucess-wtid", + .expected_response_code = MHD_HTTP_OK, + .details.wire_deposits.wtid_ref = "deposit-wtid-ok", + .details.wire_deposits.total_amount_expected = "EUR:4.99" }, + /* TODO: trigger aggregation logic and then check the cases where tracking succeeds! */ diff --git a/src/exchange/taler-exchange-httpd_responses.c b/src/exchange/taler-exchange-httpd_responses.c index 7bac0d88c..c8a72f499 100644 --- a/src/exchange/taler-exchange-httpd_responses.c +++ b/src/exchange/taler-exchange-httpd_responses.c @@ -1184,14 +1184,14 @@ TMH_RESPONSE_reply_wire_deposit_details (struct MHD_Connection *connection, &dd, sizeof (struct TALER_WireDepositDetailP)); json_array_append (deposits, - json_pack ("{s:o, s:o, s:o, s:I, s:o}", - "deposit_value", TALER_JSON_from_amount (&wdd_pos->deposit_value), - "deposit_fee", TALER_JSON_from_amount (&wdd_pos->deposit_fee), + json_pack ("{s:o, s:I, s:o, s:o, s:o}", "H_contract", GNUNET_JSON_from_data (&wdd_pos->h_contract, sizeof (struct GNUNET_HashCode)), "transaction_id", (json_int_t) wdd_pos->transaction_id, "coin_pub", GNUNET_JSON_from_data (&wdd_pos->coin_pub, - sizeof (struct TALER_CoinSpendPublicKeyP)))); + sizeof (struct TALER_CoinSpendPublicKeyP)), + "deposit_value", TALER_JSON_from_amount (&wdd_pos->deposit_value), + "deposit_fee", TALER_JSON_from_amount (&wdd_pos->deposit_fee))); } wdp.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_WIRE_DEPOSIT); wdp.purpose.size = htonl (sizeof (struct TALER_WireDepositDataPS)); @@ -1206,11 +1206,11 @@ TMH_RESPONSE_reply_wire_deposit_details (struct MHD_Connection *connection, &sig); return TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_OK, - "{s:o, s:o, s:o, s:o}", + "{s:o, s:o, s:o, s:o, s:o, s:o}", "total", TALER_JSON_from_amount (total), "merchant_pub", GNUNET_JSON_from_data (merchant_pub, sizeof (struct TALER_MerchantPublicKeyP)), - "h_wire", GNUNET_JSON_from_data (h_wire, + "H_wire", GNUNET_JSON_from_data (h_wire, sizeof (struct GNUNET_HashCode)), "deposits", deposits, "exchange_sig", GNUNET_JSON_from_data (&sig, |