From 74ba46db39d3a906e819cd0ed48f1d46dffe9e38 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 14 Aug 2022 18:04:09 +0200 Subject: -work on new KYC logic: tests pass again --- src/testing/test_kyc_api.c | 49 ++++++++++++++++++----------- src/testing/test_kyc_api.conf | 6 ++++ src/testing/testing_api_cmd_purse_merge.c | 32 ++++++++++++++++++- src/testing/testing_api_cmd_reserve_purse.c | 33 +++++++++++++++++++ src/testing/testing_api_cmd_withdraw.c | 12 +++---- 5 files changed, 107 insertions(+), 25 deletions(-) (limited to 'src/testing') diff --git a/src/testing/test_kyc_api.c b/src/testing/test_kyc_api.c index edc3ac021..4d2e01b04 100644 --- a/src/testing/test_kyc_api.c +++ b/src/testing/test_kyc_api.c @@ -231,6 +231,8 @@ run (void *cls, "EUR:5.04"), CMD_TRANSFER_TO_EXCHANGE ("p2p_create-reserve-2", "EUR:5.01"), + CMD_TRANSFER_TO_EXCHANGE ("p2p_create-reserve-3", + "EUR:0.03"), TALER_TESTING_cmd_reserve_poll ("p2p_poll-reserve-1", "p2p_create-reserve-1", "EUR:5.04", @@ -293,6 +295,17 @@ run (void *cls, MHD_HTTP_OK, true, /* for merge */ "purse-with-deposit"), + TALER_TESTING_cmd_purse_merge ( + "purse-merge-into-reserve", + MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS, + "push-get-contract", + "p2p_create-reserve-1"), + TALER_TESTING_cmd_proof_kyc_oauth2 ("p2p_proof-kyc", + "purse-merge-into-reserve", + "kyc-provider-test-oauth2", + "pass", + "state", + MHD_HTTP_SEE_OTHER), TALER_TESTING_cmd_purse_merge ( "purse-merge-into-reserve", MHD_HTTP_OK, @@ -318,13 +331,26 @@ run (void *cls, TALER_TESTING_cmd_end () }; struct TALER_TESTING_Command pull[] = { + TALER_TESTING_cmd_purse_create_with_reserve ( + "purse-create-with-reserve", + MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS, + "{\"amount\":\"EUR:1\",\"summary\":\"ice cream\"}", + true /* upload contract */, + GNUNET_TIME_UNIT_MINUTES, /* expiration */ + "p2p_create-reserve-3"), + TALER_TESTING_cmd_proof_kyc_oauth2 ("p2p_proof-kyc-pull", + "purse-create-with-reserve", + "kyc-provider-test-oauth2", + "pass", + "state", + MHD_HTTP_SEE_OTHER), TALER_TESTING_cmd_purse_create_with_reserve ( "purse-create-with-reserve", MHD_HTTP_OK, "{\"amount\":\"EUR:1\",\"summary\":\"ice cream\"}", true /* upload contract */, GNUNET_TIME_UNIT_MINUTES, /* expiration */ - "p2p_create-reserve-1"), + "p2p_create-reserve-3"), TALER_TESTING_cmd_contract_get ( "pull-get-contract", MHD_HTTP_OK, @@ -353,23 +379,14 @@ run (void *cls, "pull-poll-purse-before-deposit"), TALER_TESTING_cmd_status ( "pull-check-post-merge-reserve-balance-get", - "p2p_create-reserve-1", - "EUR:2.02", + "p2p_create-reserve-3", + "EUR:1.02", MHD_HTTP_OK), - /* POST history doesn't yet support P2P transfers */ TALER_TESTING_cmd_reserve_status ( "push-check-post-merge-reserve-balance-post", - "p2p_create-reserve-1", - "EUR:2.02", + "p2p_create-reserve-3", + "EUR:1.02", MHD_HTTP_OK), - /* create 2nd purse for a deposit conflict */ - TALER_TESTING_cmd_purse_create_with_reserve ( - "purse-create-with-reserve-2", - MHD_HTTP_OK, - "{\"amount\":\"EUR:4\",\"summary\":\"beer\"}", - true /* upload contract */, - GNUNET_TIME_UNIT_MINUTES, /* expiration */ - "p2p_create-reserve-1"), TALER_TESTING_cmd_end () }; @@ -401,7 +418,6 @@ run (void *cls, CONFIG_FILE), TALER_TESTING_cmd_check_keys_pull_all_keys ("refetch /keys", 2), -#if 1 TALER_TESTING_cmd_batch ("withdraw", withdraw), TALER_TESTING_cmd_batch ("spend", @@ -412,15 +428,12 @@ run (void *cls, withdraw_kyc), TALER_TESTING_cmd_batch ("wallet-kyc", wallet_kyc), -#endif TALER_TESTING_cmd_batch ("p2p_withdraw", p2p_withdraw), -#if 0 TALER_TESTING_cmd_batch ("push", push), TALER_TESTING_cmd_batch ("pull", pull), -#endif TALER_TESTING_cmd_end () }; diff --git a/src/testing/test_kyc_api.conf b/src/testing/test_kyc_api.conf index 56c8eb858..5d8aae870 100644 --- a/src/testing/test_kyc_api.conf +++ b/src/testing/test_kyc_api.conf @@ -91,6 +91,12 @@ REQUIRED_CHECKS = DUMMY THRESHOLD = EUR:8 TIMEFRAME = 1d +[kyc-legitimization-merge] +OPERATION_TYPE = MERGE +REQUIRED_CHECKS = DUMMY +THRESHOLD = EUR:0 +TIMEFRAME = 1d + [exchangedb-postgres] CONFIG = "postgres:///talercheck" diff --git a/src/testing/testing_api_cmd_purse_merge.c b/src/testing/testing_api_cmd_purse_merge.c index 4d1e8bf4b..11dc2ec81 100644 --- a/src/testing/testing_api_cmd_purse_merge.c +++ b/src/testing/testing_api_cmd_purse_merge.c @@ -71,6 +71,18 @@ struct PurseMergeState */ struct TALER_TESTING_Interpreter *is; + /** + * Hash of the payto://-URI for the reserve we are + * merging into. + */ + struct TALER_PaytoHashP h_payto; + + /** + * Set to the KYC UUID *if* the exchange replied with + * a request for KYC. + */ + uint64_t kyc_uuid; + /** * Reserve history entry that corresponds to this operation. * Will be of type #TALER_EXCHANGE_RTT_MERGE. @@ -129,8 +141,9 @@ merge_cb (void *cls, struct PurseMergeState *ds = cls; ds->dh = NULL; - if (MHD_HTTP_OK == dr->hr.http_status) + switch (dr->hr.http_status) { + case MHD_HTTP_OK: ds->reserve_history.type = TALER_EXCHANGE_RTT_MERGE; ds->reserve_history.amount = ds->value_after_fees; GNUNET_assert (GNUNET_OK == @@ -153,6 +166,12 @@ merge_cb (void *cls, = ds->min_age; ds->reserve_history.details.merge_details.flags = TALER_WAMF_MODE_MERGE_FULLY_PAID_PURSE; + break; + case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS: + /* KYC required */ + ds->kyc_uuid = + dr->details.unavailable_for_legal_reasons.payment_target_uuid; + break; } @@ -281,6 +300,15 @@ merge_run (void *cls, } GNUNET_CRYPTO_eddsa_key_get_public (&ds->reserve_priv.eddsa_priv, &ds->reserve_pub.eddsa_pub); + { + char *payto_uri; + + payto_uri = TALER_reserve_make_payto (is->exchange_url, + &ds->reserve_pub); + TALER_payto_hash (payto_uri, + &ds->h_payto); + GNUNET_free (payto_uri); + } GNUNET_CRYPTO_eddsa_key_get_public (&merge_priv->eddsa_priv, &ds->merge_pub.eddsa_pub); ds->merge_timestamp = GNUNET_TIME_timestamp_get (); @@ -357,6 +385,8 @@ merge_traits (void *cls, TALER_TESTING_make_trait_reserve_pub (&ds->reserve_pub), TALER_TESTING_make_trait_timestamp (0, &ds->merge_timestamp), + TALER_TESTING_make_trait_payment_target_uuid (&ds->kyc_uuid), + TALER_TESTING_make_trait_h_payto (&ds->h_payto), TALER_TESTING_trait_end () }; diff --git a/src/testing/testing_api_cmd_reserve_purse.c b/src/testing/testing_api_cmd_reserve_purse.c index 915118eb7..0afe26342 100644 --- a/src/testing/testing_api_cmd_reserve_purse.c +++ b/src/testing/testing_api_cmd_reserve_purse.c @@ -97,6 +97,18 @@ struct ReservePurseState */ struct GNUNET_TIME_Timestamp purse_expiration; + /** + * Hash of the payto://-URI for the reserve we are + * merging into. + */ + struct TALER_PaytoHashP h_payto; + + /** + * Set to the KYC UUID *if* the exchange replied with + * a request for KYC. + */ + uint64_t kyc_uuid; + /** * Contract terms for the purse. */ @@ -149,6 +161,14 @@ purse_cb (void *cls, TALER_TESTING_interpreter_fail (ds->is); return; } + switch (dr->hr.http_status) + { + case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS: + /* KYC required */ + ds->kyc_uuid = + dr->details.unavailable_for_legal_reasons.payment_target_uuid; + break; + } TALER_TESTING_interpreter_next (ds->is); } @@ -194,6 +214,17 @@ purse_run (void *cls, GNUNET_CRYPTO_ecdhe_key_create (&ds->contract_priv.ecdhe_priv); ds->purse_expiration = GNUNET_TIME_absolute_to_timestamp ( GNUNET_TIME_relative_to_absolute (ds->expiration_rel)); + + { + char *payto_uri; + + payto_uri = TALER_reserve_make_payto (is->exchange_url, + &ds->reserve_pub); + TALER_payto_hash (payto_uri, + &ds->h_payto); + GNUNET_free (payto_uri); + } + GNUNET_assert (0 == json_object_set_new ( ds->contract_terms, @@ -278,6 +309,8 @@ purse_traits (void *cls, TALER_TESTING_make_trait_reserve_priv (&ds->reserve_priv), TALER_TESTING_make_trait_reserve_pub (&ds->reserve_pub), TALER_TESTING_make_trait_reserve_sig (&ds->reserve_sig), + TALER_TESTING_make_trait_payment_target_uuid (&ds->kyc_uuid), + TALER_TESTING_make_trait_h_payto (&ds->h_payto), TALER_TESTING_trait_end () }; diff --git a/src/testing/testing_api_cmd_withdraw.c b/src/testing/testing_api_cmd_withdraw.c index 6b77a35e7..877c9ca67 100644 --- a/src/testing/testing_api_cmd_withdraw.c +++ b/src/testing/testing_api_cmd_withdraw.c @@ -304,10 +304,6 @@ reserve_withdraw_cb (void *cls, GNUNET_YES)); } break; - case MHD_HTTP_ACCEPTED: - /* nothing to check */ - ws->kyc_uuid = wr->details.accepted.payment_target_uuid; - break; case MHD_HTTP_FORBIDDEN: /* nothing to check */ break; @@ -322,6 +318,8 @@ reserve_withdraw_cb (void *cls, break; case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS: /* KYC required */ + ws->kyc_uuid = + wr->details.unavailable_for_legal_reasons.payment_target_uuid; break; default: /* Unsupported status code (by test harness) */ @@ -545,8 +543,10 @@ withdraw_traits (void *cls, (const char **) &ws->reserve_payto_uri), TALER_TESTING_make_trait_exchange_url ( (const char **) &ws->exchange_url), - TALER_TESTING_make_trait_age_commitment_proof (0, ws->age_commitment_proof), - TALER_TESTING_make_trait_h_age_commitment (0, ws->h_age_commitment), + TALER_TESTING_make_trait_age_commitment_proof (0, + ws->age_commitment_proof), + TALER_TESTING_make_trait_h_age_commitment (0, + ws->h_age_commitment), TALER_TESTING_trait_end () }; -- cgit v1.2.3