gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 03/04: Worked on policy upload. Payment is working, u


From: gnunet
Subject: [taler-anastasis] 03/04: Worked on policy upload. Payment is working, uploading afterwards not...
Date: Wed, 22 Jan 2020 12:46:11 +0100

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

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

commit 33a296620c0b0f5753be9bbb4b56d46457515dd4
Author: Dennis Neufeld <address@hidden>
AuthorDate: Wed Jan 22 11:43:16 2020 +0000

    Worked on policy upload. Payment is working, uploading afterwards not...
---
 src/backend/anastasis-httpd_policy_upload.c |  5 ++-
 src/include/anastasis_service.h             |  2 +-
 src/include/anastasis_testing_lib.h         | 17 ++++++----
 src/lib/anastasis_api_policy_store.c        | 26 +++++++++------
 src/lib/test_anastasis_api.c                |  4 ++-
 src/lib/testing_api_cmd_policy_store.c      | 52 ++++++++++++++++-------------
 6 files changed, 60 insertions(+), 46 deletions(-)

diff --git a/src/backend/anastasis-httpd_policy_upload.c 
b/src/backend/anastasis-httpd_policy_upload.c
index f6336f8..62572c4 100644
--- a/src/backend/anastasis-httpd_policy_upload.c
+++ b/src/backend/anastasis-httpd_policy_upload.c
@@ -249,7 +249,7 @@ amount_to_post_counter (const struct TALER_Amount *amount)
  *                    0 if the backend's reply is bogus (fails to follow the 
protocol)
  * @param ec taler-specific error code
  * @param obj raw JSON reply, or error details if the request failed
- * @param payment_identifier_str payment_identifier base64 encoded of the 
newly created order
+ * @param order_id payment_identifier (base32 encoded) of the newly created 
order
  */
 static void
 proposal_cb (void *cls,
@@ -467,7 +467,6 @@ begin_payment (struct PolicyUploadContext *puc,
                                                     sizeof(
                                                       struct
                                                       
ANASTASIS_PaymentSecretP));
-
   }
 
   if (qs == ANASTASIS_DB_STATUS_NO_RESULTS)
@@ -707,7 +706,7 @@ AH_handler_policy_post (struct MHD_Connection *connection,
             GNUNET_STRINGS_string_to_data (pay_id,
                                            strlen (pay_id),
                                            &puc->payment_identifier,
-                                           sizeof (&puc->payment_identifier))) 
)
+                                           sizeof (struct 
ANASTASIS_PaymentSecretP))) )
       {
         GNUNET_break_op (0);
         return TALER_MHD_reply_with_error (connection,
diff --git a/src/include/anastasis_service.h b/src/include/anastasis_service.h
index 83c2ee5..a568491 100644
--- a/src/include/anastasis_service.h
+++ b/src/include/anastasis_service.h
@@ -399,7 +399,7 @@ ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
                         size_t recovery_data_size,
                         int payment_requested,
                         const struct
-                        ANASTASIS_PaymentSecretP *paymentSecretP,
+                        ANASTASIS_PaymentSecretP paymentSecretP,
                         ANASTASIS_PolicyStoreCallback cb,
                         void *cb_cls);
 
diff --git a/src/include/anastasis_testing_lib.h 
b/src/include/anastasis_testing_lib.h
index 76a2e2b..f4e7a9c 100644
--- a/src/include/anastasis_testing_lib.h
+++ b/src/include/anastasis_testing_lib.h
@@ -252,23 +252,26 @@ enum ANASTASIS_TESTING_PolicyStoreOption
  * @param label command label
  * @param anastasis_url base URL of the anastasis serving
  *        the policy store request.
+ * @param prev_upload reference to a previous upload we are
+ *        supposed to update, NULL for none
+ * @param last_upload reference to the last upload for the
+ *          same account, used to check result on MHD_HTTP_CONFLICT
  * @param http_status expected HTTP status.
- * @param priv private account identifier
- * @param pub account identifier
- * @param payment_id payment identifier
- * @param policy_data recovery data to post /policy
- * @param policy_data_size size of recovery data
+ * @param pso policy store options
+ * @param recovery_data recovery data to post
+ * @param recovery_data_size size of recovery/policy data
  * @return the command
  */
 struct TALER_TESTING_Command
 ANASTASIS_TESTING_cmd_policy_store (const char *label,
                                     const char *anastasis_url,
                                     const char *prev_upload,
+                                    const char *last_upload,
                                     unsigned int http_status,
                                     enum
                                     ANASTASIS_TESTING_PolicyStoreOption pso,
-                                    const void *policy_data,
-                                    size_t policy_data_size);
+                                    const void *recovery_data,
+                                    size_t recovery_data_size);
 
 /**
  * Make the "policy lookup" command.
diff --git a/src/lib/anastasis_api_policy_store.c 
b/src/lib/anastasis_api_policy_store.c
index b569f7f..b0a76f7 100644
--- a/src/lib/anastasis_api_policy_store.c
+++ b/src/lib/anastasis_api_policy_store.c
@@ -73,7 +73,7 @@ struct ANASTASIS_PolicyStoreOperation
   /**
    * Hash of the data we are uploading.
    */
-  struct GNUNET_HashCode new_recovery_data_hash;
+  struct GNUNET_HashCode new_upload_hash;
 };
 
 /**
@@ -124,13 +124,13 @@ handle_policy_store_finished (void *cls,
     break;
   case MHD_HTTP_NO_CONTENT:
     ud.us = ANASTASIS_US_SUCCESS;
-    ud.details.curr_backup_hash = &pso->new_recovery_data_hash;
+    ud.details.curr_backup_hash = &pso->new_upload_hash;
     udp = &ud;
     ec = TALER_EC_NONE;
     break;
   case MHD_HTTP_NOT_MODIFIED:
     ud.us = ANASTASIS_US_SUCCESS;
-    ud.details.curr_backup_hash = &pso->new_recovery_data_hash;
+    ud.details.curr_backup_hash = &pso->new_upload_hash;
     udp = &ud;
     ec = TALER_EC_NONE;
     break;
@@ -277,7 +277,7 @@ ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
                         size_t recovery_data_size,
                         int payment_requested,
                         const struct
-                        ANASTASIS_PaymentSecretP *paymentSecretP,
+                        ANASTASIS_PaymentSecretP paymentSecretP,
                         ANASTASIS_PolicyStoreCallback cb,
                         void *cb_cls)
 {
@@ -369,10 +369,10 @@ ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
       job_headers = ext;
     }
     /* Setup Payment-Identifier header */
-    if (NULL != paymentSecretP)
+    if (NULL != &paymentSecretP)
     {
       val = GNUNET_STRINGS_data_to_string_alloc (&paymentSecretP,
-                                                 sizeof (paymentSecretP));
+                                                 sizeof (struct 
ANASTASIS_PaymentSecretP));
       GNUNET_asprintf (&hdr,
                        "Payment-Identifier: %s",
                        val);
@@ -393,7 +393,7 @@ ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
   /* Finished setting up headers */
 
   pso = GNUNET_new (struct ANASTASIS_PolicyStoreOperation);
-  pso->new_recovery_data_hash = usp.new_recovery_data_hash;
+  pso->new_upload_hash = usp.new_recovery_data_hash;
   {
     char *acc_pub_str;
     char *path;
@@ -409,23 +409,27 @@ ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
                      acc_pub_str);
     GNUNET_free (acc_pub_str);
 
+    char *paid_order_id;
+    paid_order_id = GNUNET_STRINGS_data_to_string_alloc (&paymentSecretP,
+                                                         sizeof (struct 
ANASTASIS_PaymentSecretP));
     pso->url = (GNUNET_YES == payment_requested)
               ? TALER_url_join (backend_url,
                                 path,
                                 "pay",
                                 "y",
-                                (NULL != paymentSecretP)
+                                (NULL != paid_order_id)
                                 ? "paying"
                                 : NULL,
-                                paymentSecretP,
+                                paid_order_id,
                                 NULL)
               : TALER_url_join (backend_url,
                                 path,
-                                (NULL != paymentSecretP)
+                                (NULL != paid_order_id)
                                 ? "paying"
                                 : NULL,
-                                paymentSecretP,
+                                paid_order_id,
                                 NULL);
+    GNUNET_free_non_null (paid_order_id);
     GNUNET_free (path);
   }
   pso->ctx = ctx;
diff --git a/src/lib/test_anastasis_api.c b/src/lib/test_anastasis_api.c
index f41440a..c04ca38 100644
--- a/src/lib/test_anastasis_api.c
+++ b/src/lib/test_anastasis_api.c
@@ -262,7 +262,8 @@ run (void *cls,
 
     ANASTASIS_TESTING_cmd_policy_store ("policy-store-1",
                                         anastasis_url,
-                                        NULL,
+                                        NULL /* prev upload */,
+                                        NULL /* last upload */,
                                         MHD_HTTP_PAYMENT_REQUIRED,
                                         ANASTASIS_TESTING_PSO_NONE,
                                         "Test-1",
@@ -287,6 +288,7 @@ run (void *cls,
     ANASTASIS_TESTING_cmd_policy_store ("policy-store-2",
                                         anastasis_url,
                                         "policy-store-1",
+                                        NULL /* last upload */,
                                         MHD_HTTP_NO_CONTENT,
                                         ANASTASIS_TESTING_PSO_NONE,
                                         "Test-1",
diff --git a/src/lib/testing_api_cmd_policy_store.c 
b/src/lib/testing_api_cmd_policy_store.c
index cfb4cf1..10941e5 100644
--- a/src/lib/testing_api_cmd_policy_store.c
+++ b/src/lib/testing_api_cmd_policy_store.c
@@ -95,7 +95,7 @@ struct PolicyStoreState
   /**
    * Payment identifier.
    */
-  struct ANASTASIS_PaymentSecretP *payment_id;
+  struct ANASTASIS_PaymentSecretP payment_id;
 
   /**
    * Previous upload, or NULL for none. Used to calculate what THIS
@@ -315,20 +315,6 @@ policy_store_run (void *cls,
       }
       pss->anastasis_pub = *pub;
     }
-    {
-      const struct ANASTASIS_PaymentSecretP *payment_identifier;
-
-      if (GNUNET_OK !=
-          ANASTASIS_TESTING_get_trait_payment_identifier (ref,
-                                                          0,
-                                                          &payment_identifier))
-      {
-        GNUNET_break (0);
-        TALER_TESTING_interpreter_fail (pss->is);
-        return;
-      }
-      pss->payment_id = payment_identifier;
-    }
     if (0 != (ANASTASIS_TESTING_PSO_REFERENCE_ORDER_ID & pss->psopt))
     {
       {
@@ -350,6 +336,17 @@ policy_store_run (void *cls,
           TALER_TESTING_interpreter_fail (pss->is);
           return;
         }
+        
+        if (GNUNET_OK !=
+            GNUNET_STRINGS_string_to_data (order_id,
+                                           strlen (order_id),
+                                           &pss->payment_id,
+                                           sizeof (struct 
ANASTASIS_PaymentSecretP)))
+        {
+          GNUNET_break (0);
+          TALER_TESTING_interpreter_fail (pss->is);
+          return;
+        }
       }
     }
   }
@@ -364,12 +361,17 @@ policy_store_run (void *cls,
                                         &pss->anastasis_pub.pub);
     GNUNET_free (priv);
   }
-  {
-    // hash recovery data
-    GNUNET_CRYPTO_hash (pss->recovery_data,
-                        pss->recovery_data_size,
-                        &pss->curr_hash);
-  }
+  
+  if (0 != (ANASTASIS_TESTING_PSO_PREV_HASH_WRONG & pss->psopt))
+    GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+                              &pss->prev_hash,
+                              sizeof (struct GNUNET_HashCode));
+
+  // hash recovery data
+  GNUNET_CRYPTO_hash (pss->recovery_data,
+                      pss->recovery_data_size,
+                      &pss->curr_hash);
+  
   pss->pso = ANASTASIS_policy_store (is->ctx,
                                      pss->anastasis_url,
                                      &pss->anastasis_priv,
@@ -450,8 +452,6 @@ policy_store_traits (void *cls,
                                                &pss->anastasis_priv),
     TALER_TESTING_make_trait_order_id (0,
                                        pss->payment_order_id),
-    ANASTASIS_TESTING_make_trait_payment_identifier (0,
-                                                     &pss->payment_id),
     TALER_TESTING_trait_end ()
   };
 
@@ -468,6 +468,10 @@ policy_store_traits (void *cls,
  * @param label command label
  * @param anastasis_url base URL of the anastasis serving
  *        the policy store request.
+ * @param prev_upload reference to a previous upload we are
+ *        supposed to update, NULL for none
+ * @param last_upload reference to the last upload for the
+ *          same account, used to check result on MHD_HTTP_CONFLICT
  * @param http_status expected HTTP status.
  * @param pso policy store options
  * @param recovery_data recovery data to post
@@ -478,6 +482,7 @@ struct TALER_TESTING_Command
 ANASTASIS_TESTING_cmd_policy_store (const char *label,
                                     const char *anastasis_url,
                                     const char *prev_upload,
+                                    const char *last_upload,
                                     unsigned int http_status,
                                     enum
                                     ANASTASIS_TESTING_PolicyStoreOption pso,
@@ -493,6 +498,7 @@ ANASTASIS_TESTING_cmd_policy_store (const char *label,
   pss->psopt = pso;
   pss->anastasis_url = anastasis_url;
   pss->prev_upload = prev_upload;
+  pss->last_upload = last_upload;
 
   struct TALER_TESTING_Command cmd = {
     .cls = pss,

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



reply via email to

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