aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2024-07-23 16:31:35 +0200
committerChristian Grothoff <christian@grothoff.org>2024-07-29 12:18:47 +0200
commite0f37c65d680c63a4fdfad8aca55f44f502417b0 (patch)
tree748b6ce19bfb5d4b65c93d86a0c99a4dbc7ea4c1
parentb70b9616f46dc75d887ef77fd9490e5febfe8606 (diff)
add new CMDs for KYC info+start
-rw-r--r--src/include/taler_testing_lib.h54
-rw-r--r--src/testing/Makefile.am2
-rw-r--r--src/testing/testing_api_cmd_get_kyc_info.c244
-rw-r--r--src/testing/testing_api_cmd_post_kyc_start.c239
4 files changed, 530 insertions, 9 deletions
diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h
index 212bb8ab4..7441311a8 100644
--- a/src/include/taler_testing_lib.h
+++ b/src/include/taler_testing_lib.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2018-2023 Taler Systems SA
+ (C) 2018-2024 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
@@ -2193,10 +2193,11 @@ TALER_TESTING_cmd_revoke_sign_key (
* @return the command
*/
struct TALER_TESTING_Command
-TALER_TESTING_cmd_wallet_kyc_get (const char *label,
- const char *reserve_reference,
- const char *threshold_balance,
- unsigned int expected_response_code);
+TALER_TESTING_cmd_wallet_kyc_get (
+ const char *label,
+ const char *reserve_reference,
+ const char *threshold_balance,
+ unsigned int expected_response_code);
/**
@@ -2209,10 +2210,44 @@ TALER_TESTING_cmd_wallet_kyc_get (const char *label,
* @return the command
*/
struct TALER_TESTING_Command
-TALER_TESTING_cmd_check_kyc_get (const char *label,
- const char *payment_target_reference,
- const char *account_reference,
- unsigned int expected_response_code);
+TALER_TESTING_cmd_check_kyc_get (
+ const char *label,
+ const char *payment_target_reference,
+ const char *account_reference,
+ unsigned int expected_response_code);
+
+
+/**
+ * Create a request for detailed account KYC information.
+ *
+ * @param label command label.
+ * @param payment_target_reference command with a payment target to query
+ * @param kyc_check_reference command with account access token trait to use
+ * @param expected_response_code expected HTTP status
+ * @return the command
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_get_kyc_info (
+ const char *label,
+ const char *kyc_check_reference,
+ unsigned int expected_response_code);
+
+
+/**
+ * Create a request for detailed account KYC information.
+ *
+ * @param label command label.
+ * @param kyc_info_reference command with requirement information to query
+ * @param requirement_index index of the KYC requirement to trigger the KYC start for
+ * @param expected_response_code expected HTTP status
+ * @return the command
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_post_kyc_start (
+ const char *label,
+ const char *kyc_info_reference,
+ unsigned int requirement_index,
+ unsigned int expected_response_code);
/**
@@ -2740,6 +2775,7 @@ TALER_TESTING_get_trait (const struct TALER_TESTING_Trait *traits,
op (denom_sig, const struct TALER_DenominationSignature) \
op (amounts, const struct TALER_Amount) \
op (deposit_amount, const struct TALER_Amount) \
+ op (kyc_id, const char) \
op (deposit_fee_amount, const struct TALER_Amount) \
op (age_commitment, const struct TALER_AgeCommitment) \
op (age_commitment_proof, const struct TALER_AgeCommitmentProof) \
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 266c2b242..262a6440f 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -74,6 +74,7 @@ libtalertesting_la_SOURCES = \
testing_api_cmd_exec_wirewatch.c \
testing_api_cmd_get_auditor.c \
testing_api_cmd_get_exchange.c \
+ testing_api_cmd_get_kyc_info.c \
testing_api_cmd_insert_deposit.c \
testing_api_cmd_kyc_check_get.c \
testing_api_cmd_kyc_proof.c \
@@ -83,6 +84,7 @@ libtalertesting_la_SOURCES = \
testing_api_cmd_offline_sign_wire_fees.c \
testing_api_cmd_offline_sign_keys.c \
testing_api_cmd_offline_sign_extensions.c \
+ testing_api_cmd_post_kyc_start.c \
testing_api_cmd_purse_create_deposit.c \
testing_api_cmd_purse_delete.c \
testing_api_cmd_purse_deposit.c \
diff --git a/src/testing/testing_api_cmd_get_kyc_info.c b/src/testing/testing_api_cmd_get_kyc_info.c
new file mode 100644
index 000000000..56ad432da
--- /dev/null
+++ b/src/testing/testing_api_cmd_get_kyc_info.c
@@ -0,0 +1,244 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 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
+ <http://www.gnu.org/licenses/>
+*/
+
+/**
+ * @file testing/testing_api_cmd_get_kyc_info.c
+ * @brief Implement the testing CMDs for the GET /kyc_info operation.
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_testing_lib.h"
+
+/**
+ * State for a GET kyc-info CMD.
+ */
+struct GetKycInfoState
+{
+
+ /**
+ * Command to get the account access token from.
+ */
+ const char *kyc_check_reference;
+
+ /**
+ * Expected HTTP response code.
+ */
+ unsigned int expected_response_code;
+
+ /**
+ * Handle to the GET /kyc-info pending operation.
+ */
+ struct TALER_EXCHANGE_KycInfoHandle *kwh;
+
+ /**
+ * Interpreter state.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Array of IDs for possible KYC processes we could
+ * start according to the response.
+ */
+ char **ids;
+
+ /**
+ * Length of the @e ids array.
+ */
+ unsigned int num_ids;
+};
+
+
+/**
+ * Handle response to the command.
+ *
+ * @param cls closure.
+ * @param kpci GET KYC status response details
+ */
+static void
+kyc_info_cb (
+ void *cls,
+ const struct TALER_EXCHANGE_KycProcessClientInformation *kpci)
+{
+ struct GetKycInfoState *kcg = cls;
+ struct TALER_TESTING_Interpreter *is = kcg->is;
+
+ kcg->kwh = NULL;
+ if (kcg->expected_response_code != kpci->hr.http_status)
+ {
+ TALER_TESTING_unexpected_status (
+ is,
+ kpci->hr.http_status,
+ kcg->expected_response_code);
+ return;
+ }
+ switch (kpci->hr.http_status)
+ {
+ case MHD_HTTP_OK:
+ kcg->num_ids = kpci->details.ok.requirements_length;
+ kcg->ids = GNUNET_new_array (kcg->num_ids,
+ char *);
+ for (unsigned int i = 0; i<kcg->num_ids; i++)
+ kcg->ids[i] = GNUNET_strdup (
+ kpci->details.ok.requirements[i].id);
+ break;
+ case MHD_HTTP_NO_CONTENT:
+ break;
+ default:
+ GNUNET_break (0);
+ break;
+ }
+ TALER_TESTING_interpreter_next (kcg->is);
+}
+
+
+/**
+ * Run the command.
+ *
+ * @param cls closure.
+ * @param cmd the command to execute.
+ * @param is the interpreter state.
+ */
+static void
+get_kyc_info_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct GetKycInfoState *kcg = cls;
+ const struct TALER_TESTING_Command *res_cmd;
+ const struct TALER_AccountAccessTokenP *token;
+
+ (void) cmd;
+ kcg->is = is;
+ res_cmd = TALER_TESTING_interpreter_lookup_command (
+ kcg->is,
+ kcg->kyc_check_reference);
+ if (NULL == res_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (kcg->is);
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_account_access_token (
+ res_cmd,
+ &token))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (kcg->is);
+ return;
+ }
+ kcg->kwh = TALER_EXCHANGE_kyc_info (
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ token,
+ NULL /* etag */,
+ GNUNET_TIME_UNIT_ZERO,
+ &kyc_info_cb,
+ kcg);
+ GNUNET_assert (NULL != kcg->kwh);
+}
+
+
+/**
+ * Cleanup the state from a "track transaction" CMD, and possibly
+ * cancel a operation thereof.
+ *
+ * @param cls closure.
+ * @param cmd the command which is being cleaned up.
+ */
+static void
+get_kyc_info_cleanup (
+ void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct GetKycInfoState *kcg = cls;
+
+ if (NULL != kcg->kwh)
+ {
+ TALER_TESTING_command_incomplete (kcg->is,
+ cmd->label);
+ TALER_EXCHANGE_kyc_info_cancel (kcg->kwh);
+ kcg->kwh = NULL;
+ }
+ for (unsigned int i = 0; i<kcg->num_ids; i++)
+ GNUNET_free (kcg->ids[i]);
+ GNUNET_free (kcg->ids);
+ GNUNET_free (kcg);
+}
+
+
+/**
+ * Offer internal data from a "check KYC" CMD.
+ *
+ * @param cls closure.
+ * @param[out] ret result (could be anything).
+ * @param trait name of the trait.
+ * @param index index number of the object to offer.
+ * @return #GNUNET_OK on success.
+ */
+static enum GNUNET_GenericReturnValue
+get_kyc_info_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct GetKycInfoState *kcg = cls;
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_kyc_id (index,
+ kcg->ids[index]),
+ TALER_TESTING_trait_end ()
+ };
+
+ if (index >= kcg->num_ids)
+ return GNUNET_NO;
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_get_kyc_info (
+ const char *label,
+ const char *kyc_check_reference,
+ unsigned int expected_response_code)
+{
+ struct GetKycInfoState *kcg;
+
+ kcg = GNUNET_new (struct GetKycInfoState);
+ kcg->kyc_check_reference = kyc_check_reference;
+ kcg->expected_response_code = expected_response_code;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = kcg,
+ .label = label,
+ .run = &get_kyc_info_run,
+ .cleanup = &get_kyc_info_cleanup,
+ .traits = &get_kyc_info_traits
+ };
+
+ return cmd;
+ }
+}
+
+
+/* end of testing_api_cmd_get_kyc_info.c */
diff --git a/src/testing/testing_api_cmd_post_kyc_start.c b/src/testing/testing_api_cmd_post_kyc_start.c
new file mode 100644
index 000000000..d8d0002e7
--- /dev/null
+++ b/src/testing/testing_api_cmd_post_kyc_start.c
@@ -0,0 +1,239 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 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
+ <http://www.gnu.org/licenses/>
+*/
+
+/**
+ * @file testing/testing_api_cmd_post_kyc_start.c
+ * @brief Implement the testing CMDs for a POST /kyc-start operation.
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_testing_lib.h"
+
+/**
+ * State for a POST /kyc-start CMD.
+ */
+struct PostKycStartState
+{
+
+ /**
+ * Command that did a GET on /kyc-info
+ */
+ const char *kyc_info_reference;
+
+ /**
+ * Index of the requirement to start.
+ */
+ unsigned int requirement_index;
+
+ /**
+ * Expected HTTP response code.
+ */
+ unsigned int expected_response_code;
+
+ /**
+ * Redirect URL returned by the request on success.
+ */
+ char *redirect_url;
+
+ /**
+ * Handle to the KYC start pending operation.
+ */
+ struct TALER_EXCHANGE_KycStartHandle *kwh;
+
+ /**
+ * Interpreter state.
+ */
+ struct TALER_TESTING_Interpreter *is;
+};
+
+
+/**
+ * Handle response to the command.
+ *
+ * @param cls closure.
+ * @param ks GET KYC status response details
+ */
+static void
+post_kyc_start_cb (
+ void *cls,
+ const struct TALER_EXCHANGE_KycStartResponse *ks)
+{
+ struct PostKycStartState *kcg = cls;
+ struct TALER_TESTING_Interpreter *is = kcg->is;
+
+ kcg->kwh = NULL;
+ if (kcg->expected_response_code != ks->hr.http_status)
+ {
+ TALER_TESTING_unexpected_status (is,
+ ks->hr.http_status,
+ kcg->expected_response_code);
+ return;
+ }
+ switch (ks->hr.http_status)
+ {
+ case MHD_HTTP_OK:
+ kcg->redirect_url
+ = GNUNET_strdup (ks->details.ok.redirect_url);
+ break;
+ case MHD_HTTP_NO_CONTENT:
+ break;
+ default:
+ GNUNET_break (0);
+ break;
+ }
+ TALER_TESTING_interpreter_next (kcg->is);
+}
+
+
+/**
+ * Run the command.
+ *
+ * @param cls closure.
+ * @param cmd the command to execute.
+ * @param is the interpreter state.
+ */
+static void
+post_kyc_start_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct PostKycStartState *kcg = cls;
+ const struct TALER_TESTING_Command *res_cmd;
+ const char *id;
+
+ (void) cmd;
+ kcg->is = is;
+ res_cmd = TALER_TESTING_interpreter_lookup_command (
+ kcg->is,
+ kcg->kyc_info_reference);
+ if (NULL == res_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (kcg->is);
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_kyc_id (
+ res_cmd,
+ kcg->requirement_index,
+ &id))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (kcg->is);
+ return;
+ }
+ if (NULL == id)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (kcg->is);
+ return;
+ }
+ kcg->kwh = TALER_EXCHANGE_kyc_start (
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ id,
+ &post_kyc_start_cb,
+ kcg);
+ GNUNET_assert (NULL != kcg->kwh);
+}
+
+
+/**
+ * Cleanup the state from a "track transaction" CMD, and possibly
+ * cancel a operation thereof.
+ *
+ * @param cls closure.
+ * @param cmd the command which is being cleaned up.
+ */
+static void
+post_kyc_start_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct PostKycStartState *kcg = cls;
+
+ if (NULL != kcg->kwh)
+ {
+ TALER_TESTING_command_incomplete (kcg->is,
+ cmd->label);
+ TALER_EXCHANGE_kyc_start_cancel (kcg->kwh);
+ kcg->kwh = NULL;
+ }
+ GNUNET_free (kcg->redirect_url);
+ GNUNET_free (kcg);
+}
+
+
+/**
+ * Offer internal data from a "check KYC" CMD.
+ *
+ * @param cls closure.
+ * @param[out] ret result (could be anything).
+ * @param trait name of the trait.
+ * @param index index number of the object to offer.
+ * @return #GNUNET_OK on success.
+ */
+static enum GNUNET_GenericReturnValue
+post_kyc_start_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct PostKycStartState *kcg = cls;
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_kyc_url (kcg->redirect_url),
+ TALER_TESTING_trait_end ()
+ };
+
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_post_kyc_start (
+ const char *label,
+ const char *kyc_info_reference,
+ unsigned int requirement_index,
+ unsigned int expected_response_code)
+{
+ struct PostKycStartState *kcg;
+
+ kcg = GNUNET_new (struct PostKycStartState);
+ kcg->kyc_info_reference = kyc_info_reference;
+ kcg->requirement_index = requirement_index;
+ kcg->expected_response_code = expected_response_code;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = kcg,
+ .label = label,
+ .run = &post_kyc_start_run,
+ .cleanup = &post_kyc_start_cleanup,
+ .traits = &post_kyc_start_traits
+ };
+
+ return cmd;
+ }
+}
+
+
+/* end of testing_api_cmd_post_kyc_start.c */