exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

commit 5aaa9545ad310cb762ffb9c8a8016afc288ed05d
parent 9c672c08f021c4a58b10b42e931742e45f21cbad
Author: Christian Grothoff <grothoff@gnunet.org>
Date:   Wed, 18 Jun 2025 11:30:48 +0200

add new testing CMD to fetch active legitimization measures (for #9027)

Diffstat:
Msrc/include/taler-exchange/aml_attributes_get.h | 31++++++++++++++++++++++---------
Msrc/include/taler-exchange/aml_decisions_get.h | 29+++++++++++++++++++++--------
Msrc/include/taler-exchange/aml_legitimizations_get.h | 23++++++++---------------
Msrc/include/taler-exchange/aml_transfers_kycauth_get.h | 34++++++++++++++++++++++------------
Msrc/include/taler-exchange/common.h | 2+-
Msrc/include/taler_testing_lib.h | 21+++++++++++++++++++++
Msrc/testing/Makefile.am | 1+
Asrc/testing/testing_api_cmd_get_active_legitimization_measures.c | 345+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 441 insertions(+), 45 deletions(-)

diff --git a/src/include/taler-exchange/aml_attributes_get.h b/src/include/taler-exchange/aml_attributes_get.h @@ -125,7 +125,7 @@ TALER_EXCHANGE_aml_attributes_get_create ( * @param l limit on the number of results to return * @return representation of the option as a struct TALER_EXCHANGE_AmlAttributesGetOptionValue */ -#define TALER_EXCHANGE_aml_attributes_get_option_limit_(l) \ +#define TALER_EXCHANGE_aml_attributes_get_option_limit(l) \ (const struct TALER_EXCHANGE_AmlAttributesGetOptionValue) \ { \ .option = TALER_EXCHANGE_AML_ATTRIBUTES_GET_OPTION_LIMIT, \ @@ -139,7 +139,7 @@ TALER_EXCHANGE_aml_attributes_get_create ( * @param o offset to use * @return representation of the option as a struct TALER_EXCHANGE_AmlAttributesGetOptionValue */ -#define TALER_EXCHANGE_aml_attributes_get_option_offset_(o) \ +#define TALER_EXCHANGE_aml_attributes_get_option_offset(o) \ (const struct TALER_EXCHANGE_AmlAttributesGetOptionValue) \ { \ .option = TALER_EXCHANGE_AML_ATTRIBUTES_GET_OPTION_OFFSET, \ @@ -147,12 +147,25 @@ TALER_EXCHANGE_aml_attributes_get_create ( } -enum TALER_ErrorCode +/** + * Set the requested options for the operation. + * + * If any option fail other options may be or may be not applied. + * + * @param aagh the request to set the options for + * @param num_options length of the @a options array + * @param options an array of options + * @return ::TALER_EC_NONE on success, + * error code otherwise + * @return #GNUNET_OK on success, + * #GNUNET_NO on failure, + * #GNUNET_SYSERR on internal error + */ +enum GNUNET_GenericReturnValue TALER_EXCHANGE_aml_attributes_get_set_options_ ( struct TALER_EXCHANGE_AmlAttributesGetHandle *aagh, unsigned int num_options, - struct TALER_EXCHANGE_AmlAttributesGetOptionValue options[ - static num_options]); + const struct TALER_EXCHANGE_AmlAttributesGetOptionValue *options); /** @@ -172,13 +185,13 @@ TALER_EXCHANGE_aml_attributes_get_set_options_ ( * @return ::TALER_EC_NONE on success, * error code otherwise */ -#define TALER_EXCHANGE_aml_attributes_get_set_options(aagh,...) \ +#define TALER_EXCHANGE_aml_attributes_get_set_options(aagh,...) \ TALER_EXCHANGE_aml_attributes_get_set_options_ ( \ aagh, \ + TALER_EXCHANGE_COMMON_OPTIONS_ARRAY_MAX_SIZE, \ ((const struct TALER_EXCHANGE_AmlAttributesGetOptionValue[]) \ - {__VA_ARGS__, TALER_EXCHANGE_aml_attributes_get_option_end_ () } \ - ), \ - TALER_EXCHANGE_COMMON_OPTIONS_ARRAY_MAX_SIZE) + {__VA_ARGS__, TALER_EXCHANGE_aml_attributes_get_option_end_ () } \ + )) /** diff --git a/src/include/taler-exchange/aml_decisions_get.h b/src/include/taler-exchange/aml_decisions_get.h @@ -338,7 +338,7 @@ TALER_EXCHANGE_aml_decisions_get_create ( * @param l limit on the number of results to return * @return representation of the option as a struct TALER_EXCHANGE_AmlDecisionsGetOptionValue */ -#define TALER_EXCHANGE_aml_decisions_get_option_limit_(l) \ +#define TALER_EXCHANGE_aml_decisions_get_option_limit(l) \ (const struct TALER_EXCHANGE_AmlDecisionsGetOptionValue) \ { \ .option = TALER_EXCHANGE_AML_DECISIONS_GET_OPTION_LIMIT, \ @@ -352,7 +352,7 @@ TALER_EXCHANGE_aml_decisions_get_create ( * @param o offset to use * @return representation of the option as a struct TALER_EXCHANGE_AmlDecisionsGetOptionValue */ -#define TALER_EXCHANGE_aml_decisions_get_option_offset_(o) \ +#define TALER_EXCHANGE_aml_decisions_get_option_offset(o) \ (const struct TALER_EXCHANGE_AmlDecisionsGetOptionValue) \ { \ .option = TALER_EXCHANGE_AML_DECISIONS_GET_OPTION_OFFSET, \ @@ -366,7 +366,7 @@ TALER_EXCHANGE_aml_decisions_get_create ( * @param p normalized payto URI hash of the account to filter by * @return representation of the option as a struct TALER_EXCHANGE_AmlDecisionsGetOptionValue */ -#define TALER_EXCHANGE_aml_decisions_get_option_h_payto_(p) \ +#define TALER_EXCHANGE_aml_decisions_get_option_h_payto(p) \ (const struct TALER_EXCHANGE_AmlDecisionsGetOptionValue) \ { \ .option = TALER_EXCHANGE_AML_DECISIONS_GET_OPTION_H_PAYTO, \ @@ -379,7 +379,7 @@ TALER_EXCHANGE_aml_decisions_get_create ( * @param a activity filter to use * @return representation of the option as a struct TALER_EXCHANGE_AmlDecisionsGetOptionValue */ -#define TALER_EXCHANGE_aml_decisions_get_option_active_(a) \ +#define TALER_EXCHANGE_aml_decisions_get_option_active(a) \ (const struct TALER_EXCHANGE_AmlDecisionsGetOptionValue) \ { \ .option = TALER_EXCHANGE_AML_DECISIONS_GET_OPTION_ACTIVE, \ @@ -392,7 +392,7 @@ TALER_EXCHANGE_aml_decisions_get_create ( * @param i investigation filter to use * @return representation of the option as a struct TALER_EXCHANGE_AmlDecisionsGetOptionValue */ -#define TALER_EXCHANGE_aml_decisions_get_option_investigation_(i) \ +#define TALER_EXCHANGE_aml_decisions_get_option_investigation(i) \ (const struct TALER_EXCHANGE_AmlDecisionsGetOptionValue) \ { \ .option = TALER_EXCHANGE_AML_DECISIONS_GET_OPTION_INVESTIGATION, \ @@ -400,7 +400,19 @@ TALER_EXCHANGE_aml_decisions_get_create ( } -enum TALER_ErrorCode +/** + * Set the requested options for the operation. + * + * If any option fail other options may be or may be not applied. + * + * @param adgh the request to set the options for + * @param num_options length of the @a options array + * @param options an array of options + * @return #GNUNET_OK on success, + * #GNUNET_NO on failure, + * #GNUNET_SYSERR on internal error + */ +enum GNUNET_GenericReturnValue TALER_EXCHANGE_aml_decisions_get_set_options_ ( struct TALER_EXCHANGE_AmlDecisionsGetHandle *adgh, unsigned int num_options, @@ -422,8 +434,9 @@ TALER_EXCHANGE_aml_decisions_get_set_options_ ( * @param adgh the request to set the options for * @param ... the list of the options, each option must be created * by helpers TALER_EXCHANGE_aml_decisions_get_option_NAME(VALUE) - * @return ::TALER_EC_NONE on success, - * error code otherwise + * @return #GNUNET_OK on success, + * #GNUNET_NO on failure, + * #GNUNET_SYSERR on internal error */ #define TALER_EXCHANGE_aml_decisions_get_set_options(adgh,...) \ TALER_EXCHANGE_aml_decisions_get_set_options_ ( \ diff --git a/src/include/taler-exchange/aml_legitimizations_get.h b/src/include/taler-exchange/aml_legitimizations_get.h @@ -146,7 +146,7 @@ TALER_EXCHANGE_aml_legitimizations_get_create ( * @param l limit on the number of results to return * @return representation of the option as a struct TALER_EXCHANGE_AmlLegitimizationsGetOptionValue */ -#define TALER_EXCHANGE_aml_legitimizations_get_option_limit_(l) \ +#define TALER_EXCHANGE_aml_legitimizations_get_option_limit(l) \ (const struct TALER_EXCHANGE_AmlLegitimizationsGetOptionValue) \ { \ .option = TALER_EXCHANGE_AML_LEGITIMIZATIONS_GET_OPTION_LIMIT, \ @@ -160,7 +160,7 @@ TALER_EXCHANGE_aml_legitimizations_get_create ( * @param o offset to use * @return representation of the option as a struct TALER_EXCHANGE_AmlLegitimizationsGetOptionValue */ -#define TALER_EXCHANGE_aml_legitimizations_get_option_offset_(o) \ +#define TALER_EXCHANGE_aml_legitimizations_get_option_offset(o) \ (const struct TALER_EXCHANGE_AmlLegitimizationsGetOptionValue) \ { \ .option = TALER_EXCHANGE_AML_LEGITIMIZATIONS_GET_OPTION_OFFSET, \ @@ -174,7 +174,7 @@ TALER_EXCHANGE_aml_legitimizations_get_create ( * @param p normalized payto URI hash of the account to filter by * @return representation of the option as a struct TALER_EXCHANGE_AmlLegitimizationsGetOptionValue */ -#define TALER_EXCHANGE_aml_legitimizations_get_option_h_payto_(p) \ +#define TALER_EXCHANGE_aml_legitimizations_get_option_h_payto(p) \ (const struct TALER_EXCHANGE_AmlLegitimizationsGetOptionValue) \ { \ .option = TALER_EXCHANGE_AML_LEGITIMIZATIONS_GET_OPTION_H_PAYTO, \ @@ -187,7 +187,7 @@ TALER_EXCHANGE_aml_legitimizations_get_create ( * @param a activity filter to use * @return representation of the option as a struct TALER_EXCHANGE_AmlLegitimizationsGetOptionValue */ -#define TALER_EXCHANGE_aml_legitimizations_get_option_active_(a) \ +#define TALER_EXCHANGE_aml_legitimizations_get_option_active(a) \ (const struct TALER_EXCHANGE_AmlLegitimizationsGetOptionValue) \ { \ .option = TALER_EXCHANGE_AML_LEGITIMIZATIONS_GET_OPTION_ACTIVE, \ @@ -200,12 +200,6 @@ TALER_EXCHANGE_aml_legitimizations_get_create ( * * If any option fail other options may be or may be not applied. * - * It should be used with helpers that creates required options, for example: - * - * TALER_EXCHANGE_aml_legitimizations_get_set_options ( - * algh, - * TALER_EXCHANGE_aml_legitimizations_get_option_h_payto_(&h_payto)); - * * @param algh the request to set the options for * @param num_options length of the @a options array * @param options array of options, each option must be created @@ -218,8 +212,7 @@ enum GNUNET_GenericReturnValue TALER_EXCHANGE_aml_legitimizations_get_set_options_ ( struct TALER_EXCHANGE_AmlLegitimizationsGetHandle *algh, unsigned int num_options, - struct TALER_EXCHANGE_AmlLegitimizationsGetOptionValue options[ - static num_options]); + const struct TALER_EXCHANGE_AmlLegitimizationsGetOptionValue *options); /** @@ -240,13 +233,13 @@ TALER_EXCHANGE_aml_legitimizations_get_set_options_ ( * #GNUNET_NO on failure, * #GNUNET_SYSERR on internal error */ -#define TALER_EXCHANGE_aml_legitimizations_get_set_options(algh,...) \ +#define TALER_EXCHANGE_aml_legitimizations_get_set_options(algh,...) \ TALER_EXCHANGE_aml_legitimizations_get_set_options_ ( \ algh, \ + TALER_EXCHANGE_COMMON_OPTIONS_ARRAY_MAX_SIZE, \ ((const struct TALER_EXCHANGE_AmlLegitimizationsGetOptionValue[]) \ {__VA_ARGS__, TALER_EXCHANGE_aml_legitimizations_get_option_end_ () } \ - ), \ - TALER_EXCHANGE_COMMON_OPTIONS_ARRAY_MAX_SIZE) + )) /** diff --git a/src/include/taler-exchange/aml_transfers_kycauth_get.h b/src/include/taler-exchange/aml_transfers_kycauth_get.h @@ -132,7 +132,7 @@ TALER_EXCHANGE_aml_transfers_kycauth_get_create ( * * @return the terminating object of struct TALER_EXCHANGE_AmlTransfersKycauthGetOptionValue */ -#define TALER_EXCHANGE_aml_transfers_kycauth_get_option_end_() \ +#define TALER_EXCHANGE_aml_transfers_kycauth_get_option_end_() \ (const struct TALER_EXCHANGE_AmlTransfersKycauthGetOptionValue) \ { \ .option = TALER_EXCHANGE_AML_TRANSFERS_KYCAUTH_GET_OPTION_END \ @@ -144,7 +144,7 @@ TALER_EXCHANGE_aml_transfers_kycauth_get_create ( * @param t minimum amount threshold * @return representation of the option as a struct TALER_EXCHANGE_AmlTransfersKycauthGetOptionValue */ -#define TALER_EXCHANGE_aml_transfers_kycauth_get_option_threshold_(t) \ +#define TALER_EXCHANGE_aml_transfers_kycauth_get_option_threshold(t) \ (const struct TALER_EXCHANGE_AmlTransfersKycauthGetOptionValue) \ { \ .option = TALER_EXCHANGE_AML_TRANSFERS_KYCAUTH_GET_OPTION_THRESHOLD, \ @@ -157,7 +157,7 @@ TALER_EXCHANGE_aml_transfers_kycauth_get_create ( * @param l limit on the number of results to return * @return representation of the option as a struct TALER_EXCHANGE_AmlTransfersKycauthGetOptionValue */ -#define TALER_EXCHANGE_aml_transfers_kycauth_get_option_limit_(l) \ +#define TALER_EXCHANGE_aml_transfers_kycauth_get_option_limit(l) \ (const struct TALER_EXCHANGE_AmlTransfersKycauthGetOptionValue) \ { \ .option = TALER_EXCHANGE_AML_TRANSFERS_KYCAUTH_GET_OPTION_LIMIT, \ @@ -171,7 +171,7 @@ TALER_EXCHANGE_aml_transfers_kycauth_get_create ( * @param o offset to use * @return representation of the option as a struct TALER_EXCHANGE_AmlTransfersKycauthGetOptionValue */ -#define TALER_EXCHANGE_aml_transfers_kycauth_get_option_offset_(o) \ +#define TALER_EXCHANGE_aml_transfers_kycauth_get_option_offset(o) \ (const struct TALER_EXCHANGE_AmlTransfersKycauthGetOptionValue) \ { \ .option = TALER_EXCHANGE_AML_TRANSFERS_KYCAUTH_GET_OPTION_OFFSET, \ @@ -185,7 +185,7 @@ TALER_EXCHANGE_aml_transfers_kycauth_get_create ( * @param p normalized payto URI hash of the account to filter by * @return representation of the option as a struct TALER_EXCHANGE_AmlTransfersKycauthGetOptionValue */ -#define TALER_EXCHANGE_aml_transfers_kycauth_get_option_h_payto_(p) \ +#define TALER_EXCHANGE_aml_transfers_kycauth_get_option_h_payto(p) \ (const struct TALER_EXCHANGE_AmlTransfersKycauthGetOptionValue) \ { \ .option = TALER_EXCHANGE_AML_TRANSFERS_KYCAUTH_GET_OPTION_H_PAYTO, \ @@ -193,12 +193,23 @@ TALER_EXCHANGE_aml_transfers_kycauth_get_create ( } -enum TALER_ErrorCode +/** + * Set the requested options for the operation. + * + * If any option fail other options may be or may be not applied. + * + * @param atkgh the request to set the options for + * @param num_options length of the @a options array + * @param options an array of options + * @return #GNUNET_OK on success, + * #GNUNET_NO on failure, + * #GNUNET_SYSERR on internal error + */ +enum GNUNET_GenericReturnValue TALER_EXCHANGE_aml_transfers_kycauth_get_set_options_ ( struct TALER_EXCHANGE_AmlTransfersKycauthGetHandle *atkgh, unsigned int num_options, - struct TALER_EXCHANGE_AmlTransfersKycauthGetOptionValue options[ - static num_options]); + const struct TALER_EXCHANGE_AmlTransfersKycauthGetOptionValue *options); /** @@ -218,14 +229,13 @@ TALER_EXCHANGE_aml_transfers_kycauth_get_set_options_ ( * @return ::TALER_EC_NONE on success, * error code otherwise */ -#define TALER_EXCHANGE_aml_transfers_kycauth_get_set_options(atkgh,...) \ +#define TALER_EXCHANGE_aml_transfers_kycauth_get_set_options(atkgh,...) \ TALER_EXCHANGE_aml_transfers_kycauth_get_set_options_ ( \ atkgh, \ + TALER_EXCHANGE_COMMON_OPTIONS_ARRAY_MAX_SIZE, \ ((const struct TALER_EXCHANGE_AmlTransfersKycauthGetOptionValue[]) \ {__VA_ARGS__, TALER_EXCHANGE_aml_transfers_kycauth_get_option_end_ () \ - } \ - ), \ - TALER_EXCHANGE_COMMON_OPTIONS_ARRAY_MAX_SIZE) + }) /** diff --git a/src/include/taler-exchange/common.h b/src/include/taler-exchange/common.h @@ -35,7 +35,7 @@ * Maximum number of options that can be set in one set_options * call. Used as a dummy for "infinite" in the varargs case. */ -#define TALER_EXCHANGE_COMMON_OPTIONS_ARRAY_MAX_SIZE SIZE_MAX +#define TALER_EXCHANGE_COMMON_OPTIONS_ARRAY_MAX_SIZE UINT_MAX /** diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h @@ -2556,6 +2556,27 @@ TALER_TESTING_cmd_take_aml_decision ( /** + * Lookup active legitimization measure for a particular account. + * + * @param label command label + * @param ref_officer command that previously created an + * officer + * @param ref_operation command that previously created an + * h_payto which to make an AML decision about + * @param expected_response expected HTTP return status + * @param expected_measures legitimization measure we expect to find, NULL if none + * @return the command + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_get_active_legitimization_measures ( + const char *label, + const char *ref_officer, + const char *ref_operation, + unsigned int expected_response, + const char *expected_measures); + + +/** * Fetch and check AML decision. * * @param label command label diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am @@ -73,6 +73,7 @@ libtalertesting_la_SOURCES = \ testing_api_cmd_exec_transfer.c \ testing_api_cmd_exec_wget.c \ testing_api_cmd_exec_wirewatch.c \ + testing_api_cmd_get_active_legitimization_measures.c \ testing_api_cmd_get_auditor.c \ testing_api_cmd_get_exchange.c \ testing_api_cmd_get_kyc_info.c \ diff --git a/src/testing/testing_api_cmd_get_active_legitimization_measures.c b/src/testing/testing_api_cmd_get_active_legitimization_measures.c @@ -0,0 +1,345 @@ +/* + This file is part of TALER + Copyright (C) 2025 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_active_legitimization_measures.c + * @brief command for testing /aml/$OFFICER_PUB/legitimizations + * @author Christian Grothoff + */ + +/** + * State for a GET "active_legitimization_measures" CMD. + */ +struct GetLegitimizationMeasuresState; +#define TALER_EXCHANGE__AML_LEGITIMIZATIONS_GET_RESULT_CLOSURE \ + struct GetLegitimizationMeasuresState + +#include "platform.h" +#include "taler_json_lib.h" +#include <gnunet/gnunet_curl_lib.h> +#include "taler_testing_lib.h" +#include "taler_signatures.h" +#include "backoff.h" + + +struct GetLegitimizationMeasuresState +{ + + /** + * Handle while operation is running. + */ + struct TALER_EXCHANGE_AmlLegitimizationsGetHandle *dh; + + /** + * Our interpreter. + */ + struct TALER_TESTING_Interpreter *is; + + /** + * Reference to command to previous set officer command that gives + * us an officer_priv trait. + */ + const char *officer_ref_cmd; + + /** + * Reference to command to previous AML-triggering event that gives + * us a payto-hash trait. + */ + const char *account_ref_cmd; + + /** + * Payto hash of the account we are manipulating the AML settings for. + */ + struct TALER_NormalizedPaytoHashP h_payto; + + /** + * Expected legitimization measures. + */ + json_t *expected_measures; + + /** + * Expected response code. + */ + unsigned int expected_response; +}; + + +/** + * Callback to analyze the /aml-decision/$OFFICER_PUB response, just used to check + * if the response code is acceptable. + * + * @param ds command state + * @param result response details + */ +static void +get_active_legitimization_measures_cb ( + TALER_EXCHANGE__AML_LEGITIMIZATIONS_GET_RESULT_CLOSURE *ds, + const struct TALER_EXCHANGE_AmlLegitimizationsGetResult *result) +{ + const struct TALER_EXCHANGE_HttpResponse *hr = &result->hr; + + ds->dh = NULL; + if (ds->expected_response != hr->http_status) + { + TALER_TESTING_unexpected_status (ds->is, + hr->http_status, + ds->expected_response); + return; + } + if (MHD_HTTP_OK == hr->http_status) + { + if (NULL == ds->expected_measures) + { + if (0 != result->details.ok.measures_length) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (ds->is); + return; + } + } + else + { + if (1 != result->details.ok.measures_length) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (ds->is); + return; + } + for (size_t i = 0; i<result->details.ok.measures_length; i++) + { + const struct TALER_EXCHANGE_AmlLegitimizationsGetMeasureDetails *d + = &result->details.ok.measures[i]; + + json_dumpf (d->measures, + stderr, + 0); + if (1 != json_equal (d->measures, + ds->expected_measures)) + { + GNUNET_break (0); + json_dumpf (d->measures, + stderr, + 0); + TALER_TESTING_interpreter_fail (ds->is); + return; + } + } + } + } + TALER_TESTING_interpreter_next (ds->is); +} + + +/** + * Run the command. + * + * @param cls closure. + * @param cmd the command to execute. + * @param is the interpreter state. + */ +static void +get_active_legitimization_measures_run ( + void *cls, + const struct TALER_TESTING_Command *cmd, + struct TALER_TESTING_Interpreter *is) +{ + struct GetLegitimizationMeasuresState *ds = cls; + const struct TALER_NormalizedPaytoHashP *h_payto; + const struct TALER_AmlOfficerPrivateKeyP *officer_priv; + const struct TALER_TESTING_Command *ref; + const char *exchange_url; + + (void) cmd; + ds->is = is; + { + const struct TALER_TESTING_Command *exchange_cmd; + + exchange_cmd = TALER_TESTING_interpreter_get_command (is, + "exchange"); + if (NULL == exchange_cmd) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } + GNUNET_assert (GNUNET_OK == + TALER_TESTING_get_trait_exchange_url (exchange_cmd, + &exchange_url)); + } + ref = TALER_TESTING_interpreter_lookup_command (is, + ds->account_ref_cmd); + if (NULL == ref) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } + if (GNUNET_OK != + TALER_TESTING_get_trait_h_normalized_payto (ref, + &h_payto)) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } + ref = TALER_TESTING_interpreter_lookup_command (is, + ds->officer_ref_cmd); + if (NULL == ref) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } + if (GNUNET_OK != + TALER_TESTING_get_trait_officer_priv (ref, + &officer_priv)) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } + ds->h_payto = *h_payto; + ds->dh = TALER_EXCHANGE_aml_legitimizations_get_create ( + TALER_TESTING_interpreter_get_context (is), + exchange_url, + officer_priv); + GNUNET_assert (GNUNET_OK == + TALER_EXCHANGE_aml_legitimizations_get_set_options ( + ds->dh, + TALER_EXCHANGE_aml_legitimizations_get_option_h_payto ( + h_payto), + TALER_EXCHANGE_aml_legitimizations_get_option_active ( + TALER_EXCHANGE_YNA_YES))); + GNUNET_assert ( + TALER_EXCHANGE_AML_LEGITIMIZATIONS_GET_START_OK == + TALER_EXCHANGE_aml_legitimizations_get_start ( + ds->dh, + &get_active_legitimization_measures_cb, + ds)); + + if (NULL == ds->dh) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } +} + + +/** + * Free the state of a "get_aml_decision" CMD, and possibly cancel a + * pending operation thereof. + * + * @param cls closure, must be a `struct GetLegitimizationMeasuresState`. + * @param cmd the command which is being cleaned up. + */ +static void +get_active_legitimization_measures_cleanup ( + void *cls, + const struct TALER_TESTING_Command *cmd) +{ + struct GetLegitimizationMeasuresState *ds = cls; + + if (NULL != ds->dh) + { + TALER_TESTING_command_incomplete (ds->is, + cmd->label); + TALER_EXCHANGE_aml_legitimizations_get_cancel (ds->dh); + ds->dh = NULL; + } + json_decref (ds->expected_measures); + GNUNET_free (ds); +} + + +/** + * Offer internal data of a "AML decision" CMD state to other + * commands. + * + * @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_active_legitimization_measures_traits (void *cls, + const void **ret, + const char *trait, + unsigned int index) +{ + struct GetLegitimizationMeasuresState *ws = cls; + struct TALER_TESTING_Trait traits[] = { + TALER_TESTING_make_trait_h_normalized_payto (&ws->h_payto), + TALER_TESTING_trait_end () + }; + + return TALER_TESTING_get_trait (traits, + ret, + trait, + index); +} + + +struct TALER_TESTING_Command +TALER_TESTING_cmd_get_active_legitimization_measures ( + const char *label, + const char *ref_officer, + const char *ref_operation, + unsigned int expected_response, + const char *expected_measures) +{ + struct GetLegitimizationMeasuresState *ds; + json_error_t err; + + ds = GNUNET_new (struct GetLegitimizationMeasuresState); + ds->officer_ref_cmd = ref_officer; + ds->account_ref_cmd = ref_operation; + ds->expected_response = expected_response; + if (NULL != expected_measures) + { + ds->expected_measures = json_loads (expected_measures, + JSON_DECODE_ANY, + &err); + if (NULL == ds->expected_measures) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Invalid JSON in new rules of %s: %s\n", + label, + err.text); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Input was: `%s'\n", + expected_measures); + GNUNET_assert (0); + } + } + { + struct TALER_TESTING_Command cmd = { + .cls = ds, + .label = label, + .run = &get_active_legitimization_measures_run, + .cleanup = &get_active_legitimization_measures_cleanup, + .traits = &get_active_legitimization_measures_traits + }; + + return cmd; + } +} + + +/* end of testing_api_cmd_get_active_legitimization_measures.c */