gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-merchant] branch master updated (c85dd0f -> d194cdb)


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] branch master updated (c85dd0f -> d194cdb)
Date: Tue, 22 May 2018 08:59:22 +0200

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

marcello pushed a change to branch master
in repository merchant.

    from c85dd0f  adapt to latest twister changes.
     new 2f6093e  Refund test CMD takes expected HTTP code.
     new 07f3974  Increase refund on a unpaid contract.
     new 11c2eb2  Attempting refund increase on a non existent order id.
     new d194cdb  Issuing a refund lookup with a non existent order id.

The 4 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/include/taler_merchant_testing_lib.h |  6 ++-
 src/lib/merchant_api_refund.c            | 56 ++++++++++++++++++-------
 src/lib/test_merchant_api.conf           |  2 +-
 src/lib/test_merchant_api_new.c          | 72 ++++++++++++++++++++++++++++----
 src/lib/testing_api_cmd_refund.c         | 23 +++++++---
 5 files changed, 127 insertions(+), 32 deletions(-)

diff --git a/src/include/taler_merchant_testing_lib.h 
b/src/include/taler_merchant_testing_lib.h
index 304a16b..97e03d9 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -219,7 +219,8 @@ TALER_TESTING_cmd_refund_lookup
    struct GNUNET_CURL_Context *ctx,
    const char *increase_reference,
    const char *pay_reference,
-   const char *order_id);
+   const char *order_id,
+   unsigned int http_code);
 
 
 /**
@@ -233,7 +234,8 @@ TALER_TESTING_cmd_refund_increase
    const char *reason,
    const char *order_id,
    const char *refund_amount,
-   const char *refund_fee);
+   const char *refund_fee,
+   unsigned int http_code);
 
 
 /**
diff --git a/src/lib/merchant_api_refund.c b/src/lib/merchant_api_refund.c
index 2f02735..0dbd52f 100644
--- a/src/lib/merchant_api_refund.c
+++ b/src/lib/merchant_api_refund.c
@@ -121,9 +121,14 @@ handle_refund_increase_finished (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Backend didn't even return from POST /refund\n");
     return;
+
+  /* Good to hand everything to the callback, as all
+   * the logic is actually there.  */
   case MHD_HTTP_OK:
+  case MHD_HTTP_BAD_REQUEST:
+  case MHD_HTTP_NOT_FOUND:
     rio->cb (rio->cb_cls,
-             MHD_HTTP_OK,
+             response_code,
              TALER_EC_NONE,
              json);
     break;
@@ -133,13 +138,22 @@ handle_refund_increase_finished (void *cls,
      * NOTE that json must be a Taler-specific error object (FIXME,
      * need a link to error objects at docs)
      */
-    json_unpack ((json_t *) json,
-                 "{s:s, s:I, s:s}",
-                 "error", &error,
-                 "code", &code,
-                 "hint", &hint);
+    if (-1 == json_unpack
+        ((json_t *) json,
+         "{s:s, s:I, s:s}",
+         "error", &error,
+         "code", &code,
+         "hint", &hint))
+    
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "/refund failed (HTTP code: %lu), backend did "
+                "not give a valid error object\n", response_code);
+      break;
+    }
+
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Failed POST /refund, error: %s, code: %d, hint: %s\n",
+                "/refund, error: %s, code: %d, hint: %s\n",
                 error,
                 code,
                 hint);
@@ -271,12 +285,13 @@ handle_refund_lookup_finished (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Backend didn't even return from GET /refund\n");
     return;
+
   case MHD_HTTP_OK:
+  case MHD_HTTP_NOT_FOUND:
     rlo->cb (rlo->cb_cls,
-             MHD_HTTP_OK,
+             response_code,
              TALER_EC_NONE,
              json);
-    TALER_MERCHANT_refund_lookup_cancel (rlo);
     break;
   default:
     /**
@@ -284,15 +299,24 @@ handle_refund_lookup_finished (void *cls,
      * NOTE that json must be a Taler-specific error object (FIXME,
      * need a link to error objects at docs)
      */
-    json_unpack ((json_t *) json,
-                 "{s:s, s:I, s:s}",
-                 "error", &error,
-                 "code", &code);
+    if (-1 == json_unpack ((json_t *) json,
+        "{s:s, s:I, s:s}",
+        "error", &error,
+        "code", &code))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Failed GET /refund, error: %s, code: %d\n",
+                  error,
+                  code);
+      break;
+    } 
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Failed GET /refund, error: %s, code: %d\n",
-                error,
-                code);
+                "Failed /refund lookup, backend did not give"
+                " a valid error object, HTTP code was %lu\n",
+                response_code);
   }
+
+  TALER_MERCHANT_refund_lookup_cancel (rlo);
 }
 
 
diff --git a/src/lib/test_merchant_api.conf b/src/lib/test_merchant_api.conf
index 7f1d086..7b79170 100644
--- a/src/lib/test_merchant_api.conf
+++ b/src/lib/test_merchant_api.conf
@@ -113,7 +113,7 @@ ACTIVE_dtip = YES
 [exchange-kudos]
 MASTER_KEY = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG
 CURRENCY = KUDOS
-URL = http://localhost:8081/
+BASE_URL = http://localhost:8081/
 
 
 # Auditors must be in sections "auditor-", the rest of the section
diff --git a/src/lib/test_merchant_api_new.c b/src/lib/test_merchant_api_new.c
index aaa4a07..83e565b 100644
--- a/src/lib/test_merchant_api_new.c
+++ b/src/lib/test_merchant_api_new.c
@@ -455,20 +455,76 @@ run (void *cls,
        10,
        10),
 
-    TALER_TESTING_cmd_refund_increase ("refund-increase-1",
-                                       merchant_url,
-                                       is->ctx,
-                                       "refund test",
-                                       "1",
-                                       "EUR:0.1",
-                                       "EUR:0.01"),
+    TALER_TESTING_cmd_refund_increase
+      ("refund-increase-1",
+       merchant_url,
+       is->ctx,
+       "refund test",
+       "1",
+       "EUR:0.1",
+       "EUR:0.01",
+       MHD_HTTP_OK),
 
     TALER_TESTING_cmd_refund_lookup ("refund-lookup-1",
                                      merchant_url,
                                      is->ctx,
                                      "refund-increase-1",
                                      "deposit-simple",
-                                     "1"),
+                                     "1",
+                                     MHD_HTTP_OK),
+
+    /* Trying to pick up a non existent refund.  */
+    TALER_TESTING_cmd_refund_lookup ("refund-lookup-non-existent",
+                                     merchant_url,
+                                     is->ctx,
+                                     "refund-increase-1",
+                                     "deposit-simple",
+                                     "non-existend-id",
+                                     MHD_HTTP_NOT_FOUND),
+
+    /* Test /refund on a contract that was never paid.  */
+
+    TALER_TESTING_cmd_proposal
+      ("create-proposal-not-to-be-paid",
+       merchant_url,
+       is->ctx,
+       MHD_HTTP_OK,
+       "{\"max_fee\":\
+          {\"currency\":\"EUR\",\
+           \"value\":0,\
+           \"fraction\":50000000},\
+        \"order_id\":\"1-unpaid\",\
+        \"refund_deadline\":\"\\/Date(0)\\/\",\
+        \"pay_deadline\":\"\\/Date(99999999999)\\/\",\
+        \"amount\":\
+          {\"currency\":\"EUR\",\
+           \"value\":5,\
+           \"fraction\":0},\
+        \"summary\": \"useful product\",\
+        \"fulfillment_url\": \"https://example.com/\",\
+        \"products\": [ {\"description\":\"ice cream\",\
+                         \"value\":\"{EUR:5}\"} ] }",
+        NULL),
+
+    TALER_TESTING_cmd_refund_increase
+      ("refund-increase-unpaid-proposal",
+       merchant_url,
+       is->ctx,
+       "refund test",
+       "1-unpaid",
+       "EUR:0.1",
+       "EUR:0.01",
+       MHD_HTTP_BAD_REQUEST),
+
+    TALER_TESTING_cmd_refund_increase
+      ("refund-increase-unpaid-proposal",
+       merchant_url,
+       is->ctx,
+       "refund test",
+       "non-existent-id",
+       "EUR:0.1",
+       "EUR:0.01",
+       MHD_HTTP_NOT_FOUND),
 
     /* Test tipping.  */
     TALER_TESTING_cmd_fakebank_transfer_with_instance
diff --git a/src/lib/testing_api_cmd_refund.c b/src/lib/testing_api_cmd_refund.c
index 7cae8c6..7dc5683 100644
--- a/src/lib/testing_api_cmd_refund.c
+++ b/src/lib/testing_api_cmd_refund.c
@@ -47,6 +47,8 @@ struct RefundIncreaseState
   const char *reason;
 
   struct TALER_TESTING_Interpreter *is;
+
+  unsigned int http_code;
 };
 
 struct RefundLookupState
@@ -63,6 +65,8 @@ struct RefundLookupState
 
   const char *increase_reference;
 
+  unsigned int http_code;
+
   struct TALER_TESTING_Interpreter *is;
 };
 
@@ -127,7 +131,7 @@ refund_increase_cb (void *cls,
   struct RefundIncreaseState *ris = cls;
 
   ris->rio = NULL;
-  if (MHD_HTTP_OK != http_status)
+  if (ris->http_code != http_status)
     TALER_TESTING_FAIL (ris->is);
 
   TALER_TESTING_interpreter_next (ris->is);
@@ -209,13 +213,18 @@ refund_lookup_cb (void *cls,
   const json_t *arr;
 
   rls->rlo = NULL;
-  if (MHD_HTTP_OK != http_status)
+  if (rls->http_code != http_status)
     TALER_TESTING_FAIL (rls->is);
 
   map = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO);
   arr = json_object_get (obj, "refund_permissions");
   if (NULL == arr)
-    TALER_TESTING_FAIL (rls->is);
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Tolerating a refund permission not found\n");
+    TALER_TESTING_interpreter_next (rls->is);
+    return;
+  }
 
   json_array_foreach (arr, index, elem)
   {
@@ -400,7 +409,8 @@ TALER_TESTING_cmd_refund_increase
    const char *reason,
    const char *order_id,
    const char *refund_amount,
-   const char *refund_fee)
+   const char *refund_fee,
+   unsigned int http_code)
 {
   struct RefundIncreaseState *ris;
   struct TALER_TESTING_Command cmd;
@@ -412,6 +422,7 @@ TALER_TESTING_cmd_refund_increase
   ris->refund_amount = refund_amount;
   ris->refund_fee = refund_fee;
   ris->reason = reason;
+  ris->http_code = http_code;
 
   cmd.cls = ris;
   cmd.label = label;
@@ -432,7 +443,8 @@ TALER_TESTING_cmd_refund_lookup
    struct GNUNET_CURL_Context *ctx,
    const char *increase_reference,
    const char *pay_reference,
-   const char *order_id)
+   const char *order_id,
+   unsigned int http_code)
 {
   struct RefundLookupState *rls;
   struct TALER_TESTING_Command cmd;
@@ -443,6 +455,7 @@ TALER_TESTING_cmd_refund_lookup
   rls->order_id = order_id;
   rls->pay_reference = pay_reference;
   rls->increase_reference = increase_reference;
+  rls->http_code = http_code;
 
   cmd.cls = rls;
   cmd.label = label;

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



reply via email to

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