aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-04-10 16:37:08 +0200
committerChristian Grothoff <christian@grothoff.org>2017-04-10 16:37:08 +0200
commit368b9f8fcbd33cfc3106b2683a376422275a3c23 (patch)
tree5dd69d119d69a035fd271481f2e51782f18f9e4d
parent2684327176f5e4aab35d1c25b32b37a4c065fadd (diff)
add test case for #3887
-rw-r--r--src/exchange-lib/test_exchange_api.c109
-rw-r--r--src/exchange/taler-exchange-httpd.c8
-rw-r--r--src/exchange/taler-exchange-httpd_db.c2
-rw-r--r--src/exchange/taler-exchange-httpd_keystate.c3
-rw-r--r--src/exchange/taler-exchange-httpd_payback.c2
-rw-r--r--src/exchangedb/exchangedb_denomkeys.c5
6 files changed, 126 insertions, 3 deletions
diff --git a/src/exchange-lib/test_exchange_api.c b/src/exchange-lib/test_exchange_api.c
index 700f1b7fc..a331d9d67 100644
--- a/src/exchange-lib/test_exchange_api.c
+++ b/src/exchange-lib/test_exchange_api.c
@@ -1369,6 +1369,7 @@ maint_child_death (void *cls)
GNUNET_break (0 ==
GNUNET_OS_process_kill (exchanged,
SIGUSR1));
+ sleep (5); /* make sure signal was received and processed */
break;
default:
GNUNET_break (0);
@@ -3375,6 +3376,78 @@ run (void *cls)
/* ************** Test /payback API ************* */
+ /* Fill reserve with EUR:5.01, as withdraw fee is 1 ct per config,
+ then withdraw a coin and then have it be paid back. */
+ { .oc = OC_ADMIN_ADD_INCOMING,
+ .label = "payback-create-reserve-1",
+ .expected_response_code = MHD_HTTP_OK,
+ .details.admin_add_incoming.sender_details = "{ \"type\":\"test\", \"bank_uri\":\"http://localhost:8082/\", \"account_number\":42}",
+ .details.admin_add_incoming.transfer_details = "{ \"uuid\":4 }",
+ .details.admin_add_incoming.amount = "EUR:5.01" },
+ /* Withdraw a 5 EUR coin, at fee of 1 ct */
+ { .oc = OC_WITHDRAW_SIGN,
+ .label = "payback-withdraw-coin-1",
+ .expected_response_code = MHD_HTTP_OK,
+ .details.reserve_withdraw.reserve_reference = "payback-create-reserve-1",
+ .details.reserve_withdraw.amount = "EUR:5" },
+ { .oc = OC_REVOKE,
+ .label = "revoke-1",
+ .expected_response_code = MHD_HTTP_OK,
+ .details.revoke.ref = "payback-withdraw-coin-1" },
+ { .oc = OC_PAYBACK,
+ .label = "payback-1",
+ .expected_response_code = MHD_HTTP_OK,
+ .details.payback.ref = "payback-withdraw-coin-1",
+ .details.payback.amount = "EUR:5" },
+
+
+ /* Fill reserve with EUR:1.01, as withdraw fee is 1 ct per config,
+ then withdraw a coin, partially spend it, and then have the rest paid back.
+ (Do not use EUR:5 here as the EUR:5 coin was revoked and we did not
+ bother to create a new one...) */
+ { .oc = OC_ADMIN_ADD_INCOMING,
+ .label = "payback-create-reserve-2",
+ .expected_response_code = MHD_HTTP_OK,
+ .details.admin_add_incoming.sender_details = "{ \"type\":\"test\", \"bank_uri\":\"http://localhost:8082/\", \"account_number\":42}",
+ .details.admin_add_incoming.transfer_details = "{ \"uuid\":5 }",
+ .details.admin_add_incoming.amount = "EUR:1.01" },
+ /* Withdraw a 1 EUR coin, at fee of 1 ct */
+ { .oc = OC_WITHDRAW_SIGN,
+ .label = "payback-withdraw-coin-2",
+ .expected_response_code = MHD_HTTP_OK,
+ .details.reserve_withdraw.reserve_reference = "payback-create-reserve-2",
+ .details.reserve_withdraw.amount = "EUR:1" },
+
+ { .oc = OC_DEPOSIT,
+ .label = "payback-deposit-partial",
+ .expected_response_code = MHD_HTTP_OK,
+ .details.deposit.amount = "EUR:0.5",
+ .details.deposit.coin_ref = "payback-withdraw-coin-2",
+ .details.deposit.wire_details = "{ \"type\":\"test\", \"bank_uri\":\"http://localhost:8082/\", \"account_number\":42 }",
+ .details.deposit.proposal_data = "{ \"items\": [ { \"name\":\"more ice cream\", \"value\":1 } ] }" },
+ { .oc = OC_REVOKE,
+ .label = "revoke-2",
+ .expected_response_code = MHD_HTTP_OK,
+ .details.revoke.ref = "payback-withdraw-coin-2" },
+ { .oc = OC_PAYBACK,
+ .label = "payback-2",
+ .expected_response_code = MHD_HTTP_OK,
+ .details.payback.ref = "payback-withdraw-coin-2",
+ .details.payback.amount = "EUR:0.5" },
+
+ /* Test that revoked coins cannot be withdrawn */
+ { .oc = OC_ADMIN_ADD_INCOMING,
+ .label = "payback-create-reserve-3",
+ .expected_response_code = MHD_HTTP_OK,
+ .details.admin_add_incoming.sender_details = "{ \"type\":\"test\", \"bank_uri\":\"http://localhost:8082/\", \"account_number\":42}",
+ .details.admin_add_incoming.transfer_details = "{ \"uuid\":6 }",
+ .details.admin_add_incoming.amount = "EUR:1.01" },
+ { .oc = OC_WITHDRAW_SIGN,
+ .label = "payback-withdraw-coin-3-revoked",
+ .expected_response_code = MHD_HTTP_NOT_FOUND,
+ .details.reserve_withdraw.reserve_reference = "payback-create-reserve-3",
+ .details.reserve_withdraw.amount = "EUR:1" },
+
/* ************** End of payback API testing************* */
#endif
@@ -3404,6 +3477,40 @@ run (void *cls)
/**
+ * Remove files from previous runs
+ */
+static void
+cleanup_files ()
+{
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+ char *dir;
+
+ cfg = GNUNET_CONFIGURATION_create ();
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_load (cfg,
+ "test_exchange_api.conf"))
+ {
+ GNUNET_break (0);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ exit (77);
+ }
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "exchange",
+ "keydir",
+ &dir));
+ if (GNUNET_YES ==
+ GNUNET_DISK_directory_test (dir,
+ GNUNET_NO))
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_DISK_directory_remove (dir));
+ GNUNET_free (dir);
+ GNUNET_CONFIGURATION_destroy (cfg);
+}
+
+
+
+/**
* Main function for the testcase for the exchange API.
*
* @param argc expected to be 1
@@ -3443,6 +3550,8 @@ main (int argc,
8082);
return 77;
}
+ cleanup_files ();
+
proc = GNUNET_OS_start_process (GNUNET_NO,
GNUNET_OS_INHERIT_STD_ALL,
NULL, NULL, NULL,
diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c
index 6b285a3c3..b40eaf3a6 100644
--- a/src/exchange/taler-exchange-httpd.c
+++ b/src/exchange/taler-exchange-httpd.c
@@ -32,6 +32,7 @@
#include "taler-exchange-httpd_deposit.h"
#include "taler-exchange-httpd_refund.h"
#include "taler-exchange-httpd_reserve.h"
+#include "taler-exchange-httpd_payback.h"
#include "taler-exchange-httpd_wire.h"
#include "taler-exchange-httpd_refresh.h"
#include "taler-exchange-httpd_tracking.h"
@@ -295,6 +296,13 @@ handle_mhd_request (void *cls,
"Only POST is allowed", 0,
&TEH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED },
+ { "/payback", MHD_HTTP_METHOD_POST, "application/json",
+ NULL, 0,
+ &TEH_PAYBACK_handler_payback, MHD_HTTP_OK },
+ { "/refresh/link", NULL, "text/plain",
+ "Only GET is allowed", 0,
+ &TEH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED },
+
{ NULL, NULL, NULL, NULL, 0, 0 }
};
static struct TEH_RequestHandler h404 =
diff --git a/src/exchange/taler-exchange-httpd_db.c b/src/exchange/taler-exchange-httpd_db.c
index 191e2a4b6..57be19708 100644
--- a/src/exchange/taler-exchange-httpd_db.c
+++ b/src/exchange/taler-exchange-httpd_db.c
@@ -192,7 +192,7 @@ calculate_transaction_list_totals (struct TALER_EXCHANGEDB_TransactionList *tl,
}
}
/* spent = spent - refunded */
- if (GNUNET_OK !=
+ if (GNUNET_SYSERR ==
TALER_amount_subtract (&spent,
&spent,
&refunded))
diff --git a/src/exchange/taler-exchange-httpd_keystate.c b/src/exchange/taler-exchange-httpd_keystate.c
index 2b7019594..95ddd04bf 100644
--- a/src/exchange/taler-exchange-httpd_keystate.c
+++ b/src/exchange/taler-exchange-httpd_keystate.c
@@ -308,6 +308,9 @@ reload_keys_denom_iter (void *cls,
if (NULL != revocation_master_sig)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Adding denomination key `%s' to revokation set\n",
+ alias);
res = store_in_map (ctx->revoked_map,
dki);
if (GNUNET_NO == res)
diff --git a/src/exchange/taler-exchange-httpd_payback.c b/src/exchange/taler-exchange-httpd_payback.c
index b4b664f94..7e1c70848 100644
--- a/src/exchange/taler-exchange-httpd_payback.c
+++ b/src/exchange/taler-exchange-httpd_payback.c
@@ -168,7 +168,7 @@ TEH_PAYBACK_handler_payback (struct TEH_RequestHandler *rh,
struct GNUNET_JSON_Specification spec[] = {
TALER_JSON_spec_denomination_public_key ("denom_pub",
&coin.denom_pub),
- TALER_JSON_spec_denomination_signature ("ub_sig",
+ TALER_JSON_spec_denomination_signature ("denom_sig",
&coin.denom_sig),
GNUNET_JSON_spec_fixed_auto ("coin_pub",
&coin.coin_pub),
diff --git a/src/exchangedb/exchangedb_denomkeys.c b/src/exchangedb/exchangedb_denomkeys.c
index 017960277..5ff3b5c51 100644
--- a/src/exchangedb/exchangedb_denomkeys.c
+++ b/src/exchangedb/exchangedb_denomkeys.c
@@ -54,7 +54,10 @@ TALER_EXCHANGEDB_denomination_key_revoke (const char *exchange_base_dir,
ret = GNUNET_SYSERR;
start = GNUNET_TIME_absolute_ntoh (dki->issue.properties.start);
GNUNET_asprintf (&fn,
- "%s" DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR "%llu.rev",
+ "%s" DIR_SEPARATOR_STR
+ TALER_EXCHANGEDB_DIR_DENOMINATION_KEYS DIR_SEPARATOR_STR
+ "%s" DIR_SEPARATOR_STR
+ "%llu.rev",
exchange_base_dir,
alias,
(unsigned long long) start.abs_value_us);