gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated (1a3fec2 -> c2df06c)


From: gnunet
Subject: [taler-anastasis] branch master updated (1a3fec2 -> c2df06c)
Date: Tue, 28 Apr 2020 19:14:47 +0200

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

dennis-neufeld pushed a change to branch master
in repository anastasis.

    from 1a3fec2  added json and callback
     new ccdfb79  Modified TruthUpload
     new c29ecf1  worked on testing anastasis.c
     new 10f273c  worked on testing anastasis.c (truth upload)
     new c2df06c  worked on testing truth upload (anastasis.c)

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/anastasis.h               |   9 +-
 src/include/anastasis_service.h       |   1 -
 src/include/anastasis_testing_lib.h   |  94 +++++++++
 src/lib/Makefile.am                   |   4 +-
 src/lib/anastasis.c                   |  25 ++-
 src/lib/anastasis_api_policy_store.c  |   2 +-
 src/lib/test_anastasis.c              |  43 ++++
 src/lib/testing_api_cmd_truth_store.c |  10 +-
 src/lib/testing_cmd_truth_upload.c    | 360 ++++++++++++++++++++++++++++++++++
 src/lib/testing_trait_truth.c         | 115 +++++++++++
 10 files changed, 644 insertions(+), 19 deletions(-)
 create mode 100644 src/lib/testing_cmd_truth_upload.c
 create mode 100644 src/lib/testing_trait_truth.c

diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index c8270f6..5d3bc0d 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -263,22 +263,25 @@ typedef void
 typedef void
 (*ANASTASIS_TruthCallback)(void *cls,
                            struct ANASTASIS_Truth *t);
+
 /**
 * Uploads a truth object onto a escrow provider
 *
+* @param ctx the CURL context used to connect to the backend
 * @param id_data user provided authentication for generation of the truth 
encryption
 * @param method defines the method of the challenge (secure question, sms, 
email)
 * @param instructions depending on method! usually only for security 
question/answer!
 * @param mime_type format of the challenge
-* @param data contains the keyshare for this truth
-* @param data_size size of the data
+* @param truth_data contains the truth for this challenge i.e. phone number, 
email address
+* @param truth_data_size size of the data
 * @param tpc opens a truth payment callback to pay the upload
 * @param tpc_cls closure for the payment callback
 * @param tc opens the truth callback which contains the status of the upload
 * @param tc_cls closure for the callback
 */
 struct ANASTASIS_TruthUpload *
-ANASTASIS_truth_upload (const json_t *id_data,
+ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
+                        const json_t *id_data,
                         const char *provider_url,
                         const char *method,
                         const char *instructions,
diff --git a/src/include/anastasis_service.h b/src/include/anastasis_service.h
index c21ed9d..ad1a9aa 100644
--- a/src/include/anastasis_service.h
+++ b/src/include/anastasis_service.h
@@ -100,7 +100,6 @@ struct ANASTASIS_Salt
 
 GNUNET_NETWORK_STRUCT_END
 
-
 /**
  * High-level ways how an upload may conclude.
  */
diff --git a/src/include/anastasis_testing_lib.h 
b/src/include/anastasis_testing_lib.h
index 9ab793d..f523058 100644
--- a/src/include/anastasis_testing_lib.h
+++ b/src/include/anastasis_testing_lib.h
@@ -24,6 +24,7 @@
 #define ANASTASIS_TESTING_LIB_H
 
 #include "anastasis_service.h"
+#include "anastasis.h"
 #include <gnunet/gnunet_json_lib.h>
 #include <taler/taler_testing_lib.h>
 #include <microhttpd.h>
@@ -430,6 +431,99 @@ ANASTASIS_TESTING_cmd_salt (const char *label,
                             const char *anastasis_url,
                             unsigned int http_status);
 
+/* ********************* test truth upload ********************* */
+
+/**
+ * Obtain numbers of truth traits from @a cmd.
+ *
+ * @param cmd command to extract the number from.
+ * @param index the index of the number
+ * @param n[out] set to the number coming from @a cmd.
+ * @return #GNUNET_OK on success.
+ */
+int
+ANASTASIS_TESTING_get_trait_truth_number (const struct
+                                          TALER_TESTING_Command *cmd,
+                                          unsigned int index,
+                                          const unsigned int **n);
+
+
+/**
+ * Offer the number of truth traits.
+ *
+ * @param index the number's index number (usually zero).
+ * @param n the number to offer.
+ * @return #GNUNET_OK on success.
+ */
+struct TALER_TESTING_Trait
+ANASTASIS_TESTING_make_trait_truth_number (unsigned int index,
+                                           const unsigned int *n);
+
+
+/**
+ * Obtain a truth from @a cmd.
+ *
+ * @param cmd command to extract the truth from.
+ * @param index the index of the truth
+ * @param t[out] set to the truth coming from @a cmd.
+ * @return #GNUNET_OK on success.
+ */
+int
+ANASTASIS_TESTING_get_trait_truth (const struct TALER_TESTING_Command *cmd,
+                                   unsigned int index,
+                                   const struct ANASTASIS_Truth **t);
+
+
+/**
+ * Offer an truth.
+ *
+ * @param index the truth's index number.
+ * @param t the truth to offer.
+ * @return #GNUNET_OK on success.
+ */
+struct TALER_TESTING_Trait
+ANASTASIS_TESTING_make_trait_truth (unsigned int index,
+                                    const struct ANASTASIS_Truth *t);
+
+/**
+ * Creates a sample of id_data.
+ *
+ * @param id_data some sample data (e.g. AHV, name, surname, ...)
+ * @return truth in json format
+ */
+json_t *
+ANASTASIS_TESTING_make_id_data_example (const char *id_data);
+
+/**
+ * Make the "truth upload" command.
+ *
+ * @param label command label
+ * @param anastasis_url base URL of the anastasis serving our requests.
+ * @param id_data ID data to generate user identifier
+ * @param method specifies escrow method
+ * @param instructions specifies what the client/user has to do
+ * @param mime_type mime type of truth_data
+ * @param truth_data some truth data (e.g. hash of answer to a secret question)
+ * @param truth_data_size size of truth_data
+ * @param http_status expected HTTP status
+ * @param tso truth upload options
+ * @param upload_ref reference to the previous upload
+ * @return the command
+ */
+struct TALER_TESTING_Command
+ANASTASIS_TESTING_cmd_truth_upload (const char *label,
+                                    const char *anastasis_url,
+                                    const json_t *id_data,
+                                    const char *method,
+                                    const char *instructions,
+                                    const char *mime_type,
+                                    const void *truth_data,
+                                    size_t truth_data_size,
+                                    unsigned int http_status,
+                                    enum
+                                    ANASTASIS_TESTING_TruthStoreOption tso,
+                                    const char *upload_ref);
+
 
 /* ********************* test secret share ********************* */
 
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 9056b66..32bcd5c 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -67,8 +67,10 @@ libanastasistesting_la_SOURCES = \
   testing_api_trait_payment_identifier.c \
   testing_api_trait_uuid.c \
   testing_api_trait_hash.c \
+  testing_cmd_truth_upload.c \
   testing_cmd_secret_share.c \
-  testing_cmd_recover_secret.c
+  testing_cmd_recover_secret.c \
+  testing_trait_truth.c
 libanastasistesting_la_LIBADD = \
   $(top_builddir)/src/lib/libanastasisrest.la \
   -ltalerexchange \
diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index 884c634..57c9257 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -505,30 +505,37 @@ struct ANASTASIS_TruthUpload
    * Expected HTTP Status
    */
   unsigned int http_status;
+
   /**
    * CURL Context for the Post Request
    */
   struct GNUNET_CURL_Context *ctx;
+
   /**
    * User identifier used for the keyshare encryption
    */
   struct ANASTASIS_CRYPTO_UserIdentifierP id;
+
   /**
    * Callback which tells the user the payment details for the upload
    */
   ANASTASIS_TruthPaymentCallback tpc;
+
   /**
    * Closure for the payment callback
    */
   void *tpc_cls;
+
   /**
    * Callback which sends back the generated truth object later used to build 
the policy
    */
   ANASTASIS_TruthCallback tc;
+
   /**
    * Closure for the Callback
    */
   void *tc_cls;
+
   /**
    * Reference to the Truthstore Operation
    */
@@ -619,6 +626,7 @@ truth_store_callback (void *cls,
 /**
 * Uploads a truth object onto a escrow provider
 *
+* @param ctx the CURL context used to connect to the backend
 * @param id_data user provided authentication for generation of the truth 
encryption
 * @param method defines the method of the challenge (secure question, sms, 
email)
 * @param instructions depending on method! usually only for security 
question/answer!
@@ -631,7 +639,8 @@ truth_store_callback (void *cls,
 * @param tc_cls closure for the callback
 */
 struct ANASTASIS_TruthUpload *
-ANASTASIS_truth_upload (const json_t *id_data,
+ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
+                        const json_t *id_data,
                         const char *provider_url,
                         const char *method,
                         const char *instructions,
@@ -645,19 +654,26 @@ ANASTASIS_truth_upload (const json_t *id_data,
 {
   // FIXME Challenge
   struct ANASTASIS_TruthUpload *tu;
-  tu = GNUNET_new (struct ANASTASIS_TruthUpload);
   struct ANASTASIS_Truth *t;
-  t = GNUNET_new (struct ANASTASIS_Truth);
+  struct SaltState *ss;
   struct ANASTASIS_CRYPTO_EncryptedKeyShareP *encrypted_key_share;
   void *encrypted_truth;
   size_t encrypted_truth_size;
   json_t *truth;
+
+  tu = GNUNET_new (struct ANASTASIS_TruthUpload);
+  t = GNUNET_new (struct ANASTASIS_Truth);
+  ss = GNUNET_new (struct ANASTASIS_CRYPTO_SaltP);
+  tu->tc_cls = tc_cls;
+  tu->tpc_cls = tpc_cls;
+  tu->tpc = tpc;
+  tu->tc = tc;
+  tu->ctx = ctx;
   t->url = provider_url;
   t->method = method;
   t->instructions = instructions;
   t->mime_type = mime_type;
   uuid_generate (t->uuid);
-  struct SaltState *ss = tpc_cls;
 
   ss->http_status = MHD_HTTP_OK;
   ss->so = ANASTASIS_salt (tu->ctx,
@@ -716,6 +732,7 @@ ANASTASIS_truth_upload (const json_t *id_data,
   // FIXME PAYMENT CALLBACK
   return tu;
 }
+
 /**
 * Cancels a upload process
 * @param tu handle for the upload
diff --git a/src/lib/anastasis_api_policy_store.c 
b/src/lib/anastasis_api_policy_store.c
index e4036b3..cb8e324 100644
--- a/src/lib/anastasis_api_policy_store.c
+++ b/src/lib/anastasis_api_policy_store.c
@@ -292,7 +292,7 @@ ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
     .purpose.size = htonl (sizeof (usp))
   };
 
-  /*
+  /* FIXME: Maybe can be deleted
   if (NULL != prev_recovery_data_hash)
     usp.old_recovery_data_hash = *prev_recovery_data_hash;
   */
diff --git a/src/lib/test_anastasis.c b/src/lib/test_anastasis.c
index c89c879..0c4be60 100644
--- a/src/lib/test_anastasis.c
+++ b/src/lib/test_anastasis.c
@@ -185,6 +185,48 @@ run (void *cls,
 
   struct TALER_TESTING_Command anastasis[] = {
     // FIXME: testing logic here
+    ANASTASIS_TESTING_cmd_truth_upload ("truth-create-1",
+                                        anastasis_url,
+                                        ANASTASIS_TESTING_make_id_data_example 
(
+                                          "MaxMuster123456789"
+                                          ),
+                                        "Secure-Question",
+                                        "You have to answer the secure 
question.",
+                                        "string",
+                                        "HashOfSomeTruth",
+                                        strlen ("HashOfSomeTruth"),
+                                        MHD_HTTP_NO_CONTENT,
+                                        ANASTASIS_TESTING_TSO_NONE,
+                                        NULL),
+
+    ANASTASIS_TESTING_cmd_truth_upload ("truth-create-2",
+                                        anastasis_url,
+                                        ANASTASIS_TESTING_make_id_data_example 
(
+                                          "MaxMuster123456789"
+                                          ),
+                                        "Secure-Question",
+                                        "You have to answer the secure 
question.",
+                                        "string",
+                                        "HashOfSomeTruth",
+                                        strlen ("HashOfSomeTruth"),
+                                        MHD_HTTP_NO_CONTENT,
+                                        ANASTASIS_TESTING_TSO_NONE,
+                                        "truth-create-1"),
+
+    ANASTASIS_TESTING_cmd_truth_upload ("truth-create-3",
+                                        anastasis_url,
+                                        ANASTASIS_TESTING_make_id_data_example 
(
+                                          "MaxMuster123456789"
+                                          ),
+                                        "Secure-Question",
+                                        "You have to answer the secure 
question.",
+                                        "string",
+                                        "HashOfSomeTruth",
+                                        strlen ("HashOfSomeTruth"),
+                                        MHD_HTTP_NO_CONTENT,
+                                        ANASTASIS_TESTING_TSO_NONE,
+                                        "truth-create-2"),
+    /*
     ANASTASIS_TESTING_cmd_secret_share ("secret-share-1",
                                         anastasis_url,
                                         MHD_HTTP_PAYMENT_REQUIRED,
@@ -196,6 +238,7 @@ run (void *cls,
                                           MHD_HTTP_PAYMENT_REQUIRED,
                                           ANASTASIS_TESTING_RSO_NONE,
                                           NULL),
+    */
 
     TALER_TESTING_cmd_end ()
   };
diff --git a/src/lib/testing_api_cmd_truth_store.c 
b/src/lib/testing_api_cmd_truth_store.c
index 5dfc0d5..e994d20 100644
--- a/src/lib/testing_api_cmd_truth_store.c
+++ b/src/lib/testing_api_cmd_truth_store.c
@@ -5,19 +5,11 @@
   Anastasis is free software; you can redistribute it and/or modify it under 
the
   terms of the GNU Lesser General Public License as published by the Free 
Software
   Foundation; either version 3, or (at your option) any later version.
-<<<<<<< HEAD
 
   Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY
   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 
-=======
-
-  Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY
-  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-
->>>>>>> f6a488c... modified salt request
   You should have received a copy of the GNU General Public License along with
   Anastasis; see the file COPYING.GPL.  If not, see 
<http://www.gnu.org/licenses/>
 */
@@ -110,7 +102,7 @@ struct TruthStoreState
  * Function called with the results of a #truth_store().
  *
  * @param cls closure
- * @param ec Taler error code
+ * @param ec ANASTASIS error code
  * @param http_status HTTP status of the request
  * @param ud details about the upload operation
  */
diff --git a/src/lib/testing_cmd_truth_upload.c 
b/src/lib/testing_cmd_truth_upload.c
new file mode 100644
index 0000000..3f60aad
--- /dev/null
+++ b/src/lib/testing_cmd_truth_upload.c
@@ -0,0 +1,360 @@
+/*
+  This file is part of Anastasis
+  Copyright (C) 2020 Taler Systems SA
+
+  Anastasis is free software; you can redistribute it and/or modify it under 
the
+  terms of the GNU Lesser General Public License as published by the Free 
Software
+  Foundation; either version 3, or (at your option) any later version.
+
+  Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY
+  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License along with
+  Anastasis; see the file COPYING.GPL.  If not, see 
<http://www.gnu.org/licenses/>
+*/
+/**
+ * @file lib/testing_cmd_truth_upload.c
+ * @brief command to execute the anastasis secret share service
+ * @author Christian Grothoff
+ * @author Dennis Neufeld
+ * @author Dominik Meister
+ */
+
+#include "platform.h"
+#include "anastasis_testing_lib.h"
+#include <taler/taler_util.h>
+#include <taler/taler_testing_lib.h>
+
+
+/**
+ * State for a "truth upload" CMD.
+ */
+struct TruthUploadState
+{
+  /**
+   * The interpreter state.
+   */
+  struct TALER_TESTING_Interpreter *is;
+
+  /**
+   * URL of the anastasis backend.
+   */
+  const char *anastasis_url;
+
+  /**
+   * The ID data to generate user identifier
+   */
+  const json_t *id_data;
+
+  /**
+   * The escrow method
+   */
+  const char *method;
+
+  /**
+   * Instructions to be returned to client/user
+   * (e.g. "Look at your smartphone. SMS was sent to you")
+   */
+  const char *instructions;
+
+  /**
+   * Mime type of truth_data (eg. jpeg, string etc.)
+   */
+  const char *mime_type;
+
+  /**
+   * The truth_data (e.g. hash of answer to a secure question)
+   */
+  const void *truth_data;
+
+  /**
+   * Size of truth_data
+   */
+  size_t truth_data_size;
+
+  /**
+   * Expected status code.
+   */
+  unsigned int http_status;
+
+  /**
+   * The /truth POST operation handle.
+   */
+  struct ANASTASIS_TruthUpload *tuo;
+
+  /**
+   * closure for the payment callback
+   */
+  void *tpc_cls;
+
+  /**
+   * Reference to upload command of previous truth upload.
+   */
+  const char *upload_reference;
+
+  /**
+   * Options for how we are supposed to do the upload.
+   */
+  enum ANASTASIS_TESTING_TruthStoreOption tsopt;
+
+  /**
+   * Truth object
+   */
+  const struct ANASTASIS_Truth *truth;
+
+  /**
+   * index of truth (for trait)
+   */
+  unsigned int truth_number;
+};
+
+
+/**
+* Upload information
+* caller MUST free 't' using ANASTASIS_truth_free()
+*
+* @param cls closure for callback
+* @param t Truth object (contains provider url and uuid)
+*/
+static void
+truth_upload_cb (void *cls,
+                 struct ANASTASIS_Truth *t)
+{
+  struct TruthUploadState *tus = cls;
+  tus->tuo = NULL;
+
+  if (NULL == t)
+  {
+    GNUNET_break (0);
+    TALER_TESTING_interpreter_fail (tus->is);
+    return;
+  }
+  tus->truth = t;
+
+  TALER_TESTING_interpreter_next (tus->is);
+}
+
+
+/**
+ * Initiates a callback for the payment of the truth upload
+ *
+ * @param cls closure
+ * @param taler_pay_url payment link for the transaction (taler://pay/Foo)
+ * @param ec status code of the request
+ */
+static void
+truth_payment_cb (void *cls,
+                  const char *taler_pay_url,
+                  enum TALER_ErrorCode ec)
+{
+  struct TruthUploadState *tus = cls;
+  tus->tuo = NULL;
+  // FIXME: Payment handling
+  return;
+}
+
+
+/**
+ * Run a "truth upload" CMD.
+ *
+ * @param cls closure.
+ * @param cmd command currently being run.
+ * @param is interpreter state.
+ */
+static void
+truth_upload_run (void *cls,
+                  const struct TALER_TESTING_Command *cmd,
+                  struct TALER_TESTING_Interpreter *is)
+{
+  struct TruthUploadState *tus = cls;
+
+  tus->is = is;
+  if (NULL != tus->upload_reference)
+  {
+    const struct TALER_TESTING_Command *ref;
+
+    ref = TALER_TESTING_interpreter_lookup_command
+            (is,
+            tus->upload_reference);
+    if (NULL == ref)
+    {
+      GNUNET_break (0);
+      TALER_TESTING_interpreter_fail (tus->is);
+      return;
+    }
+    const unsigned int *number;
+
+    if (GNUNET_OK !=
+        ANASTASIS_TESTING_get_trait_truth_number (ref,
+                                                  0,
+                                                  &number))
+    {
+      GNUNET_break (0);
+      TALER_TESTING_interpreter_fail (tus->is);
+      return;
+    }
+    tus->truth_number = *number + 1;
+  }
+  else
+  {
+    tus->truth_number = 0;
+  }
+
+  tus->tuo = ANASTASIS_truth_upload (is->ctx,
+                                     tus->id_data,
+                                     tus->anastasis_url,
+                                     tus->method,
+                                     tus->instructions,
+                                     tus->mime_type,
+                                     tus->truth_data,
+                                     tus->truth_data_size,
+                                     &truth_payment_cb,
+                                     tus->tpc_cls,
+                                     &truth_upload_cb,
+                                     tus);
+
+  if (NULL == tus->tuo)
+  {
+    GNUNET_break (0);
+    TALER_TESTING_interpreter_fail (tus->is);
+    return;
+  }
+}
+
+
+/**
+ * Free the state of a "truth upload" CMD, and possibly
+ * cancel it if it did not complete.
+ *
+ * @param cls closure.
+ * @param cmd command being freed.
+ */
+static void
+truth_upload_cleanup (void *cls,
+                      const struct TALER_TESTING_Command *cmd)
+{
+  // FIXME: Cleanup logic
+  struct TruthUploadState *tus = cls;
+
+  if (NULL != tus->tuo)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Command '%s' did not complete\n",
+                cmd->label);
+    ANASTASIS_truth_upload_cancel (tus->tuo);
+    tus->tuo = NULL;
+  }
+  GNUNET_free_non_null ((void *) tus->truth);
+  GNUNET_free_non_null ((void *) tus->truth_data);
+  GNUNET_free (tus);
+}
+
+
+/**
+ * Offer internal data to other commands.
+ *
+ * @param cls closure
+ * @param ret[out] result (could be anything)
+ * @param trait name of the trait
+ * @param index index number of the object to extract.
+ * @return #GNUNET_OK on success
+ */
+static int
+truth_upload_traits (void *cls,
+                     const void **ret,
+                     const char *trait,
+                     unsigned int index)
+{
+  struct TruthUploadState *tus = cls;
+  struct TALER_TESTING_Trait traits[] = {
+    ANASTASIS_TESTING_make_trait_truth (tus->truth_number,
+                                        tus->truth),
+    ANASTASIS_TESTING_make_trait_truth_number (0,
+                                               &tus->truth_number),
+    TALER_TESTING_trait_end ()
+  };
+
+  return TALER_TESTING_get_trait (traits,
+                                  ret,
+                                  trait,
+                                  index);
+}
+
+
+/**
+ * Creates a sample of id_data.
+ *
+ * @param id_data some sample data (e.g. AHV, name, surname, ...)
+ * @return truth in json format
+ */
+json_t *
+ANASTASIS_TESTING_make_id_data_example (const char *id_data)
+{
+  json_t *id;
+
+  id = json_pack ("{s:s}",
+                  "id_data", id_data);
+  GNUNET_assert (NULL != id);
+
+  return id;
+}
+
+
+/**
+ * Make the "truth upload" command.
+ *
+ * @param label command label
+ * @param anastasis_url base URL of the anastasis serving our requests.
+ * @param id_data ID data to generate user identifier
+ * @param method specifies escrow method
+ * @param instructions specifies what the client/user has to do
+ * @param mime_type mime type of truth_data
+ * @param truth_data some truth data (e.g. hash of answer to a secret question)
+ * @param truth_data_size size of truth_data
+ * @param http_status expected HTTP status
+ * @param tso truth upload options
+ * @param upload_ref reference to the previous upload
+ * @return the command
+ */
+struct TALER_TESTING_Command
+ANASTASIS_TESTING_cmd_truth_upload (const char *label,
+                                    const char *anastasis_url,
+                                    const json_t *id_data,
+                                    const char *method,
+                                    const char *instructions,
+                                    const char *mime_type,
+                                    const void *truth_data,
+                                    size_t truth_data_size,
+                                    unsigned int http_status,
+                                    enum
+                                    ANASTASIS_TESTING_TruthStoreOption tso,
+                                    const char *upload_ref)
+{
+  struct TruthUploadState *tus;
+
+  tus = GNUNET_new (struct TruthUploadState);
+  tus->http_status = http_status;
+  tus->tsopt = tso;
+  tus->anastasis_url = anastasis_url;
+  tus->upload_reference = upload_ref;
+  tus->id_data = id_data;
+  tus->method = method;
+  tus->instructions = instructions;
+  tus->mime_type = mime_type;
+  tus->truth_data_size = truth_data_size;
+  tus->truth_data = truth_data;
+
+  struct TALER_TESTING_Command cmd = {
+    .cls = tus,
+    .label = label,
+    .run = &truth_upload_run,
+    .cleanup = &truth_upload_cleanup,
+    .traits = &truth_upload_traits
+  };
+
+  return cmd;
+}
+
+
+/* end of testing_cmd_truth_upload.c */
\ No newline at end of file
diff --git a/src/lib/testing_trait_truth.c b/src/lib/testing_trait_truth.c
new file mode 100644
index 0000000..2ed45a2
--- /dev/null
+++ b/src/lib/testing_trait_truth.c
@@ -0,0 +1,115 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2020 Taler Systems SA
+
+  TALER is free software; you can redistribute it and/or modify it
+  under the terms of the GNU General Public License as published
+  by the Free Software Foundation; either version 3, or (at your
+  option) any later version.
+
+  TALER is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU General Public
+  License along with TALER; see the file COPYING.  If not, see
+  <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file lib/testing_api_trait_uuid.c
+ * @brief traits to offer a hash
+ * @author Christian Grothoff
+ * @author Dominik Meister
+ * @author Dennis Neufeld
+ */
+#include "platform.h"
+#include "anastasis_testing_lib.h"
+
+#define ANASTASIS_TESTING_TRAIT_TRUTH "anastasis-truth"
+#define ANASTASIS_TESTING_TRAIT_TRUTH_NUMBER "anastasis-truth-number"
+
+/**
+ * Obtain numbers of truth traits from @a cmd.
+ *
+ * @param cmd command to extract the number from.
+ * @param index the index of the number
+ * @param n[out] set to the number coming from @a cmd.
+ * @return #GNUNET_OK on success.
+ */
+int
+ANASTASIS_TESTING_get_trait_truth_number (const struct
+                                          TALER_TESTING_Command *cmd,
+                                          unsigned int index,
+                                          const unsigned int **n)
+{
+  return cmd->traits (cmd->cls,
+                      (const void **) n,
+                      ANASTASIS_TESTING_TRAIT_TRUTH_NUMBER,
+                      index);
+}
+
+
+/**
+ * Offer the number of truth traits.
+ *
+ * @param index the number's index number (usually zero).
+ * @param n the number to offer.
+ * @return #GNUNET_OK on success.
+ */
+struct TALER_TESTING_Trait
+ANASTASIS_TESTING_make_trait_truth_number
+  (unsigned int index,
+  const unsigned int *n)
+{
+  struct TALER_TESTING_Trait ret = {
+    .index = index,
+    .trait_name = ANASTASIS_TESTING_TRAIT_TRUTH_NUMBER,
+    .ptr = (const void *) n
+  };
+  return ret;
+}
+
+
+/**
+ * Obtain a truth from @a cmd.
+ *
+ * @param cmd command to extract the truth from.
+ * @param index the index of the truth
+ * @param t[out] set to the truth coming from @a cmd.
+ * @return #GNUNET_OK on success.
+ */
+int
+ANASTASIS_TESTING_get_trait_truth (const struct TALER_TESTING_Command *cmd,
+                                   unsigned int index,
+                                   const struct ANASTASIS_Truth **t)
+{
+  return cmd->traits (cmd->cls,
+                      (const void **) t,
+                      ANASTASIS_TESTING_TRAIT_TRUTH,
+                      index);
+}
+
+
+/**
+ * Offer an truth.
+ *
+ * @param index the truth's index number.
+ * @param t the truth to offer.
+ * @return #GNUNET_OK on success.
+ */
+struct TALER_TESTING_Trait
+ANASTASIS_TESTING_make_trait_truth
+  (unsigned int index,
+  const struct ANASTASIS_Truth *t)
+{
+  struct TALER_TESTING_Trait ret = {
+    .index = index,
+    .trait_name = ANASTASIS_TESTING_TRAIT_TRUTH,
+    .ptr = (const void *) t
+  };
+  return ret;
+}
+
+
+/* end of testing_trait_truth.c */

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



reply via email to

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