diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-11-30 00:53:58 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-11-30 00:53:58 +0100 |
commit | 6510f9aa481e037fcc5c9b1e13cc9eb0526918e7 (patch) | |
tree | 6a8c3e325f0ba66e806979b72269f0b0506d817d | |
parent | 35dc96ac784586d0c137a43ff90eea7b7b253d7a (diff) | |
download | sync-6510f9aa481e037fcc5c9b1e13cc9eb0526918e7.tar.gz sync-6510f9aa481e037fcc5c9b1e13cc9eb0526918e7.tar.bz2 sync-6510f9aa481e037fcc5c9b1e13cc9eb0526918e7.zip |
test payment required by client
-rw-r--r-- | src/include/sync_testing_lib.h | 10 | ||||
-rw-r--r-- | src/lib/test_sync_api.c | 28 | ||||
-rw-r--r-- | src/lib/testing_api_cmd_backup_upload.c | 22 | ||||
-rw-r--r-- | src/sync/sync-httpd_backup_post.c | 9 |
4 files changed, 55 insertions, 14 deletions
diff --git a/src/include/sync_testing_lib.h b/src/include/sync_testing_lib.h index 79e7eec..5a0d657 100644 --- a/src/include/sync_testing_lib.h +++ b/src/include/sync_testing_lib.h @@ -216,17 +216,19 @@ enum SYNC_TESTING_UploadOption * 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 uo upload options * @param http_status expected HTTP status. - * @param pub account identifier - * @param payment_id payment identifier - * @param policy_data recovery data to post - * + * @param backup_data data to upload + * @param backup_data_size number of bytes in @a backup_data * @return the command */ struct TALER_TESTING_Command SYNC_TESTING_cmd_backup_upload (const char *label, const char *sync_url, const char *prev_upload, + const char *last_upload, enum SYNC_TESTING_UploadOption uo, unsigned int http_status, const void *backup_data, diff --git a/src/lib/test_sync_api.c b/src/lib/test_sync_api.c index 3a1d942..e7f223b 100644 --- a/src/lib/test_sync_api.c +++ b/src/lib/test_sync_api.c @@ -192,6 +192,7 @@ run (void *cls, SYNC_TESTING_cmd_backup_upload ("backup-upload-1", sync_url, NULL /* prev upload */, + NULL /* last upload */, SYNC_TESTING_UO_NONE, MHD_HTTP_PAYMENT_REQUIRED, "Test-1", @@ -215,6 +216,7 @@ run (void *cls, SYNC_TESTING_cmd_backup_upload ("backup-upload-2", sync_url, "backup-upload-1", + NULL, SYNC_TESTING_UO_NONE, MHD_HTTP_NO_CONTENT, "Test-1", @@ -223,11 +225,35 @@ run (void *cls, SYNC_TESTING_cmd_backup_upload ("backup-upload-3", sync_url, "backup-upload-2", + NULL, SYNC_TESTING_UO_NONE, MHD_HTTP_NO_CONTENT, "Test-3", strlen ("Test-3")), - /* Test download: no backup exists */ + /* Test download: succeeds! */ + SYNC_TESTING_cmd_backup_download ("download-3", + sync_url, + MHD_HTTP_OK, + "backup-upload-3"), + /* now updated upload should fail (conflict) */ + SYNC_TESTING_cmd_backup_upload ("backup-upload-3b", + sync_url, + "backup-upload-2", + "backup-upload-3", + SYNC_TESTING_UO_NONE, + MHD_HTTP_CONFLICT, + "Test-3b", + strlen ("Test-3b")), + /* now updated upload should fail (payment requested) */ + SYNC_TESTING_cmd_backup_upload ("backup-upload-4", + sync_url, + "backup-upload-3", + "backup-upload-3", + SYNC_TESTING_UO_REQUEST_PAYMENT, + MHD_HTTP_PAYMENT_REQUIRED, + "Test-4", + strlen ("Test-4")), + /* Test download: previous did NOT change the data on the server! */ SYNC_TESTING_cmd_backup_download ("download-3", sync_url, MHD_HTTP_OK, diff --git a/src/lib/testing_api_cmd_backup_upload.c b/src/lib/testing_api_cmd_backup_upload.c index bdbd374..d9f0c38 100644 --- a/src/lib/testing_api_cmd_backup_upload.c +++ b/src/lib/testing_api_cmd_backup_upload.c @@ -67,11 +67,18 @@ struct BackupUploadState const char *sync_url; /** - * Previous upload, or NULL for none. + * Previous upload, or NULL for none. Used to calculate what THIS + * upload is based on. */ const char *prev_upload; /** + * Last upload, or NULL for none, usually same as @e prev_upload. + * Used to check the response on #MHD_HTTP_CONFLICT. + */ + const char *last_upload; + + /** * Payment order ID we got back, if any. Otherwise NULL. */ char *payment_order_id; @@ -198,7 +205,7 @@ backup_upload_cb (void *cls, ref = TALER_TESTING_interpreter_lookup_command (bus->is, - bus->prev_upload); + bus->last_upload); GNUNET_assert (NULL != ref); GNUNET_assert (GNUNET_OK == SYNC_TESTING_get_trait_hash (ref, @@ -433,17 +440,19 @@ backup_upload_traits (void *cls, * 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 uo upload options * @param http_status expected HTTP status. - * @param pub account identifier - * @param payment_id payment identifier - * @param policy_data recovery data to post - * + * @param backup_data data to upload + * @param backup_data_size number of bytes in @a backup_data * @return the command */ struct TALER_TESTING_Command SYNC_TESTING_cmd_backup_upload (const char *label, const char *sync_url, const char *prev_upload, + const char *last_upload, enum SYNC_TESTING_UploadOption uo, unsigned int http_status, const void *backup_data, @@ -454,6 +463,7 @@ SYNC_TESTING_cmd_backup_upload (const char *label, bus = GNUNET_new (struct BackupUploadState); bus->http_status = http_status; bus->prev_upload = prev_upload; + bus->last_upload = last_upload; bus->uopt = uo; bus->sync_url = sync_url; bus->backup = backup_data; diff --git a/src/sync/sync-httpd_backup_post.c b/src/sync/sync-httpd_backup_post.c index f0acc5a..251dc10 100644 --- a/src/sync/sync-httpd_backup_post.c +++ b/src/sync/sync-httpd_backup_post.c @@ -265,12 +265,12 @@ proposal_cb (void *cls, enum SYNC_DB_QueryStatus qs; bc->po = NULL; - GNUNET_CONTAINER_DLL_remove (bc_head, - bc_tail, - bc); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Resuming connection with order `%s'\n", order_id); + GNUNET_CONTAINER_DLL_remove (bc_head, + bc_tail, + bc); MHD_resume_connection (bc->con); SH_trigger_daemon (); if (MHD_HTTP_OK != http_status) @@ -381,6 +381,9 @@ check_payment_cb (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Payment status checked: %s\n", paid ? "paid" : "unpaid"); + GNUNET_CONTAINER_DLL_remove (bc_head, + bc_tail, + bc); MHD_resume_connection (bc->con); SH_trigger_daemon (); GNUNET_break ( (GNUNET_NO == refunded) && |