implement testing_api_cmd_check_aml_decision

This commit is contained in:
Christian Grothoff 2023-02-03 14:06:17 +01:00
parent f6877449eb
commit c3243aa39f
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
7 changed files with 175 additions and 59 deletions

View File

@ -4373,7 +4373,7 @@ typedef void
/** /**
* @brief Handle for a POST /aml/$OFFICER_PUB/decisions request. * @brief Handle for a POST /aml/$OFFICER_PUB/decisions/$STATUS request.
*/ */
struct TALER_EXCHANGE_LookupAmlDecisions; struct TALER_EXCHANGE_LookupAmlDecisions;
@ -4423,6 +4423,16 @@ struct TALER_EXCHANGE_AmlDecisionDetail
*/ */
struct GNUNET_TIME_Timestamp decision_time; struct GNUNET_TIME_Timestamp decision_time;
/**
* New threshold set by this decision.
*/
struct TALER_Amount new_threshold;
/**
* Who made the decision?
*/
struct TALER_AmlOfficerPublicKeyP decider_pub;
/** /**
* Justification given for the decision. * Justification given for the decision.
*/ */
@ -4481,7 +4491,7 @@ struct TALER_EXCHANGE_AmlDecisionResponse
{ {
/** /**
* Array of AML decision summaries returned by the exchange. * Array of AML decision details returned by the exchange.
*/ */
const struct TALER_EXCHANGE_AmlDecisionDetail *aml_history; const struct TALER_EXCHANGE_AmlDecisionDetail *aml_history;
@ -4520,7 +4530,7 @@ typedef void
/** /**
* @brief Handle for a POST /aml/$OFFICER_PUB/decisions request. * @brief Handle for a POST /aml/$OFFICER_PUB/decision/$H_PAYTO request.
*/ */
struct TALER_EXCHANGE_LookupAmlDecision; struct TALER_EXCHANGE_LookupAmlDecision;

View File

@ -2933,6 +2933,8 @@ TALER_TESTING_get_trait (const struct TALER_TESTING_Trait *traits,
op (officer_pub, const struct TALER_AmlOfficerPublicKeyP) \ op (officer_pub, const struct TALER_AmlOfficerPublicKeyP) \
op (officer_priv, const struct TALER_AmlOfficerPrivateKeyP) \ op (officer_priv, const struct TALER_AmlOfficerPrivateKeyP) \
op (officer_name, const char *) \ op (officer_name, const char *) \
op (aml_decision, enum TALER_AmlDecisionState) \
op (aml_justification, const char *) \
op (purse_priv, const struct TALER_PurseContractPrivateKeyP) \ op (purse_priv, const struct TALER_PurseContractPrivateKeyP) \
op (purse_pub, const struct TALER_PurseContractPublicKeyP) \ op (purse_pub, const struct TALER_PurseContractPublicKeyP) \
op (merge_priv, const struct TALER_PurseMergePrivateKeyP) \ op (merge_priv, const struct TALER_PurseMergePrivateKeyP) \

View File

@ -86,8 +86,12 @@ parse_aml_history (const json_t *aml_history,
&aml->decision_time), &aml->decision_time),
GNUNET_JSON_spec_string ("justification", GNUNET_JSON_spec_string ("justification",
&aml->justification), &aml->justification),
TALER_JSON_spec_amount_any ("new_threshold",
&aml->new_threshold),
GNUNET_JSON_spec_uint32 ("new_state", GNUNET_JSON_spec_uint32 ("new_state",
&state32), &state32),
GNUNET_JSON_spec_fixed_auto ("decider_pub",
&aml->decider_pub),
GNUNET_JSON_spec_end () GNUNET_JSON_spec_end ()
}; };

View File

@ -55,6 +55,7 @@ libtalertesting_la_SOURCES = \
testing_api_cmd_batch_deposit.c \ testing_api_cmd_batch_deposit.c \
testing_api_cmd_batch_withdraw.c \ testing_api_cmd_batch_withdraw.c \
testing_api_cmd_change_auth.c \ testing_api_cmd_change_auth.c \
testing_api_cmd_check_aml_decision.c \
testing_api_cmd_check_keys.c \ testing_api_cmd_check_keys.c \
testing_api_cmd_common.c \ testing_api_cmd_common.c \
testing_api_cmd_contract_get.c \ testing_api_cmd_contract_get.c \

View File

@ -36,9 +36,9 @@ struct AmlCheckState
{ {
/** /**
* Auditor enable handle while operation is running. * Handle while operation is running.
*/ */
struct TALER_EXCHANGE_ManagementAuditorEnableHandle *dh; struct TALER_EXCHANGE_LookupAmlDecision *dh;
/** /**
* Our interpreter. * Our interpreter.
@ -46,57 +46,106 @@ struct AmlCheckState
struct TALER_TESTING_Interpreter *is; struct TALER_TESTING_Interpreter *is;
/** /**
* Reference to command to previous set officer * Reference to command to previous set officer.
* to update, or NULL.
*/ */
const char *ref_cmd; const char *ref_officer;
/** /**
* Name to use for the officer. * Reference to command to the previous set AML status operation.
*/ */
const char *name; const char *ref_operation;
/** /**
* Is the officer supposed to be enabled? * Expected HTTP status.
*/ */
bool is_active; unsigned int expected_http_status;
/**
* Is access supposed to be read-only?
*/
bool read_only;
}; };
/** /**
* Callback to analyze the /management/XXX response, just used to check * Callback to analyze the /aml/$OFFICER_PUB/$decision/$H_PAYTO response, just used to check
* if the response code is acceptable. * if the response code is acceptable.
* *
* @param cls closure. * @param cls closure.
* @param hr HTTP response details * @param adr response details
*/ */
static void static void
check_aml_decision_cb (void *cls, check_aml_decision_cb (void *cls,
const struct TALER_EXCHANGE_HttpResponse *hr) const struct TALER_EXCHANGE_AmlDecisionResponse *adr)
{ {
struct AmlCheckState *ds = cls; struct AmlCheckState *ds = cls;
ds->dh = NULL; ds->dh = NULL;
if (MHD_HTTP_NO_CONTENT != hr->response_code) if (ds->expected_http_status != adr->hr.http_status)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Unexpected response code %u to command %s in %s:%u\n", "Unexpected response code %u to command %s in %s:%u\n",
hr->http_status, adr->hr.http_status,
ds->is->commands[ds->is->ip].label, ds->is->commands[ds->is->ip].label,
__FILE__, __FILE__,
__LINE__); __LINE__);
json_dumpf (hr->reply, json_dumpf (adr->hr.reply,
stderr, stderr,
0); 0);
TALER_TESTING_interpreter_fail (ds->is); TALER_TESTING_interpreter_fail (ds->is);
return; return;
} }
if (MHD_HTTP_OK == adr->hr.http_status)
{
const struct TALER_TESTING_Command *ref;
const char **justification;
enum TALER_AmlDecisionState *new_state;
const struct TALER_Amount *amount;
const struct TALER_EXCHANGE_AmlDecisionDetail *oldest = NULL;
ref = TALER_TESTING_interpreter_lookup_command (ds->is,
ds->ref_operation);
if (NULL == ref)
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (ds->is);
return;
}
// FIXME: check returned details...
GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_aml_justification (ref,
&justification));
GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_aml_decision (ref,
&new_state));
GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_amount (ref,
&amount));
for (unsigned int i = 1; i<adr->details.success.aml_history_length; i++)
{
const struct TALER_EXCHANGE_AmlDecisionDetail *aml_history
= &adr->details.success.aml_history[i];
if ( (NULL == oldest) ||
(0 !=
TALER_amount_cmp (amount,
&oldest->new_threshold)) ||
(GNUNET_TIME_timestamp_cmp (oldest->decision_time,
>,
aml_history->decision_time)) )
oldest = aml_history;
}
if (NULL == oldest)
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (ds->is);
return;
}
if ( (oldest->new_state != *new_state) ||
(0 != strcmp (oldest->justification,
*justification) ) )
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (ds->is);
return;
}
}
TALER_TESTING_interpreter_next (ds->is); TALER_TESTING_interpreter_next (ds->is);
} }
@ -114,25 +163,40 @@ check_aml_decision_run (void *cls,
struct TALER_TESTING_Interpreter *is) struct TALER_TESTING_Interpreter *is)
{ {
struct AmlCheckState *ds = cls; struct AmlCheckState *ds = cls;
struct GNUNET_TIME_Timestamp now; const struct TALER_PaytoHashP *h_payto;
struct TALER_MasterSignatureP master_sig; const struct TALER_AmlOfficerPrivateKeyP *officer_priv;
const struct TALER_TESTING_Command *ref;
(void) cmd; (void) cmd;
now = GNUNET_TIME_timestamp_get ();
ds->is = is; ds->is = is;
TALER_exchange_offline_check_aml_decision_sign (&is->auditor_pub, ref = TALER_TESTING_interpreter_lookup_command (is,
is->auditor_url, ds->ref_operation);
now, if (NULL == ref)
&is->master_priv, {
&master_sig); GNUNET_break (0);
ds->dh = TALER_EXCHANGE_management_enable_auditor ( TALER_TESTING_interpreter_fail (is);
return;
}
GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_h_payto (ref,
&h_payto));
ref = TALER_TESTING_interpreter_lookup_command (is,
ds->ref_officer);
if (NULL == ref)
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (is);
return;
}
GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_officer_priv (ref,
&officer_priv));
ds->dh = TALER_EXCHANGE_lookup_aml_decision (
is->ctx, is->ctx,
is->exchange_url, is->exchange_url,
&is->auditor_pub, h_payto,
is->auditor_url, officer_priv,
"test-case auditor", /* human-readable auditor name */ true, /* history */
now,
&master_sig,
&check_aml_decision_cb, &check_aml_decision_cb,
ds); ds);
if (NULL == ds->dh) if (NULL == ds->dh)
@ -163,7 +227,7 @@ check_aml_decision_cleanup (void *cls,
"Command %u (%s) did not complete\n", "Command %u (%s) did not complete\n",
ds->is->ip, ds->is->ip,
cmd->label); cmd->label);
TALER_EXCHANGE_management_enable_auditor_cancel (ds->dh); TALER_EXCHANGE_lookup_aml_decision_cancel (ds->dh);
ds->dh = NULL; ds->dh = NULL;
} }
GNUNET_free (ds); GNUNET_free (ds);
@ -180,10 +244,9 @@ TALER_TESTING_cmd_check_aml_decision (
struct AmlCheckState *ds; struct AmlCheckState *ds;
ds = GNUNET_new (struct AmlCheckState); ds = GNUNET_new (struct AmlCheckState);
ds->ref_cmd = ref_cmd; ds->ref_officer = ref_officer;
ds->name = name; ds->ref_operation = ref_operation;
ds->is_active = is_active; ds->expected_http_status = expected_http_status;
ds->read_only = read_only;
{ {
struct TALER_TESTING_Command cmd = { struct TALER_TESTING_Command cmd = {
.cls = ds, .cls = ds,

View File

@ -213,7 +213,7 @@ set_officer_cleanup (void *cls,
/** /**
* Offer internal data to a "set officer" CMD state to other * Offer internal data of a "set officer" CMD state to other
* commands. * commands.
* *
* @param cls closure * @param cls closure

View File

@ -57,6 +57,11 @@ struct AmlDecisionState
*/ */
const char *account_ref_cmd; const char *account_ref_cmd;
/**
* Payto hash of the account we are manipulating the AML settings for.
*/
struct TALER_PaytoHashP h_payto;
/** /**
* New AML state to use. * New AML state to use.
*/ */
@ -70,7 +75,7 @@ struct AmlDecisionState
/** /**
* Threshold transaction amount. * Threshold transaction amount.
*/ */
const char *new_threshold; struct TALER_Amount new_threshold;
/** /**
* Expected response code. * Expected response code.
@ -125,22 +130,11 @@ take_aml_decision_run (void *cls,
{ {
struct AmlDecisionState *ds = cls; struct AmlDecisionState *ds = cls;
struct GNUNET_TIME_Timestamp now; struct GNUNET_TIME_Timestamp now;
struct TALER_Amount threshold;
const struct TALER_PaytoHashP *h_payto; const struct TALER_PaytoHashP *h_payto;
const struct TALER_AmlOfficerPrivateKeyP *officer_priv; const struct TALER_AmlOfficerPrivateKeyP *officer_priv;
const struct TALER_TESTING_Command *ref; const struct TALER_TESTING_Command *ref;
(void) cmd; (void) cmd;
if (GNUNET_OK !=
TALER_string_to_amount (ds->new_threshold,
&threshold))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to parse amount `%s' at %s\n",
ds->new_threshold,
cmd->label);
GNUNET_assert (0);
}
now = GNUNET_TIME_timestamp_get (); now = GNUNET_TIME_timestamp_get ();
ds->is = is; ds->is = is;
ref = TALER_TESTING_interpreter_lookup_command (is, ref = TALER_TESTING_interpreter_lookup_command (is,
@ -165,13 +159,13 @@ take_aml_decision_run (void *cls,
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_officer_priv (ref, TALER_TESTING_get_trait_officer_priv (ref,
&officer_priv)); &officer_priv));
ds->h_payto = *h_payto;
ds->dh = TALER_EXCHANGE_add_aml_decision ( ds->dh = TALER_EXCHANGE_add_aml_decision (
is->ctx, is->ctx,
is->exchange_url, is->exchange_url,
ds->justification, ds->justification,
now, now,
&threshold, &ds->new_threshold,
h_payto, h_payto,
ds->new_state, ds->new_state,
officer_priv, officer_priv,
@ -212,6 +206,38 @@ take_aml_decision_cleanup (void *cls,
} }
/**
* 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
take_aml_decision_traits (void *cls,
const void **ret,
const char *trait,
unsigned int index)
{
struct AmlDecisionState *ws = cls;
struct TALER_TESTING_Trait traits[] = {
TALER_TESTING_make_trait_h_payto (&ws->h_payto),
TALER_TESTING_make_trait_aml_justification (&ws->justification),
TALER_TESTING_make_trait_aml_decision (&ws->new_state),
TALER_TESTING_make_trait_amount (&ws->new_threshold),
TALER_TESTING_trait_end ()
};
return TALER_TESTING_get_trait (traits,
ret,
trait,
index);
}
struct TALER_TESTING_Command struct TALER_TESTING_Command
TALER_TESTING_cmd_take_aml_decision ( TALER_TESTING_cmd_take_aml_decision (
const char *label, const char *label,
@ -227,7 +253,16 @@ TALER_TESTING_cmd_take_aml_decision (
ds = GNUNET_new (struct AmlDecisionState); ds = GNUNET_new (struct AmlDecisionState);
ds->officer_ref_cmd = ref_officer; ds->officer_ref_cmd = ref_officer;
ds->account_ref_cmd = ref_operation; ds->account_ref_cmd = ref_operation;
ds->new_threshold = new_threshold; if (GNUNET_OK !=
TALER_string_to_amount (new_threshold,
&ds->new_threshold))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to parse amount `%s' at %s\n",
new_threshold,
label);
GNUNET_assert (0);
}
ds->new_state = new_state; ds->new_state = new_state;
ds->justification = justification; ds->justification = justification;
ds->expected_response = expected_response; ds->expected_response = expected_response;
@ -236,7 +271,8 @@ TALER_TESTING_cmd_take_aml_decision (
.cls = ds, .cls = ds,
.label = label, .label = label,
.run = &take_aml_decision_run, .run = &take_aml_decision_run,
.cleanup = &take_aml_decision_cleanup .cleanup = &take_aml_decision_cleanup,
.traits = &take_aml_decision_traits
}; };
return cmd; return cmd;