gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-merchant] 01/02: Fix "insufficient funds" error case


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] 01/02: Fix "insufficient funds" error case.
Date: Tue, 22 May 2018 14:36:21 +0200

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

marcello pushed a commit to branch master
in repository merchant.

commit 7ca1490976ecff68fa57c37761cb4b9f1840ba7f
Author: Marcello Stanisci <address@hidden>
AuthorDate: Tue May 22 14:30:56 2018 +0200

    Fix "insufficient funds" error case.
    
    The test case didn't firstly create the tip
    reserve where the "insufficient funds" error
    was supposed to be caused.
---
 src/backend/taler-merchant-httpd_tip-authorize.c | 26 +++++++++++++-
 src/lib/test_merchant_api.conf                   | 14 ++++++--
 src/lib/test_merchant_api_new.c                  | 44 +++++++++++++++++++++++-
 3 files changed, 79 insertions(+), 5 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_tip-authorize.c 
b/src/backend/taler-merchant-httpd_tip-authorize.c
index ebef344..58ee405 100644
--- a/src/backend/taler-merchant-httpd_tip-authorize.c
+++ b/src/backend/taler-merchant-httpd_tip-authorize.c
@@ -109,6 +109,11 @@ struct TipAuthContext
    * Flag set to #GNUNET_YES when we have parsed the incoming JSON already.
    */
   int parsed_json;
+
+  /**
+   * Error code witnessing what the Exchange complained about.
+   */
+  enum TALER_ErrorCode exchange_ec;
 };
 
 
@@ -170,10 +175,12 @@ handle_status (void *cls,
   tac->rsh = NULL;
   if (MHD_HTTP_OK != http_status)
   {
+
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 _("Failed to obtain tipping reserve status from exchange 
(%u/%d)\n"),
                 http_status,
                 ec);
+    tac->exchange_ec = ec;
     MHD_resume_connection (tac->connection);
     TMH_trigger_daemon ();
     return;
@@ -394,7 +401,7 @@ MH_handler_tip_authorize (struct TMH_RequestHandler *rh,
   }
 
   /* handle irrecoverable errors */
-  if (TALER_EC_NONE != ec)
+  if (TALER_EC_NONE != (ec | tac->exchange_ec))
   {
     unsigned int rc;
     const char *msg;
@@ -418,6 +425,23 @@ MH_handler_tip_authorize (struct TMH_RequestHandler *rh,
       msg = "Failed to approve tip: internal server error";
       break;
     }
+
+    /* If the exchange complained earlier, we do
+     * override what the database returned.  */
+    switch (tac->exchange_ec)
+    {
+    case TALER_EC_RESERVE_STATUS_UNKNOWN:
+      rc = MHD_HTTP_NOT_FOUND;
+      msg = "Exchange does not find any reserve having this key";
+      /* We override what the DB returned, as an exchange error
+       * is more important.  */
+      ec = TALER_EC_TIP_AUTHORIZE_RESERVE_UNKNOWN; 
+      break;
+    default:
+      /* This makes the compiler silent.  */
+      break;
+    }
+
     return TMH_RESPONSE_reply_rc (connection,
                                   rc,
                                   ec,
diff --git a/src/lib/test_merchant_api.conf b/src/lib/test_merchant_api.conf
index 7b79170..2d4a36a 100644
--- a/src/lib/test_merchant_api.conf
+++ b/src/lib/test_merchant_api.conf
@@ -62,6 +62,14 @@ TIP_EXCHANGE = http://localhost:8081/
 TIP_RESERVE_PRIV_FILENAME = ${TALER_CONFIG_HOME}/merchant/reserve/dtip.priv
 NAME = Test Tipping Merchant 2
 
+[instance-nulltip]
+KEYFILE = ${TALER_CONFIG_HOME}/merchant/nulltip.priv
+TIP_EXCHANGE = http://localhost:8081/
+# This key will NEVER be used to create a reserve, so
+# as to check tip authorization against a non-reserve
+# key.
+TIP_RESERVE_PRIV_FILENAME = ${TALER_CONFIG_HOME}/merchant/reserve/nulltip.priv
+NAME = Test Null-Tipping Merchant
 
 # Account of the MERCHANT
 [account-merchant]
@@ -94,6 +102,8 @@ HONOR_tip = YES
 # Accept payments to this account in instance-dtip
 HONOR_dtip = YES
 
+HONOR_nulltip = YES
+
 # Advertise in new contracts of instance-default
 ACTIVE_default = YES
 
@@ -104,9 +114,7 @@ ACTIVE_tor = YES
 ACTIVE_tip = YES
 
 # Advertise in new contracts of instance-default
-ACTIVE_dtip = YES
-
-
+ACTIVE_nulltip = YES
 
 # Sections starting with "exchange-" specify trusted exchanges
 # (by the merchant)
diff --git a/src/lib/test_merchant_api_new.c b/src/lib/test_merchant_api_new.c
index b9028cf..e2b1c98 100644
--- a/src/lib/test_merchant_api_new.c
+++ b/src/lib/test_merchant_api_new.c
@@ -651,6 +651,25 @@ run (void *cls,
                                      "tip 2",
                                      "EUR:5.01"),
 
+
+    #if 0
+    /* This command tests the authorization of tip
+     * against a reserve that does not exist.  This is
+     * implemented by passing a "tip instance" that
+     * specifies a reserve key that was never used to
+     * actually create a reserve.  */
+    TALER_TESTING_cmd_tip_authorize_with_ec
+      ("authorize-tip-null",
+       merchant_url,
+       exchange_url,
+       is->ctx,
+       MHD_HTTP_NOT_FOUND,
+       "nulltip",
+       "tip 2",
+       "EUR:5.01",
+       TALER_EC_TIP_AUTHORIZE_RESERVE_UNKNOWN),
+    #endif
+
     TALER_TESTING_cmd_tip_query ("query-tip-1",
                                  merchant_url,
                                  is->ctx,
@@ -699,6 +718,29 @@ run (void *cls,
                                               "EUR:10.02", // pick
                                               "EUR:10.02", // auth
                                               "EUR:10.02"), // ava
+
+    TALER_TESTING_cmd_fakebank_transfer_with_instance
+      ("create-reserve-insufficient-funds",
+       "EUR:1.01",
+       fakebank_url,
+       USER_ACCOUNT_NO,
+       EXCHANGE_ACCOUNT_NO,
+       USER_LOGIN_NAME,
+       USER_LOGIN_PASS,
+       "dtip",
+       EXCHANGE_URL,
+       CONFIG_FILE),
+
+    TALER_TESTING_cmd_check_bank_transfer
+      ("check_bank_transfer-insufficient-tip-funds",
+       EXCHANGE_URL,
+       "EUR:1.01",
+       USER_ACCOUNT_NO,
+       EXCHANGE_ACCOUNT_NO),
+
+    CMD_EXEC_WIREWATCH
+      ("wirewatch-insufficient-tip-funds"),
+
     TALER_TESTING_cmd_tip_authorize_with_ec
       ("authorize-tip-3-insufficient-funds",
        merchant_url,
@@ -707,7 +749,7 @@ run (void *cls,
        MHD_HTTP_PRECONDITION_FAILED,
        "dtip",
        "tip 3",
-       "EUR:5.01",
+       "EUR:2.02",
        TALER_EC_TIP_AUTHORIZE_INSUFFICIENT_FUNDS),
 
     TALER_TESTING_cmd_tip_authorize_with_ec

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



reply via email to

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