gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated: tests for merchant account inact


From: gnunet
Subject: [taler-merchant] branch master updated: tests for merchant account inactivation
Date: Tue, 07 Jul 2020 23:05:42 +0200

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

jonathan-buchanan pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 0203e5d  tests for merchant account inactivation
0203e5d is described below

commit 0203e5d83d55d7eed0b6cc669af8750116c4448e
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
AuthorDate: Tue Jul 7 17:05:32 2020 -0400

    tests for merchant account inactivation
---
 src/include/taler_merchant_testing_lib.h   |  29 ++++++
 src/testing/test_merchant_api.c            |  48 +++++++--
 src/testing/testing_api_cmd_get_instance.c | 156 +++++++++++++++++++++++------
 3 files changed, 194 insertions(+), 39 deletions(-)

diff --git a/src/include/taler_merchant_testing_lib.h 
b/src/include/taler_merchant_testing_lib.h
index 8320100..e1908fd 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -216,6 +216,35 @@ TALER_TESTING_cmd_merchant_get_instance (const char *label,
                                          const char *instance_reference);
 
 
+/**
+ * Define a "GET instance" CMD that compares accounts returned.
+ *
+ * @param label command label.
+ * @param merchant_url base URL of the merchant serving the
+ *        GET /instances/$ID request.
+ * @param instance_id the ID of the instance to query
+ * @param http_status expected HTTP response code.
+ * @param instance_reference reference to a "POST /instances" or "PATCH 
/instances/$ID" CMD
+ *        that will provide what we expect the backend to return to us
+ * @param active_accounts the accounts the merchant is actively using.
+ * @param active_accounts_length length of @e active_accounts.
+ * @param inactive_accounts the accounts the merchant is no longer using.
+ * @param inactive_accounts_length length of @e inactive_accounts.
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_get_instance2 (const char *label,
+                                          const char *merchant_url,
+                                          const char *instance_id,
+                                          unsigned int http_status,
+                                          const char *instance_reference,
+                                          const char *active_accounts[],
+                                          unsigned int active_accounts_length,
+                                          const char *inactive_accounts[],
+                                          unsigned int
+                                          inactive_accounts_length);
+
+
 /**
  * Define a "PURGE instance" CMD.
  *
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index eeaec91..e79c9ab 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -961,7 +961,9 @@ run (void *cls,
   };
 
   const char *payto_uris[] = {
-    PAYTO_I1
+    PAYTO_I1,
+    "payto://sepa/CH9300762011623852957" /* Just for testing account
+                                            inactivation. */
   };
   struct TALER_TESTING_Command commands[] = {
     TALER_TESTING_cmd_config ("config",
@@ -990,7 +992,7 @@ run (void *cls,
     TALER_TESTING_cmd_merchant_patch_instance ("instance-patch-i1",
                                                merchant_url,
                                                "i1",
-                                               1,
+                                               2,
                                                payto_uris,
                                                "bob-the-merchant",
                                                json_pack ("{s:s}",
@@ -1005,11 +1007,43 @@ run (void *cls,
                                                GNUNET_TIME_UNIT_MINUTES,
                                                GNUNET_TIME_UNIT_MINUTES,
                                                MHD_HTTP_NO_CONTENT),
-    TALER_TESTING_cmd_merchant_get_instance ("instances-get-i1-2",
-                                             merchant_url,
-                                             "i1",
-                                             MHD_HTTP_OK,
-                                             "instance-patch-i1"),
+    TALER_TESTING_cmd_merchant_get_instance2 ("instances-get-i1-2",
+                                              merchant_url,
+                                              "i1",
+                                              MHD_HTTP_OK,
+                                              "instance-patch-i1",
+                                              payto_uris,
+                                              2,
+                                              NULL,
+                                              0),
+    TALER_TESTING_cmd_merchant_patch_instance (
+      "instance-patch-i1-inactivate-account",
+      merchant_url,
+      "i1",
+      1,
+      payto_uris,
+      "bob-the-merchant",
+      json_pack ("{s:s}",
+                 "street",
+                 "bobstreet"),
+      json_pack ("{s:s}",
+                 "street",
+                 "bobjuryst"),
+      "EUR:0.1",
+      4,
+      "EUR:0.5",
+      GNUNET_TIME_UNIT_MINUTES,
+      GNUNET_TIME_UNIT_MINUTES,
+      MHD_HTTP_NO_CONTENT),
+    TALER_TESTING_cmd_merchant_get_instance2 ("instances-get-i1-3",
+                                              merchant_url,
+                                              "i1",
+                                              MHD_HTTP_OK,
+                                              
"instance-patch-i1-inactivate-account",
+                                              payto_uris,
+                                              1,
+                                              &payto_uris[1],
+                                              1),
     TALER_TESTING_cmd_merchant_get_instance ("instances-get-i2-nx",
                                              merchant_url,
                                              "i2",
diff --git a/src/testing/testing_api_cmd_get_instance.c 
b/src/testing/testing_api_cmd_get_instance.c
index a3b9113..e7742cb 100644
--- a/src/testing/testing_api_cmd_get_instance.c
+++ b/src/testing/testing_api_cmd_get_instance.c
@@ -59,6 +59,31 @@ struct GetInstanceState
    */
   const char *instance_reference;
 
+  /**
+   * Whether we should check the instance's accounts or not.
+   */
+  bool cmp_accounts;
+
+  /**
+   * The accounts of the merchant we expect to be active.
+   */
+  const char **active_accounts;
+
+  /**
+   * The length of @e active_accounts.
+   */
+  unsigned int active_accounts_length;
+
+  /**
+   * The accounts of the merchant we expect to be inactive.
+   */
+  const char **inactive_accounts;
+
+  /**
+   * The length of @e inactive_accounts.
+   */
+  unsigned int inactive_accounts_length;
+
   /**
    * Expected HTTP response code.
    */
@@ -235,48 +260,61 @@ get_instance_cb (void *cls,
         return;
       }
     }
+    /* We aren't guaranteed an order for the accounts, so we just have to check
+       that we can match each account returned with exactly one account
+       expected. */
+    if (gis->cmp_accounts)
     {
-      const unsigned int *expected_accounts_length;
-      if (GNUNET_OK !=
-          TALER_TESTING_get_trait_uint32 (instance_cmd,
-                                          1,
-                                          &expected_accounts_length))
-      {
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                    "Could not fetch accounts length\n");
-        TALER_TESTING_interpreter_fail (gis->is);
-        return;
-      }
-      if (accounts_length != *expected_accounts_length)
+      unsigned int expected_accounts_length =
+        gis->active_accounts_length + gis->inactive_accounts_length;
+      unsigned int matches[accounts_length];
+
+      if (accounts_length != expected_accounts_length)
       {
         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                     "Accounts length does not match\n");
         TALER_TESTING_interpreter_fail (gis->is);
         return;
       }
-    }
-    for (unsigned int i = 0; i < accounts_length; ++i)
-    {
-      const char *payto_uri;
-      if (GNUNET_OK !=
-          TALER_TESTING_get_trait_string (instance_cmd,
-                                          2 + i,
-                                          &payto_uri))
+
+      memset (matches,
+              0,
+              sizeof (unsigned int) * accounts_length);
+
+      // Compare the accounts
+      for (unsigned int i = 0; i < accounts_length; ++i)
       {
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                    "Could not fetch account payto uri\n");
-        TALER_TESTING_interpreter_fail (gis->is);
-        return;
+        for (unsigned int j = 0; j < gis->active_accounts_length; ++j)
+        {
+          if ((0 == strcasecmp (accounts[i].payto_uri,
+                                gis->active_accounts[j])) &&
+              (true == accounts[i].active))
+          {
+            matches[i] += 1;
+          }
+        }
+        for (unsigned int j = 0; j < gis->inactive_accounts_length; ++j)
+        {
+          if ((0 == strcasecmp (accounts[i].payto_uri,
+                                gis->inactive_accounts[j])) &&
+              (false == accounts[i].active))
+          {
+            matches[i] += 1;
+          }
+        }
       }
-      if (0 != strcasecmp (accounts[i].payto_uri,
-                           payto_uri))
+
+      // Each account should have exactly one match.
+      for (unsigned int i = 0; i < accounts_length; ++i)
       {
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                    "Account payto uri does not match\n");
-        TALER_TESTING_interpreter_fail (gis->is);
-        return;
+        if (1 != matches[i])
+        {
+          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                      "Instance account does not match\n");
+          TALER_TESTING_interpreter_fail (gis->is);
+          return;
+        }
       }
-      // FIXME: account for deactivated accounts
     }
     break;
   default:
@@ -344,7 +382,8 @@ get_instance_cleanup (void *cls,
  * @param instance_id the ID of the instance to query
  * @param http_status expected HTTP response code.
  * @param instance_reference reference to a "POST /instances" or "PATCH 
/instances/$ID" CMD
- *        that will provide what we expect the backend to return to us
+ *        that will provide what we expect the backend to return to us.
+ *
  * @return the command.
  */
 struct TALER_TESTING_Command
@@ -361,6 +400,59 @@ TALER_TESTING_cmd_merchant_get_instance (const char *label,
   gis->instance_id = instance_id;
   gis->http_status = http_status;
   gis->instance_reference = instance_reference;
+  gis->cmp_accounts = false;
+  {
+    struct TALER_TESTING_Command cmd = {
+      .cls = gis,
+      .label = label,
+      .run = &get_instance_run,
+      .cleanup = &get_instance_cleanup
+    };
+
+    return cmd;
+  }
+}
+
+
+/**
+ * Define a "GET instance" CMD that compares accounts returned.
+ *
+ * @param label command label.
+ * @param merchant_url base URL of the merchant serving the
+ *        GET /instances/$ID request.
+ * @param instance_id the ID of the instance to query
+ * @param http_status expected HTTP response code.
+ * @param instance_reference reference to a "POST /instances" or "PATCH 
/instances/$ID" CMD
+ *        that will provide what we expect the backend to return to us
+ * @param active_accounts the accounts the merchant is actively using.
+ * @param active_accounts_length length of @e active_accounts.
+ * @param inactive_accounts the accounts the merchant is no longer using.
+ * @param inactive_accounts_length length of @e inactive_accounts.
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_get_instance2 (const char *label,
+                                          const char *merchant_url,
+                                          const char *instance_id,
+                                          unsigned int http_status,
+                                          const char *instance_reference,
+                                          const char *active_accounts[],
+                                          unsigned int active_accounts_length,
+                                          const char *inactive_accounts[],
+                                          unsigned int 
inactive_accounts_length)
+{
+  struct GetInstanceState *gis;
+
+  gis = GNUNET_new (struct GetInstanceState);
+  gis->merchant_url = merchant_url;
+  gis->instance_id = instance_id;
+  gis->http_status = http_status;
+  gis->instance_reference = instance_reference;
+  gis->cmp_accounts = true;
+  gis->active_accounts = active_accounts;
+  gis->active_accounts_length = active_accounts_length;
+  gis->inactive_accounts = inactive_accounts;
+  gis->inactive_accounts_length = inactive_accounts_length;
   {
     struct TALER_TESTING_Command cmd = {
       .cls = gis,

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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