gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: -fix misc bugs


From: gnunet
Subject: [taler-anastasis] branch master updated: -fix misc bugs
Date: Sun, 11 Jul 2021 14:51:10 +0200

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

grothoff pushed a commit to branch master
in repository anastasis.

The following commit(s) were added to refs/heads/master by this push:
     new da96091  -fix misc bugs
da96091 is described below

commit da960915f8e8abb578502f240ea0a5adb96588dd
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Jul 11 14:51:08 2021 +0200

    -fix misc bugs
---
 src/backend/anastasis-httpd_truth_upload.c         | 50 ++++++++++-------
 src/cli/test_anastasis_reducer_enter_secret.sh     | 62 +++++++++++++++++++---
 ...tasis_reducer_recovery_enter_user_attributes.sh |  4 ++
 src/cli/test_reducer.conf                          |  1 +
 src/reducer/anastasis_api_backup_redux.c           | 16 ++++--
 5 files changed, 103 insertions(+), 30 deletions(-)

diff --git a/src/backend/anastasis-httpd_truth_upload.c 
b/src/backend/anastasis-httpd_truth_upload.c
index b2cf07c..654e021 100644
--- a/src/backend/anastasis-httpd_truth_upload.c
+++ b/src/backend/anastasis-httpd_truth_upload.c
@@ -77,6 +77,11 @@ struct TruthUploadContext
    */
   struct MHD_Connection *connection;
 
+  /**
+   * Incoming JSON, NULL if not yet available.
+   */
+  json_t *json;
+
   /**
    * HTTP response code to use on resume, if non-NULL.
    */
@@ -158,6 +163,8 @@ cleanup_truth_post (struct TM_HandlerContext *hc)
     TALER_MERCHANT_merchant_order_get_cancel (tuc->cpo);
   if (NULL != tuc->resp)
     MHD_destroy_response (tuc->resp);
+  if (NULL != tuc->json)
+    json_decref (tuc->json);
   GNUNET_free (tuc);
 }
 
@@ -492,7 +499,6 @@ AH_handler_truth_post (
   size_t *truth_data_size)
 {
   struct TruthUploadContext *tuc = hc->ctx;
-  json_t *json;
   MHD_RESULT ret;
   int res;
   struct ANASTASIS_CRYPTO_EncryptedKeyShareP keyshare_data;
@@ -529,14 +535,16 @@ AH_handler_truth_post (
     {
       const char *lens;
       unsigned long len;
+      char dummy;
 
       lens = MHD_lookup_connection_value (connection,
                                           MHD_HEADER_KIND,
                                           MHD_HTTP_HEADER_CONTENT_LENGTH);
       if ( (NULL == lens) ||
            (1 != sscanf (lens,
-                         "%lu",
-                         &len)) )
+                         "%lu%c",
+                         &len,
+                         &dummy)) )
       {
         GNUNET_break_op (0);
         return TALER_MHD_reply_with_error (
@@ -609,21 +617,24 @@ AH_handler_truth_post (
     return ret;
   }
 
-  res = TALER_MHD_parse_post_json (connection,
-                                   &tuc->post_ctx,
-                                   truth_data,
-                                   truth_data_size,
-                                   &json);
-  if (GNUNET_SYSERR == res)
+  if (NULL == tuc->json)
   {
-    GNUNET_break (0);
-    return MHD_NO;
+    res = TALER_MHD_parse_post_json (connection,
+                                     &tuc->post_ctx,
+                                     truth_data,
+                                     truth_data_size,
+                                     &tuc->json);
+    if (GNUNET_SYSERR == res)
+    {
+      GNUNET_break (0);
+      return MHD_NO;
+    }
+    if ( (GNUNET_NO == res) ||
+         (NULL == tuc->json) )
+      return MHD_YES;
   }
-  if ( (GNUNET_NO == res) ||
-       (NULL == json) )
-    return MHD_YES;
   res = TALER_MHD_parse_json_data (connection,
-                                   json,
+                                   tuc->json,
                                    spec);
   if (GNUNET_SYSERR == res)
   {
@@ -631,7 +642,10 @@ AH_handler_truth_post (
     return MHD_NO;   /* hard failure */
   }
   if (GNUNET_NO == res)
+  {
+    GNUNET_break_op (0);
     return MHD_YES;   /* failure */
+  }
 
   /* check method is supported */
   {
@@ -698,6 +712,8 @@ AH_handler_truth_post (
                                                    desired_until);
         tuc->years_to_pay = rem.rel_value_us
                             / GNUNET_TIME_UNIT_YEARS.rel_value_us;
+        if (0 != (rem.rel_value_us % GNUNET_TIME_UNIT_YEARS.rel_value_us))
+          tuc->years_to_pay++;
         if (0 >
             TALER_amount_multiply (&tuc->upload_fee,
                                    &AH_truth_upload_fee,
@@ -744,7 +760,6 @@ AH_handler_truth_post (
   case GNUNET_DB_STATUS_HARD_ERROR:
   case GNUNET_DB_STATUS_SOFT_ERROR:
     GNUNET_break (0);
-    json_decref (json);
     GNUNET_JSON_parse_free (spec);
     return TALER_MHD_reply_with_error (connection,
                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
@@ -780,7 +795,6 @@ AH_handler_truth_post (
       }
       if (! ok)
       {
-        json_decref (json);
         GNUNET_JSON_parse_free (spec);
 
         return TALER_MHD_reply_with_error (connection,
@@ -794,7 +808,6 @@ AH_handler_truth_post (
     {
       struct MHD_Response *resp;
 
-      json_decref (json);
       GNUNET_JSON_parse_free (spec);
       resp = MHD_create_response_from_buffer (0,
                                               NULL,
@@ -808,7 +821,6 @@ AH_handler_truth_post (
       return ret;
     }
   }
-  json_decref (json);
   GNUNET_JSON_parse_free (spec);
   GNUNET_break (0);
   return MHD_NO;
diff --git a/src/cli/test_anastasis_reducer_enter_secret.sh 
b/src/cli/test_anastasis_reducer_enter_secret.sh
index 358d517..ecbbb07 100755
--- a/src/cli/test_anastasis_reducer_enter_secret.sh
+++ b/src/cli/test_anastasis_reducer_enter_secret.sh
@@ -275,9 +275,52 @@ $PREFIX anastasis-reducer -a \
   '{"secret": { "value" : "veryhardtoguesssecret", "mime" : "text/plain" } }' \
   enter_secret resources/06-backup.json $TFILE
 
+STATE=`jq -r -e .backup_state < $TFILE`
+if test "$STATE" != "SECRET_EDITING"
+then
+    jq < $TFILE
+    exit_fail "Expected new state to be 'SECRET_EDITING', got '$STATE'"
+fi
+
+echo " DONE"
+echo -en $COLOR$BOLD"Test expiration change ..."$NORM$NOCOLOR
+
+MILLIS=`date '+%s'`000
+# Use 156 days into the future to get 1 year
+MILLIS=`expr $MILLIS + 13478400000`
+
+$PREFIX anastasis-reducer -a \
+  "$(jq -n '
+   {"expiration": { "t_ms" : $MSEC } }' \
+   --argjson MSEC $MILLIS
+  )" \
+  update_expiration $TFILE $UFILE
+
+STATE=`jq -r -e .backup_state < $UFILE`
+if test "$STATE" != "SECRET_EDITING"
+then
+    jq < $UFILE
+    exit_fail "Expected new state to be 'SECRET_EDITING', got '$STATE'"
+fi
+
+FEES=`jq -r -e '.upload_fees[0]' < $UFILE`
+# 4x 4.99 for annual fees, plus 4x0.01 for truth uploads
+if test "$FEES" != "TESTKUDOS:20"
+then
+    jq < $TFILE
+    exit_fail "Expected upload fees to be 'TESTKUDOS:19.96', got '$FEES'"
+fi
+
+
+echo " DONE"
+echo -en $COLOR$BOLD"Test advance to payment ..."$NORM$NOCOLOR
+
+$PREFIX anastasis-reducer next $UFILE $TFILE
+
 STATE=`jq -r -e .backup_state < $TFILE`
 if test "$STATE" != "TRUTHS_PAYING"
 then
+    jq < $TFILE
     exit_fail "Expected new state to be 'TRUTHS_PAYING', got '$STATE'"
 fi
 
@@ -296,14 +339,14 @@ rm $WALLET_DB
 taler-wallet-cli --no-throttle --wallet-db=$WALLET_DB api 
'withdrawTestBalance' \
   "$(jq -n '
     {
-        amount: "TESTKUDOS:20",
+        amount: "TESTKUDOS:40",
         bankBaseUrl: $BANK_URL,
         exchangeBaseUrl: $EXCHANGE_URL
     }' \
     --arg BANK_URL "$BANK_URL" \
     --arg EXCHANGE_URL "$EXCHANGE_URL"
-  )" 2> /dev/null >/dev/null
-taler-wallet-cli --wallet-db=$WALLET_DB run-until-done 2>/dev/null >/dev/null
+  )" 2>wallet.err >wallet.log
+taler-wallet-cli --wallet-db=$WALLET_DB run-until-done 2>wallet.err >wallet.log
 
 echo " OK"
 
@@ -314,14 +357,15 @@ do
     PAY_URI=`jq --argjson INDEX $INDEX -r -e '.payments[$INDEX]' < $TFILE`
     # run wallet CLI
     echo -n "$INDEX"
-    taler-wallet-cli --wallet-db=$WALLET_DB handle-uri $PAY_URI -y 2>/dev/null 
>/dev/null
+    taler-wallet-cli --wallet-db=$WALLET_DB handle-uri $PAY_URI -y 
2>wallet.err >wallet.log
     echo -n ","
 done
 echo " OK"
 echo -e $COLOR$BOLD"Running wallet run-pending..."$NORM$NOCOLOR
-taler-wallet-cli --wallet-db=$WALLET_DB run-pending 2>/dev/null >/dev/null
+taler-wallet-cli --wallet-db=$WALLET_DB run-pending 2>wallet.err >wallet.log
 echo -e $COLOR$BOLD"Payments done"$NORM$NOCOLOR
 
+
 echo -en $COLOR$BOLD"Try to upload again ..."$NORM$NOCOLOR
 $PREFIX anastasis-reducer pay $TFILE $UFILE
 mv $UFILE $TFILE
@@ -334,6 +378,8 @@ then
     exit_fail "Expected new state to be 'POLICIES_PAYING', got '$STATE'"
 fi
 
+export TFILE
+export UFILE
 
 echo -en $COLOR$BOLD"Making payments for policy uploads ... "$NORM$NOCOLOR
 OBJECT_SIZE=`jq -r -e '.policy_payment_requests | length' < $TFILE`
@@ -341,13 +387,15 @@ for ((INDEX=0; INDEX < $OBJECT_SIZE; INDEX++))
 do
     PAY_URI=`jq --argjson INDEX $INDEX -r -e 
'.policy_payment_requests[$INDEX].payto' < $TFILE`
     # run wallet CLI
+    export PAY_URI
+    bash
     echo -n "$INDEX"
-    taler-wallet-cli --wallet-db=$WALLET_DB handle-uri $PAY_URI -y 2>/dev/null 
>/dev/null
+    taler-wallet-cli --wallet-db=$WALLET_DB handle-uri $PAY_URI -y 
2>wallet.err >wallet.log
     echo -n ","
 done
 echo " OK"
 echo -e $COLOR$BOLD"Running wallet run-pending..."$NORM$NOCOLOR
-taler-wallet-cli --wallet-db=$WALLET_DB run-pending 2>/dev/null >/dev/null
+taler-wallet-cli --wallet-db=$WALLET_DB run-pending 2>wallet.err >wallet.log
 echo -e $COLOR$BOLD"Payments done"$NORM$NOCOLOR
 
 echo -en $COLOR$BOLD"Try to upload again ..."$NORM$NOCOLOR
diff --git a/src/cli/test_anastasis_reducer_recovery_enter_user_attributes.sh 
b/src/cli/test_anastasis_reducer_recovery_enter_user_attributes.sh
index 12e0197..bd4617c 100755
--- a/src/cli/test_anastasis_reducer_recovery_enter_user_attributes.sh
+++ b/src/cli/test_anastasis_reducer_recovery_enter_user_attributes.sh
@@ -327,7 +327,11 @@ echo -n "."
 anastasis-reducer -a \
   '{"secret": { "value" : "VERYHARDT0GVESSSECRET", "mime" : "text/plain" }}' \
   enter_secret < $B1FILE > $B2FILE
+mv $B2FILE $B1FILE
+anastasis-reducer next $B1FILE $B2FILE
 echo " OK"
+
+
 echo -n "Preparing wallet"
 rm $WALLET_DB
 taler-wallet-cli --no-throttle --wallet-db=$WALLET_DB api 
'withdrawTestBalance' \
diff --git a/src/cli/test_reducer.conf b/src/cli/test_reducer.conf
index 7ef03c9..a4baaed 100644
--- a/src/cli/test_reducer.conf
+++ b/src/cli/test_reducer.conf
@@ -15,6 +15,7 @@ PAYMENT_BACKEND_URL = http://localhost:9966/
 ANNUAL_FEE = TESTKUDOS:4.99
 TRUTH_UPLOAD_FEE = TESTKUDOS:0.01
 UPLOAD_LIMIT_MB = 1
+ANNUAL_POLICY_UPLOAD_LIMIT = 128
 INSURANCE = TESTKUDOS:1.0
 
 [authorization-question]
diff --git a/src/reducer/anastasis_api_backup_redux.c 
b/src/reducer/anastasis_api_backup_redux.c
index 23e97e3..7044eae 100644
--- a/src/reducer/anastasis_api_backup_redux.c
+++ b/src/reducer/anastasis_api_backup_redux.c
@@ -2250,7 +2250,7 @@ expiration_to_years (struct GNUNET_TIME_Absolute 
expiration)
 
   rem = GNUNET_TIME_absolute_get_remaining (expiration);
   years = rem.rel_value_us / GNUNET_TIME_UNIT_YEARS.rel_value_us;
-  if (0 != rem.rel_value_us / GNUNET_TIME_UNIT_YEARS.rel_value_us)
+  if (0 != rem.rel_value_us % GNUNET_TIME_UNIT_YEARS.rel_value_us)
     years++;
   return years;
 }
@@ -2328,7 +2328,7 @@ update_expiration_cost (json_t *state,
     {
       uint32_t method;
       const char *provider_url;
-    } *seen;
+    } *seen = NULL;
     json_t *policies;
     size_t pidx;
     json_t *policy;
@@ -3276,7 +3276,6 @@ static void
 check_upload_finished (struct UploadContext *uc)
 {
   bool pay = false;
-  enum TALER_ErrorCode failed = TALER_EC_NONE;
   bool active = false;
 
   for (struct TruthUpload *tue = uc->tues_head;
@@ -3286,7 +3285,7 @@ check_upload_finished (struct UploadContext *uc)
     if (TALER_EC_NONE != tue->ec)
     {
       uc->cb (uc->cb_cls,
-              failed,
+              tue->ec,
               uc->state);
       upload_cancel_cb (uc);
       return;
@@ -4120,6 +4119,9 @@ enter_secret (json_t *state,
                                       "core_secret",
                                       GNUNET_JSON_from_data (secret,
                                                              secret_size)));
+  cb (cb_cls,
+      TALER_EC_NONE,
+      state);
   GNUNET_JSON_parse_free (spec);
   return NULL;
 }
@@ -4152,6 +4154,7 @@ update_expiration (json_t *state,
 
   if (NULL == arguments)
   {
+    GNUNET_break (0);
     ANASTASIS_redux_fail_ (cb,
                            cb_cls,
                            TALER_EC_ANASTASIS_REDUCER_INPUT_INVALID,
@@ -4163,6 +4166,7 @@ update_expiration (json_t *state,
                          spec,
                          NULL, NULL))
   {
+    GNUNET_break (0);
     ANASTASIS_redux_fail_ (cb,
                            cb_cls,
                            TALER_EC_ANASTASIS_REDUCER_INPUT_INVALID,
@@ -4173,12 +4177,16 @@ update_expiration (json_t *state,
       update_expiration_cost (state,
                               expiration))
   {
+    GNUNET_break (0);
     ANASTASIS_redux_fail_ (cb,
                            cb_cls,
                            TALER_EC_ANASTASIS_REDUCER_INPUT_INVALID_FOR_STATE,
                            "could not calculate expiration cost");
     return NULL;
   }
+  cb (cb_cls,
+      TALER_EC_NONE,
+      state);
   return NULL;
 }
 

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