summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-11-29 20:17:22 +0100
committerChristian Grothoff <christian@grothoff.org>2019-11-29 20:17:22 +0100
commit399392b6dccd1fa074406463324ff500be71b26e (patch)
tree7462952b05e4e19fa2a1f5df8c02d3742a159c07
parent955043f77c3848e2fe48496b1f8709b2d81c62fa (diff)
downloadsync-399392b6dccd1fa074406463324ff500be71b26e.tar.gz
sync-399392b6dccd1fa074406463324ff500be71b26e.tar.bz2
sync-399392b6dccd1fa074406463324ff500be71b26e.zip
work on upload command
-rw-r--r--src/include/sync_testing_lib.h55
-rw-r--r--src/lib/test_sync_api_home/.local/share/taler/auditors/auditor.outbin42328 -> 42328 bytes
-rw-r--r--src/lib/testing_api_cmd_backup_upload.c143
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
--- 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
Binary files 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.
@@ -64,10 +66,45 @@ 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,