implement testing_api_cmd_set_officer

This commit is contained in:
Christian Grothoff 2023-02-03 11:29:05 +01:00
parent ba3b53cd27
commit e0687b90f1
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
4 changed files with 131 additions and 39 deletions

View File

@ -2751,6 +2751,25 @@ TALER_TESTING_cmd_take_aml_decision (
bool block); bool block);
/**
* Fetch AML decision.
*
* @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_http_status expected HTTP response status
* @return the command
*/
struct TALER_TESTING_Command
TALER_TESTING_cmd_check_aml_decision (
const char *label,
const char *ref_officer,
const char *ref_operation,
unsigned int expected_http_status);
/* *** Generic trait logic for implementing traits ********* */ /* *** Generic trait logic for implementing traits ********* */
@ -2907,6 +2926,9 @@ TALER_TESTING_get_trait (const struct TALER_TESTING_Trait *traits,
*/ */
#define TALER_TESTING_SIMPLE_TRAITS(op) \ #define TALER_TESTING_SIMPLE_TRAITS(op) \
op (bank_row, const uint64_t) \ op (bank_row, const uint64_t) \
op (officer_pub, const struct TALER_AmlOfficerPublicKeyP) \
op (officer_priv, const struct TALER_AmlOfficerPrivateKeyP) \
op (officer_name, 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

@ -99,6 +99,7 @@ libtalertesting_la_SOURCES = \
testing_api_cmd_revoke_sign_key.c \ testing_api_cmd_revoke_sign_key.c \
testing_api_cmd_rewind.c \ testing_api_cmd_rewind.c \
testing_api_cmd_serialize_keys.c \ testing_api_cmd_serialize_keys.c \
testing_api_cmd_set_officer.c \
testing_api_cmd_signal.c \ testing_api_cmd_signal.c \
testing_api_cmd_sleep.c \ testing_api_cmd_sleep.c \
testing_api_cmd_stat.c \ testing_api_cmd_stat.c \

View File

@ -18,7 +18,7 @@
*/ */
/** /**
* @file testing/testing_api_cmd_set_officer.c * @file testing/testing_api_cmd_set_officer.c
* @brief command for testing /management/XXX * @brief command for testing /management/aml-officers
* @author Christian Grothoff * @author Christian Grothoff
*/ */
#include "platform.h" #include "platform.h"
@ -36,9 +36,9 @@ struct SetOfficerState
{ {
/** /**
* Auditor enable handle while operation is running. * Update AML officer handle while operation is running.
*/ */
struct TALER_EXCHANGE_ManagementAuditorEnableHandle *dh; struct TALER_EXCHANGE_ManagementUpdateAmlOfficer *dh;
/** /**
* Our interpreter. * Our interpreter.
@ -56,7 +56,15 @@ struct SetOfficerState
*/ */
const char *name; const char *name;
// FIXME: add trait with officer-priv here! /**
* Private key of the AML officer.
*/
struct TALER_AmlOfficerPrivateKeyP officer_priv;
/**
* Public key of the AML officer.
*/
struct TALER_AmlOfficerPublicKeyP officer_pub;
/** /**
* Is the officer supposed to be enabled? * Is the officer supposed to be enabled?
@ -85,7 +93,7 @@ set_officer_cb (void *cls,
struct SetOfficerState *ds = cls; struct SetOfficerState *ds = cls;
ds->dh = NULL; ds->dh = NULL;
if (MHD_HTTP_NO_CONTENT != hr->response_code) if (MHD_HTTP_NO_CONTENT != 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",
@ -122,18 +130,50 @@ set_officer_run (void *cls,
(void) cmd; (void) cmd;
now = GNUNET_TIME_timestamp_get (); now = GNUNET_TIME_timestamp_get ();
ds->is = is; ds->is = is;
TALER_exchange_offline_set_officer_sign (&is->auditor_pub, if (NULL == ds->ref_cmd)
is->auditor_url, {
GNUNET_CRYPTO_eddsa_key_create (&ds->officer_priv.eddsa_priv);
GNUNET_CRYPTO_eddsa_key_get_public (&ds->officer_priv.eddsa_priv,
&ds->officer_pub.eddsa_pub);
}
else
{
const struct TALER_TESTING_Command *ref;
const struct TALER_AmlOfficerPrivateKeyP *officer_priv;
const struct TALER_AmlOfficerPublicKeyP *officer_pub;
ref = TALER_TESTING_interpreter_lookup_command (is,
ds->ref_cmd);
if (NULL == ref)
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (is);
return;
}
GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_officer_pub (ref,
&officer_pub));
GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_officer_priv (ref,
&officer_priv));
ds->officer_pub = *officer_pub;
ds->officer_priv = *officer_priv;
}
TALER_exchange_offline_aml_officer_status_sign (&ds->officer_pub,
ds->name,
now, now,
ds->is_active,
ds->read_only,
&is->master_priv, &is->master_priv,
&master_sig); &master_sig);
ds->dh = TALER_EXCHANGE_management_enable_auditor ( ds->dh = TALER_EXCHANGE_management_update_aml_officer (
is->ctx, is->ctx,
is->exchange_url, is->exchange_url,
&is->auditor_pub, &ds->officer_pub,
is->auditor_url, ds->name,
"test-case auditor", /* human-readable auditor name */
now, now,
ds->is_active,
ds->read_only,
&master_sig, &master_sig,
&set_officer_cb, &set_officer_cb,
ds); ds);
@ -165,13 +205,44 @@ set_officer_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_management_update_aml_officer_cancel (ds->dh);
ds->dh = NULL; ds->dh = NULL;
} }
GNUNET_free (ds); GNUNET_free (ds);
} }
/**
* Offer internal data to a "set officer" 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
set_officer_traits (void *cls,
const void **ret,
const char *trait,
unsigned int index)
{
struct SetOfficerState *ws = cls;
struct TALER_TESTING_Trait traits[] = {
TALER_TESTING_make_trait_officer_pub (&ws->officer_pub),
TALER_TESTING_make_trait_officer_priv (&ws->officer_priv),
TALER_TESTING_make_trait_officer_name (&ws->name),
TALER_TESTING_trait_end ()
};
return TALER_TESTING_get_trait (traits,
ret,
trait,
index);
}
struct TALER_TESTING_Command struct TALER_TESTING_Command
TALER_TESTING_cmd_set_officer ( TALER_TESTING_cmd_set_officer (
const char *label, const char *label,
@ -192,8 +263,8 @@ TALER_TESTING_cmd_set_officer (
.cls = ds, .cls = ds,
.label = label, .label = label,
.run = &set_officer_run, .run = &set_officer_run,
.cleanup = &set_officer_cleanup .cleanup = &set_officer_cleanup,
// FIXME: expose trait with officer-priv here! .traits = &set_officer_traits
}; };
return cmd; return cmd;

View File

@ -56,8 +56,6 @@ struct AmlDecisionState
*/ */
const char *name; const char *name;
// FIXME: add trait with officer-priv here!
/** /**
* Is the officer supposed to be enabled? * Is the officer supposed to be enabled?
*/ */