gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-exchange] branch master updated (2684327 -> 17a74ee)


From: gnunet
Subject: [GNUnet-SVN] [taler-exchange] branch master updated (2684327 -> 17a74ee)
Date: Mon, 10 Apr 2017 16:47:48 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a change to branch master
in repository exchange.

    from 2684327  preparations for testing /payback API
     new 368b9f8  add test case for #3887
     new 17a74ee  expand /payback tests

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/exchange-lib/test_exchange_api.c         | 135 +++++++++++++++++++++++++++
 src/exchange/taler-exchange-httpd.c          |   8 ++
 src/exchange/taler-exchange-httpd_db.c       |   2 +-
 src/exchange/taler-exchange-httpd_deposit.c  |   1 +
 src/exchange/taler-exchange-httpd_keystate.c |   3 +
 src/exchange/taler-exchange-httpd_payback.c  |   2 +-
 src/exchangedb/exchangedb_denomkeys.c        |   5 +-
 7 files changed, 153 insertions(+), 3 deletions(-)

diff --git a/src/exchange-lib/test_exchange_api.c 
b/src/exchange-lib/test_exchange_api.c
index 700f1b7..c32a21b 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,104 @@ 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:2.02, as withdraw fee is 1 ct per config,
+       then withdraw two coin, partially spend one, and then have the rest 
paid back.
+       Check deposit of other coin fails.
+       (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:2.02" },
+    /* Withdraw a 1 EUR coin, at fee of 1 ct */
+    { .oc = OC_WITHDRAW_SIGN,
+      .label = "payback-withdraw-coin-2a",
+      .expected_response_code = MHD_HTTP_OK,
+      .details.reserve_withdraw.reserve_reference = "payback-create-reserve-2",
+      .details.reserve_withdraw.amount = "EUR:1" },
+    /* Withdraw a 1 EUR coin, at fee of 1 ct */
+    { .oc = OC_WITHDRAW_SIGN,
+      .label = "payback-withdraw-coin-2b",
+      .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-2a",
+      .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-2a" },
+    { .oc = OC_PAYBACK,
+      .label = "payback-2",
+      .expected_response_code = MHD_HTTP_OK,
+      .details.payback.ref = "payback-withdraw-coin-2a",
+      .details.payback.amount = "EUR:0.5" },
+    { .oc = OC_DEPOSIT,
+      .label = "payback-deposit-revoked",
+      .expected_response_code = MHD_HTTP_NOT_FOUND,
+      .details.deposit.amount = "EUR:1",
+      .details.deposit.coin_ref = "payback-withdraw-coin-2b",
+      .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 } ] }" },
+
+    /* Test deposit fails after payback, with proof in payback */
+    /* FIXME: #3887: right now, the exchange will never return the
+       coin's transaction history with payback data, as we get a 404 on the 
DK! */
+    { .oc = OC_DEPOSIT,
+      .label = "payback-deposit-partial-after-payback",
+      .expected_response_code = MHD_HTTP_NOT_FOUND,
+      .details.deposit.amount = "EUR:0.5",
+      .details.deposit.coin_ref = "payback-withdraw-coin-2a",
+      .details.deposit.wire_details = "{ \"type\":\"test\", 
\"bank_uri\":\"http://localhost:8082/\";, \"account_number\":42  }",
+      .details.deposit.proposal_data = "{ \"items\": [ { \"name\":\"extra ice 
cream\", \"value\":1 } ] }" },
+
+
+    /* 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 +3503,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 +3576,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 6b285a3..b40eaf3 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 191e2a4..57be197 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_deposit.c 
b/src/exchange/taler-exchange-httpd_deposit.c
index 3ff2475..8002d51 100644
--- a/src/exchange/taler-exchange-httpd_deposit.c
+++ b/src/exchange/taler-exchange-httpd_deposit.c
@@ -196,6 +196,7 @@ TEH_DEPOSIT_handler_deposit (struct TEH_RequestHandler *rh,
                                        TEH_KS_DKU_DEPOSIT);
   if (NULL == dki)
   {
+    /* FIXME: #3887: if DK was revoked, we might want to give a 403 and not a 
404! */
     TEH_KS_release (key_state);
     TALER_LOG_WARNING ("Unknown denomination key in /deposit request\n");
     return TEH_RESPONSE_reply_arg_unknown (connection,
diff --git a/src/exchange/taler-exchange-httpd_keystate.c 
b/src/exchange/taler-exchange-httpd_keystate.c
index 2b70195..95ddd04 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 b4b664f..7e1c708 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 0179602..5ff3b5c 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);

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]