gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 02/04: worked on testing anastasis.c


From: gnunet
Subject: [taler-anastasis] 02/04: worked on testing anastasis.c
Date: Tue, 28 Apr 2020 19:14:49 +0200

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

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

commit c29ecf10bc395ac0bc65647d6ed173236c4b2048
Author: Dennis Neufeld <address@hidden>
AuthorDate: Mon Apr 27 20:24:48 2020 +0000

    worked on testing anastasis.c
---
 src/include/anastasis_service.h       |   1 -
 src/include/anastasis_testing_lib.h   |  42 +++++
 src/lib/Makefile.am                   |   1 +
 src/lib/anastasis.c                   |  28 ++--
 src/lib/test_anastasis.c              |  42 +++++
 src/lib/testing_api_cmd_truth_store.c |   2 +-
 src/lib/testing_cmd_truth_upload.c    | 302 ++++++++++++++++++++++++++++++++++
 7 files changed, 400 insertions(+), 18 deletions(-)

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..ffa3574 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,47 @@ ANASTASIS_TESTING_cmd_salt (const char *label,
                             const char *anastasis_url,
                             unsigned int http_status);
 
+/* ********************* test truth upload ********************* */
+
+/**
+ * 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..a5f8ecb 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -67,6 +67,7 @@ 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
 libanastasistesting_la_LIBADD = \
diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index 356c338..f083bfb 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -541,11 +541,6 @@ struct ANASTASIS_TruthUpload
    */
   struct ANASTASIS_TruthStoreOperation *tso;
 
-  /**
-   * the truth details
-   */
-  json_t *truth;
-
   // FIXME not sure how to do payment
   int payment_requested;
   const char *paid_order_id;
@@ -663,6 +658,7 @@ ANASTASIS_truth_upload (const json_t *id_data,
   struct ANASTASIS_CRYPTO_EncryptedKeyShareP *encrypted_key_share;
   void *encrypted_truth;
   size_t encrypted_truth_size;
+  json_t *truth;
   t->url = provider_url;
   t->method = method;
   t->instructions = instructions;
@@ -695,21 +691,21 @@ ANASTASIS_truth_upload (const json_t *id_data,
                                   &encrypted_truth,
                                   &encrypted_truth_size);
 
-  tu->truth = json_pack ("{s:o," /* encrypted KeyShare */
-                         " s:s," /* method */
-                         " s:o," /* nonce */
-                         " s:s}", /* truth_mime */
-                         "keyshare_data", GNUNET_JSON_from_data_auto (
-                           encrypted_key_share),
-                         "method", method,
-                         "encrypted_truth", GNUNET_JSON_from_data (
-                           encrypted_truth, encrypted_truth_size),
-                         "truth_mime", mime_type);
+  truth = json_pack ("{s:o," /* encrypted KeyShare */
+                     " s:s," /* method */
+                     " s:o," /* nonce */
+                     " s:s}", /* truth_mime */
+                     "keyshare_data", GNUNET_JSON_from_data_auto (
+                       encrypted_key_share),
+                     "method", method,
+                     "encrypted_truth", GNUNET_JSON_from_data (
+                       encrypted_truth, encrypted_truth_size),
+                     "truth_mime", mime_type);
 
   tu->tso = ANASTASIS_truth_store (tu->ctx,
                                    t->url,
                                    &t->uuid,
-                                   tu->truth,
+                                   truth,
                                    tu->payment_requested,
                                    tu->paid_order_id,
                                    &truth_store_callback,
diff --git a/src/lib/test_anastasis.c b/src/lib/test_anastasis.c
index c89c879..a488161 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,
diff --git a/src/lib/testing_api_cmd_truth_store.c 
b/src/lib/testing_api_cmd_truth_store.c
index 5dfc0d5..ebfa10a 100644
--- a/src/lib/testing_api_cmd_truth_store.c
+++ b/src/lib/testing_api_cmd_truth_store.c
@@ -110,7 +110,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..096c7a1
--- /dev/null
+++ b/src/lib/testing_cmd_truth_upload.c
@@ -0,0 +1,302 @@
+/*
+  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 jsont_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;
+
+  /**
+   * 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;
+};
+
+
+/**
+ * Function called with the results of a #truth_upload().
+ *
+ * @param cls closure
+ * @param ec ANASTASIS error code
+ * @param http_status HTTP status of the request
+ * @param ud details about the upload operation
+ */
+static void
+truth_upload_cb (void *cls,
+                 enum ANASTASIS_ErrorCode ec,
+                 unsigned int http_status,
+                 const struct ANASTASIS_UploadDetails *ud)
+{
+  struct TruthUploadState *tus = cls;
+  tus->tuo = NULL;
+  if (http_status != tss->http_status)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unexpected response code %u to command %s in %s:%u\n",
+                http_status,
+                tss->is->commands[tss->is->ip].label,
+                __FILE__,
+                __LINE__);
+    TALER_TESTING_interpreter_fail (tss->is);
+    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;
+  // FIXME: Whole secret share procedure here
+  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;
+    }
+    // FIXME: get trait truth array
+  }
+
+  tus->tuo = ANASTASIS_truth_upload (tus->id_data,
+                                     tus->anastasis_url,
+                                     tus->method,
+                                     tus->instructions,
+                                     tus->mime_type,
+                                     tus->truth_data,
+                                     tus->truth_data_size,
+                                     tus->tpc,
+                                     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;
+
+  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[] = {
+    // FIXME: What traits are usefull?
+    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

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



reply via email to

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