diff options
author | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-07-07 17:05:32 -0400 |
---|---|---|
committer | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-07-07 17:05:32 -0400 |
commit | 0203e5d83d55d7eed0b6cc669af8750116c4448e (patch) | |
tree | 31c101606463a7438c11da06bfaaae16defbfa63 /src/testing | |
parent | 5eb0a2e98faecfec89add4845f817548b3fee86b (diff) | |
download | merchant-0203e5d83d55d7eed0b6cc669af8750116c4448e.tar.gz merchant-0203e5d83d55d7eed0b6cc669af8750116c4448e.tar.bz2 merchant-0203e5d83d55d7eed0b6cc669af8750116c4448e.zip |
tests for merchant account inactivation
Diffstat (limited to 'src/testing')
-rw-r--r-- | src/testing/test_merchant_api.c | 48 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_get_instance.c | 156 |
2 files changed, 165 insertions, 39 deletions
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c index eeaec917..e79c9ab8 100644 --- a/src/testing/test_merchant_api.c +++ b/src/testing/test_merchant_api.c @@ -961,7 +961,9 @@ run (void *cls, }; const char *payto_uris[] = { - PAYTO_I1 + PAYTO_I1, + "payto://sepa/CH9300762011623852957" /* Just for testing account + inactivation. */ }; struct TALER_TESTING_Command commands[] = { TALER_TESTING_cmd_config ("config", @@ -990,7 +992,7 @@ run (void *cls, TALER_TESTING_cmd_merchant_patch_instance ("instance-patch-i1", merchant_url, "i1", - 1, + 2, payto_uris, "bob-the-merchant", json_pack ("{s:s}", @@ -1005,11 +1007,43 @@ run (void *cls, GNUNET_TIME_UNIT_MINUTES, GNUNET_TIME_UNIT_MINUTES, MHD_HTTP_NO_CONTENT), - TALER_TESTING_cmd_merchant_get_instance ("instances-get-i1-2", - merchant_url, - "i1", - MHD_HTTP_OK, - "instance-patch-i1"), + TALER_TESTING_cmd_merchant_get_instance2 ("instances-get-i1-2", + merchant_url, + "i1", + MHD_HTTP_OK, + "instance-patch-i1", + payto_uris, + 2, + NULL, + 0), + TALER_TESTING_cmd_merchant_patch_instance ( + "instance-patch-i1-inactivate-account", + merchant_url, + "i1", + 1, + payto_uris, + "bob-the-merchant", + json_pack ("{s:s}", + "street", + "bobstreet"), + json_pack ("{s:s}", + "street", + "bobjuryst"), + "EUR:0.1", + 4, + "EUR:0.5", + GNUNET_TIME_UNIT_MINUTES, + GNUNET_TIME_UNIT_MINUTES, + MHD_HTTP_NO_CONTENT), + TALER_TESTING_cmd_merchant_get_instance2 ("instances-get-i1-3", + merchant_url, + "i1", + MHD_HTTP_OK, + "instance-patch-i1-inactivate-account", + payto_uris, + 1, + &payto_uris[1], + 1), TALER_TESTING_cmd_merchant_get_instance ("instances-get-i2-nx", merchant_url, "i2", 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 @@ -60,6 +60,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. */ unsigned int http_status; @@ -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, |