gnunet-svn
[Top][All Lists]
Advanced

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

[taler-sync] branch master updated: work on upload command


From: gnunet
Subject: [taler-sync] branch master updated: work on upload command
Date: Fri, 29 Nov 2019 20:17:24 +0100

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

grothoff pushed a commit to branch master
in repository sync.

The following commit(s) were added to refs/heads/master by this push:
     new 399392b  work on upload command
399392b is described below

commit 399392b6dccd1fa074406463324ff500be71b26e
Author: Christian Grothoff <address@hidden>
AuthorDate: Fri Nov 29 20:17:22 2019 +0100

    work on upload command
---
 src/include/sync_testing_lib.h                     |  55 ++++++++
 .../.local/share/taler/auditors/auditor.out        | Bin 42328 -> 42328 bytes
 src/lib/testing_api_cmd_backup_upload.c            | 143 +++++++++++++++++++--
 3 files changed, 184 insertions(+), 14 deletions(-)

diff --git a/src/include/sync_testing_lib.h b/src/include/sync_testing_lib.h
index 8bb11af..25594e1 100644
--- a/src/include/sync_testing_lib.h
+++ b/src/include/sync_testing_lib.h
@@ -177,4 +177,59 @@ SYNC_TESTING_cmd_backup_download (const char *label,
                                   unsigned int http_status,
                                   const char *upload_ref);
 
+
+/**
+ * Types of options for performing the upload. Used as a bitmask.
+ */
+enum SYNC_TESTING_UploadOption
+{
+  /**
+   * Do everything by the book.
+   */
+  SYNC_TESTING_UO_NONE = 0,
+
+  /**
+   * Use random hash for previous upload instead of correct
+   * previous hash.
+   */
+  SYNC_TESTING_UO_PREV_HASH_WRONG = 1,
+
+  /**
+   * Request payment.
+   */
+  SYNC_TESTING_UO_REQUEST_PAYMENT = 2,
+
+  /**
+   * Reference payment order ID from linked previous upload.
+   */
+  SYNC_TESTING_UO_REFERENCE_ORDER_ID = 4
+
+
+};
+
+
+/**
+ * Make the "backup upload" command.
+ *
+ * @param label command label
+ * @param sync_url base URL of the sync serving
+ *        the policy store request.
+ * @param prev_upload reference to a previous upload we are
+ *        supposed to update, NULL for none
+ * @param http_status expected HTTP status.
+ * @param pub account identifier
+ * @param payment_id payment identifier
+ * @param policy_data recovery data to post
+ *
+ * @return the command
+ */
+struct TALER_TESTING_Command
+SYNC_TESTING_cmd_backup_upload (const char *label,
+                                const char *sync_url,
+                                const char *prev_upload,
+                                enum SYNC_TESTING_UploadOption uo,
+                                unsigned int http_status,
+                                const void *backup_data,
+                                size_t backup_data_size);
+
 #endif
diff --git a/src/lib/test_sync_api_home/.local/share/taler/auditors/auditor.out 
b/src/lib/test_sync_api_home/.local/share/taler/auditors/auditor.out
index 273ebcc..a15de52 100644
Binary files 
a/src/lib/test_sync_api_home/.local/share/taler/auditors/auditor.out and 
b/src/lib/test_sync_api_home/.local/share/taler/auditors/auditor.out differ
diff --git a/src/lib/testing_api_cmd_backup_upload.c 
b/src/lib/testing_api_cmd_backup_upload.c
index e2b792e..6880205 100644
--- a/src/lib/testing_api_cmd_backup_upload.c
+++ b/src/lib/testing_api_cmd_backup_upload.c
@@ -34,24 +34,26 @@ struct BackupUploadState
 {
 
   /**
-   * The backup data we are uploading.
+   * Eddsa private key.
    */
-  const void *backup;
+  struct SYNC_AccountPrivateKeyP sync_priv;
 
   /**
-   * Number of bytes in @e backup.
+   * Eddsa public key.
    */
-  size_t backup_size;
+  struct SYNC_AccountPublicKeyP sync_pub;
 
   /**
-   * Expected status code.
+   * Hash of the previous upload (maybe bogus if
+   * #SYNC_TESTING_UO_PREV_HASH_WRONG is set in @e uo).
+   * Maybe all zeros if there was no previous upload.
    */
-  unsigned int http_status;
+  struct GNUNET_HashCode prev_hash;
 
   /**
-   * Eddsa private key.
+   * Hash of the current upload.
    */
-  struct SYNC_AccountPrivateKeyP sync_priv;
+  struct GNUNET_HashCode curr_hash;
 
   /**
    * The /backups POST operation handle.
@@ -63,11 +65,46 @@ struct BackupUploadState
    */
   const char *sync_url;
 
+  /**
+   * Previous upload, or NULL for none.
+   */
+  const char *prev_upload;
+
+  /**
+   * Payment order ID we got back, if any. Otherwise NULL.
+   */
+  char *payment_order_id;
+
+  /**
+   * Payment order ID we are to provide in the request, may be NULL.
+   */
+  const char *payment_order_req;
+
   /**
    * The interpreter state.
    */
   struct TALER_TESTING_Interpreter *is;
 
+  /**
+   * The backup data we are uploading.
+   */
+  const void *backup;
+
+  /**
+   * Number of bytes in @e backup.
+   */
+  size_t backup_size;
+
+  /**
+   * Expected status code.
+   */
+  unsigned int http_status;
+
+  /**
+   * Options for how we are supposed to do the upload.
+   */
+  enum SYNC_TESTING_UploadOption uopt;
+
 };
 
 
@@ -87,7 +124,22 @@ backup_upload_cb (void *cls,
 {
   struct BackupUploadState *bus = cls;
 
-  // FIXME: next!
+  bus->uo = NULL;
+  if (http_status != bus->http_status)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unexpected response code %u to command %s in %s:%u\n",
+                http_status,
+                bus->is->commands[bus->is->ip].label,
+                __FILE__,
+                __LINE__);
+    TALER_TESTING_interpreter_fail (bus->is);
+    return;
+  }
+
+  // FIXME: check ud, store result!
+
+  TALER_TESTING_interpreter_next (bus->is);
 }
 
 
@@ -106,19 +158,73 @@ backup_upload_run (void *cls,
   struct BackupUploadState *bus = cls;
 
   bus->is = is;
+  if (NULL != bus->prev_upload)
+  {
+    const struct TALER_TESTING_Command *ref;
+    const struct BackupUploadState *prev;
+
+    ref = TALER_TESTING_interpreter_lookup_command
+            (is,
+            bus->prev_upload);
+    if (NULL == ref)
+    {
+      GNUNET_break (0);
+      TALER_TESTING_interpreter_fail (bus->is);
+      return;
+    }
+    if (ref->run != &backup_upload_run)
+    {
+      GNUNET_break (0);
+      TALER_TESTING_interpreter_fail (bus->is);
+      return;
+    }
+    prev = ref->cls;
+    bus->sync_priv = prev->sync_priv;
+    bus->sync_pub = prev->sync_pub;
+    bus->prev_hash = prev->curr_hash;
+    if (0 != (SYNC_TESTING_UO_REFERENCE_ORDER_ID & bus->uopt))
+    {
+      bus->payment_order_req = prev->payment_order_id;
+      if (NULL == bus->payment_order_req)
+      {
+        GNUNET_break (0);
+        TALER_TESTING_interpreter_fail (bus->is);
+        return;
+      }
+    }
+  }
+  else
+  {
+    struct GNUNET_CRYPTO_EddsaPrivateKey *priv;
+
+    priv = GNUNET_CRYPTO_eddsa_key_create ();
+    bus->sync_priv.eddsa_priv = *priv;
+    GNUNET_CRYPTO_eddsa_key_get_public (priv,
+                                        &bus->sync_pub.eddsa_pub);
+    GNUNET_free (priv);
+  }
+  if (0 != (SYNC_TESTING_UO_PREV_HASH_WRONG & bus->uopt))
+    GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+                                &bus->prev_hash,
+                                sizeof (struct GNUNET_HashCode));
+  GNUNET_CRYPTO_hash (bus->backup,
+                      bus->backup_size,
+                      &bus->curr_hash);
   bus->uo = SYNC_upload (is->ctx,
                          bus->sync_url,
                          &bus->sync_priv,
-                         NULL /* prev hash */,
+                         &bus->prev_hash,
                          bus->backup_size,
                          bus->backup,
-                         GNUNET_NO /* payment req */,
-                         NULL /* pay order id */,
+                         (0 != (SYNC_TESTING_UO_REQUEST_PAYMENT & bus->uopt)),
+                         bus->payment_order_req,
                          &backup_upload_cb,
                          bus);
   if (NULL == bus->uo)
   {
-    // FIMXE: fail!
+    GNUNET_break (0);
+    TALER_TESTING_interpreter_fail (bus->is);
+    return;
   }
 }
 
@@ -144,16 +250,19 @@ backup_upload_cleanup (void *cls,
     SYNC_upload_cancel (bus->uo);
     bus->uo = NULL;
   }
+  GNUNET_free_non_null (bus->payment_order_id);
   GNUNET_free (bus);
 }
 
 
 /**
- * Make the "policy store" command.
+ * Make the "backup upload" command.
  *
  * @param label command label
  * @param sync_url base URL of the sync serving
  *        the policy store request.
+ * @param prev_upload reference to a previous upload we are
+ *        supposed to update, NULL for none
  * @param http_status expected HTTP status.
  * @param pub account identifier
  * @param payment_id payment identifier
@@ -164,6 +273,8 @@ backup_upload_cleanup (void *cls,
 struct TALER_TESTING_Command
 SYNC_TESTING_cmd_backup_upload (const char *label,
                                 const char *sync_url,
+                                const char *prev_upload,
+                                enum SYNC_TESTING_UploadOption uo,
                                 unsigned int http_status,
                                 const void *backup_data,
                                 size_t backup_data_size)
@@ -172,9 +283,13 @@ SYNC_TESTING_cmd_backup_upload (const char *label,
 
   bus = GNUNET_new (struct BackupUploadState);
   bus->http_status = http_status;
+  bus->prev_upload = prev_upload;
+  bus->uopt = uo;
   bus->sync_url = sync_url;
   bus->backup = backup_data;
   bus->backup_size = backup_data_size;
+  // FIXME: traits!
+
   {
     struct TALER_TESTING_Command cmd = {
       .cls = bus,

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



reply via email to

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