From 0203e5d83d55d7eed0b6cc669af8750116c4448e Mon Sep 17 00:00:00 2001 From: Jonathan Buchanan Date: Tue, 7 Jul 2020 17:05:32 -0400 Subject: tests for merchant account inactivation --- src/testing/testing_api_cmd_get_instance.c | 156 +++++++++++++++++++++++------ 1 file changed, 124 insertions(+), 32 deletions(-) (limited to 'src/testing/testing_api_cmd_get_instance.c') diff --git a/src/testing/testing_api_cmd_get_instance.c b/src/testing/testing_api_cmd_get_instance.c index a3b91135..e7742cbb 100644 --- a/src/testing/testing_api_cmd_get_instance.c +++ b/src/testing/testing_api_cmd_get_instance.c @@ -59,6 +59,31 @@ struct GetInstanceState */ const char *instance_reference; + /** + * Whether we should check the instance's accounts or not. + */ + bool cmp_accounts; + + /** + * The accounts of the merchant we expect to be active. + */ + const char **active_accounts; + + /** + * The length of @e active_accounts. + */ + unsigned int active_accounts_length; + + /** + * The accounts of the merchant we expect to be inactive. + */ + const char **inactive_accounts; + + /** + * The length of @e inactive_accounts. + */ + unsigned int inactive_accounts_length; + /** * Expected HTTP response code. */ @@ -235,48 +260,61 @@ get_instance_cb (void *cls, return; } } + /* We aren't guaranteed an order for the accounts, so we just have to check + that we can match each account returned with exactly one account + expected. */ + if (gis->cmp_accounts) { - const unsigned int *expected_accounts_length; - if (GNUNET_OK != - TALER_TESTING_get_trait_uint32 (instance_cmd, - 1, - &expected_accounts_length)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Could not fetch accounts length\n"); - TALER_TESTING_interpreter_fail (gis->is); - return; - } - if (accounts_length != *expected_accounts_length) + unsigned int expected_accounts_length = + gis->active_accounts_length + gis->inactive_accounts_length; + unsigned int matches[accounts_length]; + + if (accounts_length != expected_accounts_length) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Accounts length does not match\n"); TALER_TESTING_interpreter_fail (gis->is); return; } - } - for (unsigned int i = 0; i < accounts_length; ++i) - { - const char *payto_uri; - if (GNUNET_OK != - TALER_TESTING_get_trait_string (instance_cmd, - 2 + i, - &payto_uri)) + + memset (matches, + 0, + sizeof (unsigned int) * accounts_length); + + // Compare the accounts + for (unsigned int i = 0; i < accounts_length; ++i) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Could not fetch account payto uri\n"); - TALER_TESTING_interpreter_fail (gis->is); - return; + for (unsigned int j = 0; j < gis->active_accounts_length; ++j) + { + if ((0 == strcasecmp (accounts[i].payto_uri, + gis->active_accounts[j])) && + (true == accounts[i].active)) + { + matches[i] += 1; + } + } + for (unsigned int j = 0; j < gis->inactive_accounts_length; ++j) + { + if ((0 == strcasecmp (accounts[i].payto_uri, + gis->inactive_accounts[j])) && + (false == accounts[i].active)) + { + matches[i] += 1; + } + } } - if (0 != strcasecmp (accounts[i].payto_uri, - payto_uri)) + + // Each account should have exactly one match. + for (unsigned int i = 0; i < accounts_length; ++i) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Account payto uri does not match\n"); - TALER_TESTING_interpreter_fail (gis->is); - return; + if (1 != matches[i]) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Instance account does not match\n"); + TALER_TESTING_interpreter_fail (gis->is); + return; + } } - // FIXME: account for deactivated accounts } break; default: @@ -344,7 +382,8 @@ get_instance_cleanup (void *cls, * @param instance_id the ID of the instance to query * @param http_status expected HTTP response code. * @param instance_reference reference to a "POST /instances" or "PATCH /instances/$ID" CMD - * that will provide what we expect the backend to return to us + * that will provide what we expect the backend to return to us. + * * @return the command. */ struct TALER_TESTING_Command @@ -361,6 +400,59 @@ TALER_TESTING_cmd_merchant_get_instance (const char *label, gis->instance_id = instance_id; gis->http_status = http_status; gis->instance_reference = instance_reference; + gis->cmp_accounts = false; + { + struct TALER_TESTING_Command cmd = { + .cls = gis, + .label = label, + .run = &get_instance_run, + .cleanup = &get_instance_cleanup + }; + + return cmd; + } +} + + +/** + * Define a "GET instance" CMD that compares accounts returned. + * + * @param label command label. + * @param merchant_url base URL of the merchant serving the + * GET /instances/$ID request. + * @param instance_id the ID of the instance to query + * @param http_status expected HTTP response code. + * @param instance_reference reference to a "POST /instances" or "PATCH /instances/$ID" CMD + * that will provide what we expect the backend to return to us + * @param active_accounts the accounts the merchant is actively using. + * @param active_accounts_length length of @e active_accounts. + * @param inactive_accounts the accounts the merchant is no longer using. + * @param inactive_accounts_length length of @e inactive_accounts. + * @return the command. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_merchant_get_instance2 (const char *label, + const char *merchant_url, + const char *instance_id, + unsigned int http_status, + const char *instance_reference, + const char *active_accounts[], + unsigned int active_accounts_length, + const char *inactive_accounts[], + unsigned int inactive_accounts_length) +{ + struct GetInstanceState *gis; + + gis = GNUNET_new (struct GetInstanceState); + gis->merchant_url = merchant_url; + gis->instance_id = instance_id; + gis->http_status = http_status; + gis->instance_reference = instance_reference; + gis->cmp_accounts = true; + gis->active_accounts = active_accounts; + gis->active_accounts_length = active_accounts_length; + gis->inactive_accounts = inactive_accounts; + gis->inactive_accounts_length = inactive_accounts_length; { struct TALER_TESTING_Command cmd = { .cls = gis, -- cgit v1.2.3