From e653b0ae8a90856a6792cd754a054314a0d7d355 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 29 Nov 2019 14:23:15 +0100 Subject: add traits, finish download cmd --- src/include/sync_testing_lib.h | 106 ++++++++++++++++++++++ src/lib/Makefile.am | 7 +- src/lib/testing_api_cmd_backup_download.c | 140 ++++++++++++++++++++++++++++-- src/lib/testing_api_trait_account_priv.c | 73 ++++++++++++++++ src/lib/testing_api_trait_account_pub.c | 73 ++++++++++++++++ src/lib/testing_api_trait_hash.c | 73 ++++++++++++++++ 6 files changed, 461 insertions(+), 11 deletions(-) create mode 100644 src/lib/testing_api_trait_account_priv.c create mode 100644 src/lib/testing_api_trait_account_pub.c create mode 100644 src/lib/testing_api_trait_hash.c diff --git a/src/include/sync_testing_lib.h b/src/include/sync_testing_lib.h index 2fd32c1..8bb11af 100644 --- a/src/include/sync_testing_lib.h +++ b/src/include/sync_testing_lib.h @@ -26,8 +26,100 @@ #include "sync_service.h" #include +#include #include +/** + * Index used in #SYNC_TESTING_get_trait_hash() for the current hash. + */ +#define SYNC_TESTING_TRAIT_HASH_CURRENT 0 + +/** + * Index used in #SYNC_TESTING_get_trait_hash() for the previous hash. + */ +#define SYNC_TESTING_TRAIT_HASH_PREVIOUS 1 + + +/** + * Obtain a hash from @a cmd. + * + * @param cmd command to extract the number from. + * @param index the number's index number, #SYNC_TESTING_TRAIT_HASH_CURRENT or + * #SYNC_TESTING_TRAIT_HASH_PREVIOUS + * @param h[out] set to the hash coming from @a cmd. + * @return #GNUNET_OK on success. + */ +int +SYNC_TESTING_get_trait_hash (const struct TALER_TESTING_Command *cmd, + unsigned int index, + const struct GNUNET_HashCode **h); + + +/** + * Offer a hash. + * + * @param index the number's index number. + * @param h the hash to offer. + * @return #GNUNET_OK on success. + */ +struct TALER_TESTING_Trait +TALER_TESTING_make_trait_hash (unsigned int index, + const struct GNUNET_HashCode *h); + + +/** + * Obtain an account public key from @a cmd. + * + * @param cmd command to extract the public key from. + * @param index usually 0 + * @param pub[out] set to the account public key used in @a cmd. + * @return #GNUNET_OK on success. + */ +int +SYNC_TESTING_get_trait_account_pub (const struct TALER_TESTING_Command *cmd, + unsigned int index, + const struct SYNC_AccountPublicKeyP **pub); + + +/** + * Offer an account public key. + * + * @param index usually zero + * @param h the account_pub to offer. + * @return #GNUNET_OK on success. + */ +struct TALER_TESTING_Trait +TALER_TESTING_make_trait_account_pub (unsigned int index, + const struct SYNC_AccountPublicKeyP *h); + + +/** + * Obtain an account private key from @a cmd. + * + * @param cmd command to extract the number from. + * @param index must be 0 + * @param priv[out] set to the account private key used in @a cmd. + * @return #GNUNET_OK on success. + */ +int +SYNC_TESTING_get_trait_account_priv (const struct TALER_TESTING_Command *cmd, + unsigned int index, + const struct + SYNC_AccountPrivateKeyP **priv); + + +/** + * Offer an account private key. + * + * @param index usually zero + * @param priv the account_priv to offer. + * @return #GNUNET_OK on success. + */ +struct TALER_TESTING_Trait +TALER_TESTING_make_trait_account_priv (unsigned int index, + const struct + SYNC_AccountPrivateKeyP *priv); + /** * Start the sync backend process. Assume the port @@ -56,6 +148,19 @@ char * TALER_TESTING_prepare_sync (const char *config_filename); +/** + * Make the "backup download" command for a non-existent upload. + * + * @param label command label + * @param sync_url base URL of the sync serving + * the policy store request. + * @return the command + */ +struct TALER_TESTING_Command +SYNC_TESTING_cmd_backup_nx (const char *label, + const char *sync_url); + + /** * Make the "backup download" command. * @@ -71,4 +176,5 @@ SYNC_TESTING_cmd_backup_download (const char *label, const char *sync_url, unsigned int http_status, const char *upload_ref); + #endif diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index fa160a6..4a4ea4f 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -16,7 +16,7 @@ libsync_la_LDFLAGS = \ libsync_la_SOURCES = \ sync_api_curl_defaults.c sync_api_curl_defaults.h \ sync_api_download.c \ - sync_api_upload.c + sync_api_upload.c libsync_la_LIBADD = \ -lgnunetcurl \ -lgnunetjson \ @@ -32,7 +32,10 @@ libsynctesting_la_LDFLAGS = \ libsynctesting_la_SOURCES = \ testing_api_cmd_backup_download.c \ testing_api_cmd_backup_upload.c \ - testing_api_helpers.c + testing_api_helpers.c \ + testing_api_trait_account_pub.c \ + testing_api_trait_account_priv.c \ + testing_api_trait_hash.c libsynctesting_la_LIBADD = \ libsync.la \ -ltalerexchange \ diff --git a/src/lib/testing_api_cmd_backup_download.c b/src/lib/testing_api_cmd_backup_download.c index 06e74ce..5377900 100644 --- a/src/lib/testing_api_cmd_backup_download.c +++ b/src/lib/testing_api_cmd_backup_download.c @@ -34,19 +34,19 @@ struct BackupDownloadState { /** - * Reference to upload command we expect to download. + * Eddsa public key. */ - const char *upload_reference; + struct SYNC_AccountPublicKeyP sync_pub; /** - * Expected status code. + * Hash of the upload (all zeros if there was no upload). */ - unsigned int http_status; + const struct GNUNET_HashCode *upload_hash; /** - * Eddsa public key. + * Hash of the previous upload (all zeros if there was no previous upload). */ - struct SYNC_AccountPublicKeyP sync_pub; + const struct GNUNET_HashCode *prev_upload_hash; /** * The /backups POST operation handle. @@ -63,6 +63,16 @@ struct BackupDownloadState */ struct TALER_TESTING_Interpreter *is; + /** + * Reference to upload command we expect to download. + */ + const char *upload_reference; + + /** + * Expected status code. + */ + unsigned int http_status; + }; @@ -76,11 +86,42 @@ struct BackupDownloadState static void backup_download_cb (void *cls, unsigned int http_status, - const struct SYNC_DownloadDetails *ud) + const struct SYNC_DownloadDetails *dd) { struct BackupDownloadState *bds = cls; - // FIXME: next! + bds->download = NULL; + if (http_status != bds->http_status) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unexpected response code %u to command %s in %s:%u\n", + http_status, + bds->is->commands[bds->is->ip].label, + __FILE__, + __LINE__); + TALER_TESTING_interpreter_fail (bds->is); + return; + } + if (NULL != bds->upload_reference) + { + if ( (MHD_HTTP_OK == http_status) && + (0 != GNUNET_memcmp (&dd->curr_backup_hash, + bds->upload_hash)) ) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (bds->is); + return; + } + if ( (MHD_HTTP_OK == http_status) && + (0 != GNUNET_memcmp (&dd->prev_backup_hash, + bds->prev_upload_hash)) ) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (bds->is); + return; + } + } + TALER_TESTING_interpreter_next (bds->is); } @@ -99,6 +140,49 @@ backup_download_run (void *cls, struct BackupDownloadState *bds = cls; bds->is = is; + if (NULL != bds->upload_reference) + { + const struct TALER_TESTING_Command *upload_cmd; + const struct SYNC_AccountPublicKeyP *sync_pub; + + upload_cmd = TALER_TESTING_interpreter_lookup_command + (is, + bds->upload_reference); + if (NULL == upload_cmd) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (bds->is); + return; + } + if (GNUNET_OK != + SYNC_TESTING_get_trait_hash (upload_cmd, + SYNC_TESTING_TRAIT_HASH_CURRENT, + &bds->upload_hash)) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (bds->is); + return; + } + if (GNUNET_OK != + SYNC_TESTING_get_trait_hash (upload_cmd, + SYNC_TESTING_TRAIT_HASH_PREVIOUS, + &bds->upload_hash)) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (bds->is); + return; + } + if (GNUNET_OK != + SYNC_TESTING_get_trait_account_pub (upload_cmd, + 0, + &sync_pub)) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (bds->is); + return; + } + bds->sync_pub = *sync_pub; + } bds->download = SYNC_download (is->ctx, bds->sync_url, &bds->sync_pub, @@ -106,7 +190,9 @@ backup_download_run (void *cls, bds); if (NULL == bds->download) { - // FIMXE: fail! + GNUNET_break (0); + TALER_TESTING_interpreter_fail (bds->is); + return; } } @@ -154,6 +240,7 @@ SYNC_TESTING_cmd_backup_download (const char *label, { struct BackupDownloadState *bds; + GNUNET_assert (NULL != upload_ref); bds = GNUNET_new (struct BackupDownloadState); bds->http_status = http_status; bds->sync_url = sync_url; @@ -169,3 +256,38 @@ SYNC_TESTING_cmd_backup_download (const char *label, return cmd; } } + + +/** + * Make the "backup download" command for a non-existent upload. + * + * @param label command label + * @param sync_url base URL of the sync serving + * the policy store request. + * @return the command + */ +struct TALER_TESTING_Command +SYNC_TESTING_cmd_backup_nx (const char *label, + const char *sync_url) +{ + struct BackupDownloadState *bds; + struct GNUNET_CRYPTO_EddsaPrivateKey *priv; + + bds = GNUNET_new (struct BackupDownloadState); + bds->http_status = MHD_HTTP_NOT_FOUND; + bds->sync_url = sync_url; + priv = GNUNET_CRYPTO_eddsa_key_create (); + GNUNET_CRYPTO_eddsa_key_get_public (priv, + &bds->sync_pub.eddsa_pub); + GNUNET_free (priv); + { + struct TALER_TESTING_Command cmd = { + .cls = bds, + .label = label, + .run = &backup_download_run, + .cleanup = &backup_download_cleanup + }; + + return cmd; + } +} diff --git a/src/lib/testing_api_trait_account_priv.c b/src/lib/testing_api_trait_account_priv.c new file mode 100644 index 0000000..213ca34 --- /dev/null +++ b/src/lib/testing_api_trait_account_priv.c @@ -0,0 +1,73 @@ +/* + This file is part of TALER + Copyright (C) 2019 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + TALER is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Privlic License for more details. + + You should have received a copy of the GNU General Privlic + License along with TALER; see the file COPYING. If not, see + +*/ +/** + * @file lib/testing_api_trait_account_priv.c + * @brief traits to offer a account_priv + * @author Christian Grothoff + */ +#include "platform.h" +#include "sync_service.h" +#include "sync_testing_lib.h" + +#define SYNC_TESTING_TRAIT_ACCOUNT_PRIV "sync-account_priv" + + +/** + * Obtain an account private key from @a cmd. + * + * @param cmd command to extract the private key from. + * @param index the private key's index number. + * @param n[out] set to the private key coming from @a cmd. + * @return #GNUNET_OK on success. + */ +int +SYNC_TESTING_get_trait_account_priv + (const struct TALER_TESTING_Command *cmd, + unsigned int index, + const struct SYNC_AccountPrivateKeyP **priv) +{ + return cmd->traits (cmd->cls, + (const void **) priv, + SYNC_TESTING_TRAIT_ACCOUNT_PRIV, + index); +} + + +/** + * Offer an account private key. + * + * @param index usually zero + * @param priv the account_priv to offer. + * @return #GNUNET_OK on success. + */ +struct TALER_TESTING_Trait +TALER_TESTING_make_trait_account_priv + (unsigned int index, + const struct SYNC_AccountPrivateKeyP *priv) +{ + struct TALER_TESTING_Trait ret = { + .index = index, + .trait_name = SYNC_TESTING_TRAIT_ACCOUNT_PRIV, + .ptr = (const void *) priv + }; + return ret; +} + + +/* end of testing_api_trait_account_priv.c */ diff --git a/src/lib/testing_api_trait_account_pub.c b/src/lib/testing_api_trait_account_pub.c new file mode 100644 index 0000000..f5bbdeb --- /dev/null +++ b/src/lib/testing_api_trait_account_pub.c @@ -0,0 +1,73 @@ +/* + This file is part of TALER + Copyright (C) 2019 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + TALER is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public + License along with TALER; see the file COPYING. If not, see + +*/ +/** + * @file lib/testing_api_trait_account_pub.c + * @brief traits to offer a account_pub + * @author Christian Grothoff + */ +#include "platform.h" +#include "sync_service.h" +#include "sync_testing_lib.h" + +#define SYNC_TESTING_TRAIT_ACCOUNT_PUB "sync-account_pub" + + +/** + * Obtain an account public key from @a cmd. + * + * @param cmd command to extract the public key from. + * @param index the public key's index number. + * @param n[out] set to the public key coming from @a cmd. + * @return #GNUNET_OK on success. + */ +int +SYNC_TESTING_get_trait_account_pub + (const struct TALER_TESTING_Command *cmd, + unsigned int index, + const struct SYNC_AccountPublicKeyP **pub) +{ + return cmd->traits (cmd->cls, + (const void **) pub, + SYNC_TESTING_TRAIT_ACCOUNT_PUB, + index); +} + + +/** + * Offer an account public key. + * + * @param index usually zero + * @param h the account_pub to offer. + * @return #GNUNET_OK on success. + */ +struct TALER_TESTING_Trait +TALER_TESTING_make_trait_account_pub + (unsigned int index, + const struct SYNC_AccountPublicKeyP *h) +{ + struct TALER_TESTING_Trait ret = { + .index = index, + .trait_name = SYNC_TESTING_TRAIT_ACCOUNT_PUB, + .ptr = (const void *) h + }; + return ret; +} + + +/* end of testing_api_trait_account_pub.c */ diff --git a/src/lib/testing_api_trait_hash.c b/src/lib/testing_api_trait_hash.c new file mode 100644 index 0000000..810174d --- /dev/null +++ b/src/lib/testing_api_trait_hash.c @@ -0,0 +1,73 @@ +/* + This file is part of TALER + Copyright (C) 2019 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + TALER is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public + License along with TALER; see the file COPYING. If not, see + +*/ +/** + * @file lib/testing_api_trait_hash.c + * @brief traits to offer a hash + * @author Christian Grothoff + */ +#include "platform.h" +#include "sync_service.h" +#include "sync_testing_lib.h" + +#define SYNC_TESTING_TRAIT_HASH "sync-hash" + + +/** + * Obtain a hash from @a cmd. + * + * @param cmd command to extract the number from. + * @param index the number's index number. + * @param n[out] set to the number coming from @a cmd. + * @return #GNUNET_OK on success. + */ +int +SYNC_TESTING_get_trait_hash + (const struct TALER_TESTING_Command *cmd, + unsigned int index, + const struct GNUNET_HashCode **h) +{ + return cmd->traits (cmd->cls, + (const void **) h, + SYNC_TESTING_TRAIT_HASH, + index); +} + + +/** + * Offer a hash. + * + * @param index the number's index number. + * @param h the hash to offer. + * @return #GNUNET_OK on success. + */ +struct TALER_TESTING_Trait +TALER_TESTING_make_trait_hash + (unsigned int index, + const struct GNUNET_HashCode *h) +{ + struct TALER_TESTING_Trait ret = { + .index = index, + .trait_name = SYNC_TESTING_TRAIT_HASH, + .ptr = (const void *) h + }; + return ret; +} + + +/* end of testing_api_trait_hash.c */ -- cgit v1.2.3