gnunet-svn
[Top][All Lists]
Advanced

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

[taler-donau] branch master updated: create private key in testing CMD


From: gnunet
Subject: [taler-donau] branch master updated: create private key in testing CMD
Date: Wed, 06 Mar 2024 11:27:34 +0100

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

grothoff pushed a commit to branch master
in repository donau.

The following commit(s) were added to refs/heads/master by this push:
     new a59e61a  create private key in testing CMD
a59e61a is described below

commit a59e61a140b246dc75c2017630635b8731de83cb
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Wed Mar 6 11:27:32 2024 +0100

    create private key in testing CMD
---
 src/include/donau_service.h                |  4 +-
 src/include/donau_testing_lib.h            | 26 ++++----
 src/testing/testing_api_cmd_charity_post.c | 95 ++++++++++++++++++++++--------
 3 files changed, 86 insertions(+), 39 deletions(-)

diff --git a/src/include/donau_service.h b/src/include/donau_service.h
index c94b04f..cfba4f4 100644
--- a/src/include/donau_service.h
+++ b/src/include/donau_service.h
@@ -1035,12 +1035,12 @@ struct DONAU_CharityRequest
   /**
    * name of the charity
    */
-  char *name;
+  const char *name;
 
   /**
    * URL
    */
-  char *charity_url;
+  const char *charity_url;
 
   /**
    * max donation amount per year
diff --git a/src/include/donau_testing_lib.h b/src/include/donau_testing_lib.h
index fe55c63..12ea840 100644
--- a/src/include/donau_testing_lib.h
+++ b/src/include/donau_testing_lib.h
@@ -23,7 +23,7 @@
  * @author Christian Grothoff <christian@grothoff.org>
  * @author Marcello Stanisci
  * @author Lukas Matyja
- * 
+ *
  */
 #ifndef DONAU_TESTING_LIB_H
 #define DONAU_TESTING_LIB_H
@@ -32,7 +32,6 @@
 #include "donau_service.h"
 
 
-
 /**
  * Connects to the exchange.
  *
@@ -47,7 +46,7 @@ struct TALER_TESTING_Command
 TALER_TESTING_cmd_get_donau (
   const char *label,
   const struct GNUNET_CONFIGURATION_Handle *cfg,
-  //const char *last_keys_ref,
+  // const char *last_keys_ref,
   bool wait_for_keys,
   bool load_private_key);
 
@@ -62,9 +61,9 @@ TALER_TESTING_cmd_get_donau (
  */
 struct TALER_TESTING_Command
 TALER_TESTING_cmd_charity_get (const char *label,
-                                                               const uint64_t 
charity_id,
-                                                               const struct 
DONAU_BearerToken bearer,
-                                unsigned int expected_response_code);
+                               const uint64_t charity_id,
+                               const struct DONAU_BearerToken bearer,
+                               unsigned int expected_response_code);
 
 /**
  * Create a POST "charity" command.
@@ -82,8 +81,8 @@ TALER_TESTING_cmd_charity_post (const char *label,
                                 char *url,
                                 char *max_per_year,
                                 char *receipts_to_date,
-                                uint64_t current_year, 
-                                                                               
const struct DONAU_BearerToken bearer,
+                                uint64_t current_year,
+                                const struct DONAU_BearerToken bearer,
                                 unsigned int expected_response_code);
 
 struct TALER_TESTING_Command
@@ -101,9 +100,9 @@ TALER_TESTING_cmd_charity_delete (const char *label,
  */
 struct TALER_TESTING_Command
 TALER_TESTING_cmd_charities_get (const char *label,
-                                                        unsigned int 
expected_response_code);
+                                 unsigned int expected_response_code);
 
-  /**
+/**
  * Convenience function to run a test.
  *
  * @param argv command-line arguments given
@@ -141,8 +140,11 @@ TALER_TESTING_get_donau_url (
  * Call #op on all simple traits.
  */
 #define DONAU_TESTING_SIMPLE_TRAITS(op) \
+        op (charity_priv, const struct DONAU_CharityPrivateKeyP)        \
+        op (charity_pub, const struct DONAU_CharityPublicKeyP)        \
+        op (charity_id, const unsigned long long)        \
         op (donau_url, const char)                                             
   \
-        op (donau_keys, struct  DONAU_Keys)           
+        op (donau_keys, struct  DONAU_Keys)
 
 
 /**
@@ -150,7 +152,7 @@ TALER_TESTING_get_donau_url (
  */
 #define DONAU_TESTING_INDEXED_TRAITS(op)                                       
   \
         op (donation_unit_pub, const struct DONAU_DonationUnitInformation)     
   \
-        op (donau_pub, const struct TALER_ExchangePublicKeyP)              
+        op (donau_pub, const struct TALER_ExchangePublicKeyP)
 
 DONAU_TESTING_SIMPLE_TRAITS (TALER_TESTING_MAKE_DECL_SIMPLE_TRAIT)
 DONAU_TESTING_INDEXED_TRAITS (TALER_TESTING_MAKE_DECL_INDEXED_TRAIT)
diff --git a/src/testing/testing_api_cmd_charity_post.c 
b/src/testing/testing_api_cmd_charity_post.c
index e33d99d..70d6dc2 100644
--- a/src/testing/testing_api_cmd_charity_post.c
+++ b/src/testing/testing_api_cmd_charity_post.c
@@ -41,7 +41,12 @@ struct StatusState
   /**
    * The charity POST request.
    */
-  struct DONAU_CharityRequest *charity_req;
+  struct DONAU_CharityRequest charity_req;
+
+  /**
+   * Private key of the charity, created here.
+   */
+  struct DONAU_CharityPrivateKeyP charity_priv;
 
   /**
    * The bearer token for authorization.
@@ -58,6 +63,11 @@ struct StatusState
    */
   struct TALER_TESTING_Interpreter *is;
 
+  /**
+   * charity id
+   */
+  unsigned long long charity_id;
+
 };
 
 
@@ -74,7 +84,6 @@ charity_status_cb (void *cls,
 {
   struct StatusState *ss = cls;
 
-
   ss->cph = NULL;
   if (ss->expected_response_code != gcr->hr.http_status)
   {
@@ -89,6 +98,8 @@ charity_status_cb (void *cls,
     TALER_TESTING_interpreter_fail (ss->is);
     return;
   }
+  if (MHD_HTTP_OK == gcr->hr.http_status)
+    ss->charity_id = gcr->details.ok.charity_id;
   TALER_TESTING_interpreter_next (ss->is);
 }
 
@@ -111,13 +122,14 @@ status_run (void *cls,
 
   ss->cph = DONAU_charity_post (
     TALER_TESTING_interpreter_get_context (is),
-       "http://localhost:8080/";, //TODO: TALER_TESTING_get_donau_url (is),
-       ss->charity_req,
+    "http://localhost:8080/";, // TODO: TALER_TESTING_get_donau_url (is),
+    &ss->charity_req,
     ss->bearer,
     &charity_status_cb,
     ss);
 }
 
+
 /**
  * Cleanup the state from a "reserve status" CMD, and possibly
  * cancel a pending operation thereof.
@@ -133,9 +145,9 @@ status_cleanup (void *cls,
 
   if (NULL != ss->cph)
   {
-       // log incomplete command
-       TALER_TESTING_command_incomplete (ss->is,
-                                                                          
cmd->label);
+    // log incomplete command
+    TALER_TESTING_command_incomplete (ss->is,
+                                      cmd->label);
     DONAU_charity_post_cancel (ss->cph);
     ss->cph = NULL;
   }
@@ -143,53 +155,86 @@ status_cleanup (void *cls,
 }
 
 
+/**
+ * Offer internal data from a "deposit" CMD, to other commands.
+ *
+ * @param cls closure.
+ * @param[out] ret result.
+ * @param trait name of the trait.
+ * @param index index number of the object to offer.
+ * @return #GNUNET_OK on success.
+ */
+static enum GNUNET_GenericReturnValue
+charity_post_traits (void *cls,
+                     const void **ret,
+                     const char *trait,
+                     unsigned int index)
+{
+  struct StatusState *ss = cls;
+  struct TALER_TESTING_Trait traits[] = {
+    TALER_TESTING_make_trait_charity_priv (&ss->charity_priv),
+    TALER_TESTING_make_trait_charity_pub (&ss->charity_req.charity_pub),
+    TALER_TESTING_make_trait_charity_id (&ss->charity_id),
+    TALER_TESTING_trait_end ()
+  };
+
+  return TALER_TESTING_get_trait (traits,
+                                  ret,
+                                  trait,
+                                  index);
+}
+
+
 struct TALER_TESTING_Command
 TALER_TESTING_cmd_charity_post (const char *label,
-        char charity_pub[256 / 8],
-        char *name,
-        char *url,
-        char *max_per_year,
-        char *receipts_to_date,
-        uint64_t current_year,
-               const struct DONAU_BearerToken bearer,
-        unsigned int expected_response_code)
+                                const char *name,
+                                const char *url,
+                                const char *max_per_year,
+                                const char *receipts_to_date,
+                                uint64_t current_year,
+                                const struct DONAU_BearerToken *bearer,
+                                unsigned int expected_response_code)
 {
   struct StatusState *ss;
+
   ss = GNUNET_new (struct StatusState);
-  GNUNET_memcpy(&ss->charity_req->charity_pub.eddsa_pub.q_y, charity_pub, 
sizeof(ss->charity_req->charity_pub.eddsa_pub.q_y));
-  ss->charity_req->name = GNUNET_strdup (name);
-  ss->charity_req->charity_url = GNUNET_strdup (url);
+  GNUNET_CRYPTO_eddsa_key_create (&ss->charity_priv.eddsa_priv);
+  GNUNET_CRYPTO_eddsa_key_get_public (&ss->charity_priv.eddsa_priv,
+                                      &ss->charity_req.charity_pub.eddsa_pub);
+  ss->charity_req.name = name;
+  ss->charity_req.charity_url = url;
   // parse string max_per_year to amount
   if (GNUNET_OK !=
       TALER_string_to_amount (max_per_year,
-                              &ss->charity_req->max_per_year))
+                              &ss->charity_req.max_per_year))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Failed to parse amount `%s' at %s\n",
-                               max_per_year,
+                max_per_year,
                 label);
     GNUNET_assert (0);
   }
   // parse string receipts_to_date to amount
   if (GNUNET_OK !=
       TALER_string_to_amount (receipts_to_date,
-                              &ss->charity_req->receipts_to_date))
+                              &ss->charity_req.receipts_to_date))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Failed to parse amount `%s' at %s\n",
-                               receipts_to_date,
+                receipts_to_date,
                 label);
     GNUNET_assert (0);
   }
-  ss->charity_req->current_year = current_year;
+  ss->charity_req.current_year = current_year;
   ss->expected_response_code = expected_response_code;
-  ss->bearer = bearer;
+  ss->bearer = *bearer;
   {
     struct TALER_TESTING_Command cmd = {
       .cls = ss,
       .label = label,
       .run = &status_run,
-      .cleanup = &status_cleanup
+      .cleanup = &status_cleanup,
+      .traits = &charity_post_traits
     };
 
     return cmd;

-- 
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]