From e0687b90f1f208a4dd72c4a0792334ee54debf03 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 3 Feb 2023 11:29:05 +0100 Subject: [PATCH] implement testing_api_cmd_set_officer --- src/include/taler_testing_lib.h | 62 +++++++---- src/testing/Makefile.am | 1 + src/testing/testing_api_cmd_set_officer.c | 105 +++++++++++++++--- .../testing_api_cmd_take_aml_decision.c | 2 - 4 files changed, 131 insertions(+), 39 deletions(-) diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h index a2df5c33f..50563b9b6 100644 --- a/src/include/taler_testing_lib.h +++ b/src/include/taler_testing_lib.h @@ -2751,6 +2751,25 @@ TALER_TESTING_cmd_take_aml_decision ( 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 ********* */ @@ -2907,6 +2926,9 @@ TALER_TESTING_get_trait (const struct TALER_TESTING_Trait *traits, */ #define TALER_TESTING_SIMPLE_TRAITS(op) \ 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_pub, const struct TALER_PurseContractPublicKeyP) \ op (merge_priv, const struct TALER_PurseMergePrivateKeyP) \ @@ -2932,7 +2954,7 @@ TALER_TESTING_get_trait (const struct TALER_TESTING_Trait *traits, op (kyc_url, const char *) \ op (web_url, const char *) \ op (row, const uint64_t) \ - op (legi_requirement_row, const uint64_t) \ + op (legi_requirement_row, const uint64_t) \ op (array_length, const unsigned int) \ op (credit_payto_uri, const char *) \ op (debit_payto_uri, const char *) \ @@ -2950,26 +2972,26 @@ TALER_TESTING_get_trait (const struct TALER_TESTING_Trait *traits, /** * Call #op on all indexed traits. */ -#define TALER_TESTING_INDEXED_TRAITS(op) \ - op (denom_pub, const struct TALER_EXCHANGE_DenomPublicKey) \ - op (denom_sig, const struct TALER_DenominationSignature) \ - op (amounts, const struct TALER_Amount) \ - op (deposit_amount, const struct TALER_Amount) \ - op (deposit_fee_amount, const struct TALER_Amount) \ - op (age_commitment, const struct TALER_AgeCommitment) \ - op (age_commitment_proof, const struct TALER_AgeCommitmentProof) \ - op (h_age_commitment, const struct TALER_AgeCommitmentHash) \ +#define TALER_TESTING_INDEXED_TRAITS(op) \ + op (denom_pub, const struct TALER_EXCHANGE_DenomPublicKey) \ + op (denom_sig, const struct TALER_DenominationSignature) \ + op (amounts, const struct TALER_Amount) \ + op (deposit_amount, const struct TALER_Amount) \ + op (deposit_fee_amount, const struct TALER_Amount) \ + op (age_commitment, const struct TALER_AgeCommitment) \ + op (age_commitment_proof, const struct TALER_AgeCommitmentProof) \ + op (h_age_commitment, const struct TALER_AgeCommitmentHash) \ op (reserve_history, const struct TALER_EXCHANGE_ReserveHistoryEntry) \ - op (planchet_secrets, const struct TALER_PlanchetMasterSecretP) \ - op (exchange_wd_value, const struct TALER_ExchangeWithdrawValues) \ - op (coin_priv, const struct TALER_CoinSpendPrivateKeyP) \ - op (coin_pub, const struct TALER_CoinSpendPublicKeyP) \ - op (absolute_time, const struct GNUNET_TIME_Absolute) \ - op (timestamp, const struct GNUNET_TIME_Timestamp) \ - op (wire_deadline, const struct GNUNET_TIME_Timestamp) \ - op (refund_deadline, const struct GNUNET_TIME_Timestamp) \ - op (exchange_pub, const struct TALER_ExchangePublicKeyP) \ - op (exchange_sig, const struct TALER_ExchangeSignatureP) \ + op (planchet_secrets, const struct TALER_PlanchetMasterSecretP) \ + op (exchange_wd_value, const struct TALER_ExchangeWithdrawValues) \ + op (coin_priv, const struct TALER_CoinSpendPrivateKeyP) \ + op (coin_pub, const struct TALER_CoinSpendPublicKeyP) \ + op (absolute_time, const struct GNUNET_TIME_Absolute) \ + op (timestamp, const struct GNUNET_TIME_Timestamp) \ + op (wire_deadline, const struct GNUNET_TIME_Timestamp) \ + op (refund_deadline, const struct GNUNET_TIME_Timestamp) \ + op (exchange_pub, const struct TALER_ExchangePublicKeyP) \ + op (exchange_sig, const struct TALER_ExchangeSignatureP) \ op (blinding_key, const union TALER_DenominationBlindingKeyP) diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index db2a54e73..9b636ad79 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am @@ -99,6 +99,7 @@ libtalertesting_la_SOURCES = \ testing_api_cmd_revoke_sign_key.c \ testing_api_cmd_rewind.c \ testing_api_cmd_serialize_keys.c \ + testing_api_cmd_set_officer.c \ testing_api_cmd_signal.c \ testing_api_cmd_sleep.c \ testing_api_cmd_stat.c \ diff --git a/src/testing/testing_api_cmd_set_officer.c b/src/testing/testing_api_cmd_set_officer.c index 2606a6e47..a0170257a 100644 --- a/src/testing/testing_api_cmd_set_officer.c +++ b/src/testing/testing_api_cmd_set_officer.c @@ -18,7 +18,7 @@ */ /** * @file testing/testing_api_cmd_set_officer.c - * @brief command for testing /management/XXX + * @brief command for testing /management/aml-officers * @author Christian Grothoff */ #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. @@ -56,7 +56,15 @@ struct SetOfficerState */ 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? @@ -85,7 +93,7 @@ set_officer_cb (void *cls, struct SetOfficerState *ds = cls; 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, "Unexpected response code %u to command %s in %s:%u\n", @@ -122,18 +130,50 @@ set_officer_run (void *cls, (void) cmd; now = GNUNET_TIME_timestamp_get (); ds->is = is; - TALER_exchange_offline_set_officer_sign (&is->auditor_pub, - is->auditor_url, - now, - &is->master_priv, - &master_sig); - ds->dh = TALER_EXCHANGE_management_enable_auditor ( + if (NULL == ds->ref_cmd) + { + 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, + ds->is_active, + ds->read_only, + &is->master_priv, + &master_sig); + ds->dh = TALER_EXCHANGE_management_update_aml_officer ( is->ctx, is->exchange_url, - &is->auditor_pub, - is->auditor_url, - "test-case auditor", /* human-readable auditor name */ + &ds->officer_pub, + ds->name, now, + ds->is_active, + ds->read_only, &master_sig, &set_officer_cb, ds); @@ -165,13 +205,44 @@ set_officer_cleanup (void *cls, "Command %u (%s) did not complete\n", ds->is->ip, cmd->label); - TALER_EXCHANGE_management_enable_auditor_cancel (ds->dh); + TALER_EXCHANGE_management_update_aml_officer_cancel (ds->dh); ds->dh = NULL; } 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 TALER_TESTING_cmd_set_officer ( const char *label, @@ -192,8 +263,8 @@ TALER_TESTING_cmd_set_officer ( .cls = ds, .label = label, .run = &set_officer_run, - .cleanup = &set_officer_cleanup - // FIXME: expose trait with officer-priv here! + .cleanup = &set_officer_cleanup, + .traits = &set_officer_traits }; return cmd; diff --git a/src/testing/testing_api_cmd_take_aml_decision.c b/src/testing/testing_api_cmd_take_aml_decision.c index 4abb585e4..f7c251dd1 100644 --- a/src/testing/testing_api_cmd_take_aml_decision.c +++ b/src/testing/testing_api_cmd_take_aml_decision.c @@ -56,8 +56,6 @@ struct AmlDecisionState */ const char *name; - // FIXME: add trait with officer-priv here! - /** * Is the officer supposed to be enabled? */