gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-merchant] 04/04: Issuing a refund lookup with a non


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] 04/04: Issuing a refund lookup with a non existent order id.
Date: Tue, 22 May 2018 08:59:26 +0200

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

marcello pushed a commit to branch master
in repository merchant.

commit d194cdb5bb0dbde9daeec75895520269a3ab3c00
Author: Marcello Stanisci <address@hidden>
AuthorDate: Mon May 21 15:17:45 2018 +0200

    Issuing a refund lookup with a non existent order id.
---
 src/include/taler_merchant_testing_lib.h |  3 ++-
 src/lib/merchant_api_refund.c            | 28 +++++++++++++++++++---------
 src/lib/test_merchant_api_new.c          | 12 +++++++++++-
 src/lib/testing_api_cmd_refund.c         | 15 ++++++++++++---
 4 files changed, 44 insertions(+), 14 deletions(-)

diff --git a/src/include/taler_merchant_testing_lib.h 
b/src/include/taler_merchant_testing_lib.h
index 3563151..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);
 
 
 /**
diff --git a/src/lib/merchant_api_refund.c b/src/lib/merchant_api_refund.c
index 812176f..0dbd52f 100644
--- a/src/lib/merchant_api_refund.c
+++ b/src/lib/merchant_api_refund.c
@@ -285,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:
     /**
@@ -298,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_new.c b/src/lib/test_merchant_api_new.c
index d598b37..83e565b 100644
--- a/src/lib/test_merchant_api_new.c
+++ b/src/lib/test_merchant_api_new.c
@@ -470,7 +470,17 @@ run (void *cls,
                                      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.  */
 
diff --git a/src/lib/testing_api_cmd_refund.c b/src/lib/testing_api_cmd_refund.c
index 2abc89a..7dc5683 100644
--- a/src/lib/testing_api_cmd_refund.c
+++ b/src/lib/testing_api_cmd_refund.c
@@ -65,6 +65,8 @@ struct RefundLookupState
 
   const char *increase_reference;
 
+  unsigned int http_code;
+
   struct TALER_TESTING_Interpreter *is;
 };
 
@@ -211,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)
   {
@@ -436,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;
@@ -447,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]