summaryrefslogtreecommitdiff
path: root/src/exchange-lib/testing_api_helpers.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-04-02 14:24:45 +0200
committerChristian Grothoff <christian@grothoff.org>2018-04-02 14:29:44 +0200
commitcb55c1a3af9f56a6da38e5589e72df0b70d355b1 (patch)
tree5f9a3af7d9073249f77ce56c690844a6cb27c3e7 /src/exchange-lib/testing_api_helpers.c
parent7a20062bafed42f937c5388aed09042aad7014c0 (diff)
downloadexchange-cb55c1a3af9f56a6da38e5589e72df0b70d355b1.tar.gz
exchange-cb55c1a3af9f56a6da38e5589e72df0b70d355b1.tar.bz2
exchange-cb55c1a3af9f56a6da38e5589e72df0b70d355b1.zip
Changing configuration structure to enable multiple accounts.
This change enables using multiple wire plugins at the same time. Also, we now distinguish between the wire plugin (i.e. EBICS or taler_bank) and the wire method (i.e. SEPA or x-taler-bank) that the wire plugin is implementing. The "taler-bank" wire method was renamed from "test" to "x-taler-bank". This also changes the format of the /wire response of the exchange, as we now need to return multiple accounts. Note that wire fees are specified per wire method, not per wire account. taler-exchange-keyup now automatically signs all of the /wire responses in the location specified by the configuration. Account identification in wire plugins was changed to use payto://-URLs instead of method-specific JSON fields. Signing and validation of /wire responses was moved from each wire plugin to a generic validation method in libtalerutil (crypto) or libtalerjson (for JSON-formatted inputs). Convenience methods were added to generate JSON for wire accounts (salting, signing). Various section and option names were adjusted to streamline the configuration and make it more consistent overall. Documentation was updated as well.
Diffstat (limited to 'src/exchange-lib/testing_api_helpers.c')
-rw-r--r--src/exchange-lib/testing_api_helpers.c74
1 files changed, 53 insertions, 21 deletions
diff --git a/src/exchange-lib/testing_api_helpers.c b/src/exchange-lib/testing_api_helpers.c
index a942b6522..3aff0a3cc 100644
--- a/src/exchange-lib/testing_api_helpers.c
+++ b/src/exchange-lib/testing_api_helpers.c
@@ -416,42 +416,54 @@ TALER_TESTING_url_port_free (const char *url)
return GNUNET_OK;
}
+
/**
- * Allocate and return a piece of wire-details. Mostly, it adds
- * the bank_url to the JSON.
+ * Allocate and return a piece of wire-details. Combines
+ * the @a account_no and the @a bank_url to a
+ * @a payto://-URL and adds some salt to create the JSON.
*
- * @param template the wire-details template.
+ * @param account_no account number
* @param bank_url the bank_url
- *
- * @return the filled out and stringified wire-details. To
- * be manually free'd.
+ * @return JSON describing the account, including the
+ * payto://-URL of the account, must be manually decref'd
*/
-char *
-TALER_TESTING_make_wire_details (const char *template,
+json_t *
+TALER_TESTING_make_wire_details (unsigned long long account_no,
const char *bank_url)
{
- json_t *jtemplate;
-
- GNUNET_assert (NULL != (jtemplate = json_loads
- (template, JSON_REJECT_DUPLICATES, NULL)));
- GNUNET_assert (0 == json_object_set
- (jtemplate, "bank_url", json_string (bank_url)));
- return json_dumps (jtemplate, JSON_COMPACT);
+ char *payto;
+ json_t *ret;
+
+ GNUNET_asprintf (&payto,
+ "payto://x-taler-bank/%s/%llu",
+ bank_url,
+ account_no);
+ ret = json_pack ("{s:s, s:s}",
+ "url", payto,
+ "salt", "test-salt (must be constant for aggregation tests)");
+ GNUNET_free (payto);
+ return ret;
}
+
/**
* Prepare launching a fakebank. Check that the configuration
* file has the right option, and that the port is available.
* If everything is OK, return the configured URL of the fakebank.
*
* @param config_filename configuration file to use
+ * @param config_section which account to use (must match x-taler-bank)
* @return NULL on error, fakebank URL otherwise
*/
char *
-TALER_TESTING_prepare_fakebank (const char *config_filename)
+TALER_TESTING_prepare_fakebank (const char *config_filename,
+ const char *config_section)
{
struct GNUNET_CONFIGURATION_Handle *cfg;
+ char *payto_url;
char *fakebank_url;
+ const char *start;
+ const char *end;
cfg = GNUNET_CONFIGURATION_create ();
if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg,
@@ -459,17 +471,37 @@ TALER_TESTING_prepare_fakebank (const char *config_filename)
return NULL;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
- "exchange-wire-test",
- "BANK_URL",
- &fakebank_url))
+ config_section,
+ "URL",
+ &payto_url))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
- "exchange-wire-test",
- "BANK_URL");
+ config_section,
+ "URL");
GNUNET_CONFIGURATION_destroy (cfg);
return NULL;
}
GNUNET_CONFIGURATION_destroy (cfg);
+ if (0 != strncasecmp (payto_url,
+ "payto://x-taler-bank/",
+ strlen ("payto://x-taler-bank/")))
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING,
+ config_section,
+ "URL",
+ "expected `x-taler-bank' payto://-URL");
+ GNUNET_CONFIGURATION_destroy (cfg);
+ GNUNET_free (payto_url);
+ return NULL;
+ }
+ start = &payto_url [strlen ("payto://x-taler-bank/")];
+ end = strchr (start,
+ (unsigned char) '/');
+ if (NULL == end)
+ end = &start[strlen (start)];
+ fakebank_url = GNUNET_strndup (start,
+ end - start);
+ GNUNET_free (payto_url);
if (GNUNET_OK !=
TALER_TESTING_url_port_free (fakebank_url))
{