aboutsummaryrefslogtreecommitdiff
path: root/src/exchange-lib
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-09-14 20:52:39 +0200
committerChristian Grothoff <christian@grothoff.org>2017-09-14 20:52:39 +0200
commitf346e89ceb7eecf6de1abd4b2b794926d671b72c (patch)
treebd34b3ebbdc4005d09a49dec0d0837181fd1fb28 /src/exchange-lib
parentf440904f1bba73ff4e6b7d91b221fa3f6af4ed62 (diff)
(imperfect) test for #4840
Diffstat (limited to 'src/exchange-lib')
-rw-r--r--src/exchange-lib/Makefile.am4
-rw-r--r--src/exchange-lib/exchange_api_handle.c16
-rw-r--r--src/exchange-lib/test_exchange_api_keys_cherry_picking.c58
-rw-r--r--src/exchange-lib/test_exchange_api_keys_cherry_picking.conf128
-rw-r--r--src/exchange-lib/test_exchange_api_keys_cherry_picking_extended.conf5
5 files changed, 191 insertions, 20 deletions
diff --git a/src/exchange-lib/Makefile.am b/src/exchange-lib/Makefile.am
index d6e068b73..ce1653cc9 100644
--- a/src/exchange-lib/Makefile.am
+++ b/src/exchange-lib/Makefile.am
@@ -80,4 +80,6 @@ EXTRA_DIST = \
test_exchange_api_home/.local/share/taler/exchange/offline-keys/master.priv \
test_exchange_api_home/.config/taler/test.json \
test_exchange_api_home/.config/taler/sepa.json \
- test_exchange_api.conf
+ test_exchange_api.conf \
+ test_exchange_api_keys_cherry_picking.conf \
+ test_exchange_api_keys_cherry_picking_extended.conf
diff --git a/src/exchange-lib/exchange_api_handle.c b/src/exchange-lib/exchange_api_handle.c
index 822c9c7b4..cc44a787e 100644
--- a/src/exchange-lib/exchange_api_handle.c
+++ b/src/exchange-lib/exchange_api_handle.c
@@ -812,6 +812,9 @@ keys_completed_cb (void *cls,
kr->url,
response_code);
kd_old = exchange->key_data;
+ memset (&kd,
+ 0,
+ sizeof (struct TALER_EXCHANGE_Keys));
vc = TALER_EXCHANGE_VC_PROTOCOL_ERROR;
switch (response_code)
{
@@ -823,15 +826,12 @@ keys_completed_cb (void *cls,
response_code = 0;
break;
}
- memset (&kd,
- 0,
- sizeof (struct TALER_EXCHANGE_Keys));
-
/* We keep the denomination keys and auditor signatures from the
previous iteration (/keys cherry picking) */
kd.num_denom_keys = kd_old.num_denom_keys;
- kd.denom_keys = GNUNET_new_array (kd.num_denom_keys,
- struct TALER_EXCHANGE_DenomPublicKey);
+ GNUNET_array_grow (kd.denom_keys,
+ kd.denom_keys_size,
+ kd.num_denom_keys);
/* First make a shallow copy, we then need another pass for the RSA key... */
memcpy (kd.denom_keys,
kd_old.denom_keys,
@@ -857,7 +857,7 @@ keys_completed_cb (void *cls,
for (unsigned int j=0;j<aold->num_denom_keys;j++)
{
/* offsets will map 1:1 */
- unsigned int off = kd_old.denom_keys - aold->denom_keys[j];
+ unsigned int off = aold->denom_keys[j] - kd_old.denom_keys;
GNUNET_assert (off < kd_old.num_denom_keys);
anew->denom_keys[j] = &kd.denom_keys[off];
@@ -872,7 +872,6 @@ keys_completed_cb (void *cls,
response_code = 0;
break;
}
- exchange->key_data = kd;
json_decref (exchange->key_data_raw);
exchange->key_data_raw = json_deep_copy (resp_obj);
break;
@@ -882,6 +881,7 @@ keys_completed_cb (void *cls,
(unsigned int) response_code);
break;
}
+ exchange->key_data = kd;
if (MHD_HTTP_OK != response_code)
{
diff --git a/src/exchange-lib/test_exchange_api_keys_cherry_picking.c b/src/exchange-lib/test_exchange_api_keys_cherry_picking.c
index 9f771701e..0fbf1729a 100644
--- a/src/exchange-lib/test_exchange_api_keys_cherry_picking.c
+++ b/src/exchange-lib/test_exchange_api_keys_cherry_picking.c
@@ -117,7 +117,7 @@ struct Command
/**
* Command-line arguments for the process to be run.
*/
- char *const*argv;
+ char *const *argv;
/**
* Process handle.
@@ -359,6 +359,10 @@ interpreter_run (void *cls)
{
/* Did not get the expected number of denomination keys! */
GNUNET_break (0);
+ fprintf (stderr,
+ "Got %u keys in step %s\n",
+ is->keys->num_denom_keys,
+ cmd->label);
fail (is);
return;
}
@@ -419,13 +423,8 @@ do_shutdown (void *cls)
{
struct InterpreterState *is = cls;
struct Command *cmd;
- unsigned int i;
- fprintf (stderr,
- "Executing shutdown at `%s'\n",
- is->commands[is->ip].label);
-
- for (i=0;OC_END != (cmd = &is->commands[i])->oc;i++)
+ for (unsigned int i=0;OC_END != (cmd = &is->commands[i])->oc;i++)
{
switch (cmd->oc)
{
@@ -541,10 +540,47 @@ static void
run (void *cls)
{
struct InterpreterState *is;
+ static char *keyup[] = {
+ "taler-exchange-keyup",
+ "-c", "test_exchange_api_keys_cherry_picking_extended.conf",
+ "-o", "auditor.in",
+ NULL
+ };
+ static char *auditorsign[] = {
+ "taler-auditor-sign",
+ "-c", "test_exchange_api_keys_cherry_picking.conf",
+ "-u", "http://auditor/",
+ "-m", "98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG",
+ "-r", "auditor.in",
+ "-o", "test_exchange_api_home/.local/share/taler/auditors/auditor.out",
+ NULL
+ };
static struct Command commands[] =
{
/* Test signal handling by itself */
{ .oc = OC_SIGNAL_EXCHANGE },
+ /* Check we got /keys properly */
+ { .oc = OC_CHECK_KEYS,
+ .details.check_keys.generation = 1,
+ .details.check_keys.num_denom_keys = 4
+ },
+ /* Generate more keys */
+ { .oc = OC_RUN_PROCESS,
+ .details.run_process.binary = "taler-exchange-keyup",
+ .details.run_process.argv = keyup
+ },
+ /* Auditor-sign them */
+ { .oc = OC_RUN_PROCESS,
+ .details.run_process.binary = "taler-auditor-sign",
+ .details.run_process.argv = auditorsign
+ },
+ /* Load new keys into exchange via signal */
+ { .oc = OC_SIGNAL_EXCHANGE },
+ /* Re-download and check /keys */
+ { .oc = OC_CHECK_KEYS,
+ .details.check_keys.generation = 2,
+ .details.check_keys.num_denom_keys = 8
+ },
{ .oc = OC_END }
};
@@ -640,7 +676,7 @@ main (int argc,
NULL, NULL, NULL,
"taler-exchange-keyup",
"taler-exchange-keyup",
- "-c", "test_exchange_api.conf",
+ "-c", "test_exchange_api_keys_cherry_picking.conf",
"-o", "auditor.in",
NULL);
if (NULL == proc)
@@ -657,7 +693,7 @@ main (int argc,
NULL, NULL, NULL,
"taler-auditor-sign",
"taler-auditor-sign",
- "-c", "test_exchange_api.conf",
+ "-c", "test_exchange_api_keys_cherry_picking.conf",
"-u", "http://auditor/",
"-m", "98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG",
"-r", "auditor.in",
@@ -677,7 +713,7 @@ main (int argc,
NULL, NULL, NULL,
"taler-exchange-dbinit",
"taler-exchange-dbinit",
- "-c", "test_exchange_api.conf",
+ "-c", "test_exchange_api_keys_cherry_picking.conf",
"-r",
NULL);
if (NULL == proc)
@@ -715,7 +751,7 @@ main (int argc,
NULL, NULL, NULL,
"taler-exchange-httpd",
"taler-exchange-httpd",
- "-c", "test_exchange_api.conf",
+ "-c", "test_exchange_api_keys_cherry_picking.conf",
"-i",
NULL);
/* give child time to start and bind against the socket */
diff --git a/src/exchange-lib/test_exchange_api_keys_cherry_picking.conf b/src/exchange-lib/test_exchange_api_keys_cherry_picking.conf
new file mode 100644
index 000000000..c6b8ef9ea
--- /dev/null
+++ b/src/exchange-lib/test_exchange_api_keys_cherry_picking.conf
@@ -0,0 +1,128 @@
+# This file is in the public domain.
+#
+[PATHS]
+# Persistant data storage for the testcase
+TALER_TEST_HOME = test_exchange_api_home/
+
+[taler]
+# Currency supported by the exchange (can only be one)
+CURRENCY = EUR
+
+[exchange]
+
+# HTTP port the exchange listens to
+PORT = 8081
+
+# Master public key used to sign the exchange's various keys
+MASTER_PUBLIC_KEY = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG
+
+# How to access our database
+DB = postgres
+
+# Base URL of the exchange. Note that the test expects exactly this
+# value in the wire transfers.
+BASE_URL = "https://exchange.com/"
+
+[exchangedb-postgres]
+DB_CONN_STR = "postgres:///talercheck"
+
+[auditordb-postgres]
+DB_CONN_STR = "postgres:///talercheck"
+
+[exchange-wire-sepa]
+# Enable 'sepa' to test SEPA-specific routines.
+ENABLE = YES
+
+# This is the response we give out for the /wire request. It provides
+# wallets with the bank information for transfers to the exchange.
+SEPA_RESPONSE_FILE = ${TALER_CONFIG_HOME}/sepa.json
+
+# Fees for the forseeable future...
+# If you see this after 2017, update to match the next 10 years...
+WIRE-FEE-2017 = EUR:0.01
+WIRE-FEE-2018 = EUR:0.01
+WIRE-FEE-2019 = EUR:0.01
+WIRE-FEE-2020 = EUR:0.01
+WIRE-FEE-2021 = EUR:0.01
+WIRE-FEE-2022 = EUR:0.01
+WIRE-FEE-2023 = EUR:0.01
+WIRE-FEE-2024 = EUR:0.01
+WIRE-FEE-2025 = EUR:0.01
+WIRE-FEE-2026 = EUR:0.01
+
+CLOSING-FEE-2017 = EUR:0.01
+CLOSING-FEE-2018 = EUR:0.01
+CLOSING-FEE-2019 = EUR:0.01
+CLOSING-FEE-2020 = EUR:0.01
+CLOSING-FEE-2021 = EUR:0.01
+CLOSING-FEE-2022 = EUR:0.01
+CLOSING-FEE-2023 = EUR:0.01
+CLOSING-FEE-2024 = EUR:0.01
+CLOSING-FEE-2025 = EUR:0.01
+CLOSING-FEE-2026 = EUR:0.01
+
+[exchange_keys]
+# Keep it short so we can prolong later!
+LOOKAHEAD_SIGN = 60 s
+
+[exchange-wire-test]
+# Enable 'test' for testing of the actual coin operations.
+ENABLE = YES
+
+# Fees for the forseeable future...
+# If you see this after 2017, update to match the next 10 years...
+WIRE-FEE-2017 = EUR:0.01
+WIRE-FEE-2018 = EUR:0.01
+WIRE-FEE-2019 = EUR:0.01
+WIRE-FEE-2020 = EUR:0.01
+WIRE-FEE-2021 = EUR:0.01
+WIRE-FEE-2022 = EUR:0.01
+WIRE-FEE-2023 = EUR:0.01
+WIRE-FEE-2024 = EUR:0.01
+WIRE-FEE-2025 = EUR:0.01
+WIRE-FEE-2026 = EUR:0.01
+
+CLOSING-FEE-2017 = EUR:0.01
+CLOSING-FEE-2018 = EUR:0.01
+CLOSING-FEE-2019 = EUR:0.01
+CLOSING-FEE-2020 = EUR:0.01
+CLOSING-FEE-2021 = EUR:0.01
+CLOSING-FEE-2022 = EUR:0.01
+CLOSING-FEE-2023 = EUR:0.01
+CLOSING-FEE-2024 = EUR:0.01
+CLOSING-FEE-2025 = EUR:0.01
+CLOSING-FEE-2026 = EUR:0.01
+
+# This is the response we give out for the /wire request. It provides
+# wallets with the bank information for transfers to the exchange.
+TEST_RESPONSE_FILE = ${TALER_CONFIG_HOME}/test.json
+
+# What is the main website of the bank?
+BANK_URI = "http://localhost:8082/"
+# From which account at the 'bank' should outgoing wire transfers be made?
+BANK_ACCOUNT_NUMBER = 2
+
+
+[coin_eur_ct_1]
+value = EUR:0.01
+duration_overlap = 5 s
+duration_withdraw = 35 s
+duration_spend = 40 s
+duration_legal = 60 s
+fee_withdraw = EUR:0.00
+fee_deposit = EUR:0.00
+fee_refresh = EUR:0.01
+fee_refund = EUR:0.01
+rsa_keysize = 1024
+
+[coin_eur_ct_2]
+value = EUR:0.02
+duration_overlap = 5 s
+duration_withdraw = 35 s
+duration_spend = 40 s
+duration_legal = 60 s
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.01
+fee_refund = EUR:0.01
+rsa_keysize = 1024
diff --git a/src/exchange-lib/test_exchange_api_keys_cherry_picking_extended.conf b/src/exchange-lib/test_exchange_api_keys_cherry_picking_extended.conf
new file mode 100644
index 000000000..3becf3d68
--- /dev/null
+++ b/src/exchange-lib/test_exchange_api_keys_cherry_picking_extended.conf
@@ -0,0 +1,5 @@
+@INLINE@ test_exchange_api_keys_cherry_picking.conf
+
+[exchange_keys]
+# Lengthen over original value (60 s)
+LOOKAHEAD_SIGN = 100 s