adding wire plugin tests, resolving #4357
This commit is contained in:
parent
58373f2a92
commit
a7f2496795
1
.gitignore
vendored
1
.gitignore
vendored
@ -44,6 +44,7 @@ src/exchange-tools/taler-exchange-wire
|
|||||||
src/exchangedb/perf-exchangedb
|
src/exchangedb/perf-exchangedb
|
||||||
src/json/test_json
|
src/json/test_json
|
||||||
src/wire/test_sepa_wireformat
|
src/wire/test_sepa_wireformat
|
||||||
|
src/wire/test_wire_plugin
|
||||||
src/pq/test_pq
|
src/pq/test_pq
|
||||||
src/util/test_amount
|
src/util/test_amount
|
||||||
src/util/test_crypto
|
src/util/test_crypto
|
||||||
|
@ -15,7 +15,8 @@ pkgcfg_DATA = \
|
|||||||
|
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
wire-sepa.conf \
|
wire-sepa.conf \
|
||||||
wire-test.conf
|
wire-test.conf \
|
||||||
|
test_wire_plugin.conf
|
||||||
|
|
||||||
plugindir = $(libdir)/taler
|
plugindir = $(libdir)/taler
|
||||||
|
|
||||||
@ -97,6 +98,7 @@ test_sepa_wireformat_LDADD = \
|
|||||||
test_wire_plugin_SOURCES = \
|
test_wire_plugin_SOURCES = \
|
||||||
test_wire_plugin.c
|
test_wire_plugin.c
|
||||||
test_wire_plugin_LDADD = \
|
test_wire_plugin_LDADD = \
|
||||||
|
-lgnunetjson \
|
||||||
-lgnunetutil \
|
-lgnunetutil \
|
||||||
-ljansson \
|
-ljansson \
|
||||||
libtalerwire.la \
|
libtalerwire.la \
|
||||||
|
@ -539,6 +539,9 @@ sepa_get_wire_details (void *cls,
|
|||||||
"SEPA_RESPONSE_FILE",
|
"SEPA_RESPONSE_FILE",
|
||||||
&sepa_wire_file))
|
&sepa_wire_file))
|
||||||
{
|
{
|
||||||
|
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
|
||||||
|
account_name,
|
||||||
|
"SEPA_RESPONSE_FILE");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
ret = json_load_file (sepa_wire_file,
|
ret = json_load_file (sepa_wire_file,
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
#include "taler_util.h"
|
#include "taler_util.h"
|
||||||
#include "taler_wire_lib.h"
|
#include "taler_wire_lib.h"
|
||||||
#include "taler_wire_plugin.h"
|
#include "taler_wire_plugin.h"
|
||||||
|
#include <gnunet/gnunet_json_lib.h>
|
||||||
|
#include <jansson.h>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,32 +50,120 @@ struct TestBlock {
|
|||||||
* to use for the tests.
|
* to use for the tests.
|
||||||
*/
|
*/
|
||||||
static struct TestBlock tests[] = {
|
static struct TestBlock tests[] = {
|
||||||
{ "sepa", "{ \"iban\":3 }" },
|
{ "sepa", "{ \"type\":\"sepa\", \"iban\":\"DE67830654080004822650\", \"name\":\"GNUnet e.V.\", \"bic\":\"GENODEF1SLR\" }" },
|
||||||
{ "test", "{ \"bank_uri\":3 }" },
|
{ "test", "{ \"type\":\"test\", \"bank_uri\":\"http://localhost/\", \"account_number\":42 }" },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private key used to sign wire details.
|
||||||
|
*/
|
||||||
|
static struct TALER_MasterPrivateKeyP priv_key;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public key matching #priv_key.
|
||||||
|
*/
|
||||||
|
static struct TALER_MasterPublicKeyP pub_key;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Our configuration.
|
||||||
|
*/
|
||||||
|
static struct GNUNET_CONFIGURATION_Handle *cfg;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the test.
|
||||||
|
*
|
||||||
|
* @param name of the test
|
||||||
|
* @param plugin plugin to test
|
||||||
|
* @param wire wire details for testing
|
||||||
|
* @return #GNUNET_OK on success
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
run_test (const char *name,
|
||||||
|
struct TALER_WIRE_Plugin *plugin,
|
||||||
|
json_t *wire)
|
||||||
|
{
|
||||||
|
struct GNUNET_HashCode salt;
|
||||||
|
struct TALER_MasterSignatureP sig;
|
||||||
|
json_t *lwire;
|
||||||
|
|
||||||
|
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
|
||||||
|
&salt,
|
||||||
|
sizeof (salt));
|
||||||
|
if (GNUNET_OK !=
|
||||||
|
plugin->sign_wire_details (plugin->cls,
|
||||||
|
wire,
|
||||||
|
&priv_key,
|
||||||
|
&salt,
|
||||||
|
&sig))
|
||||||
|
{
|
||||||
|
GNUNET_break (0);
|
||||||
|
return GNUNET_SYSERR;
|
||||||
|
}
|
||||||
|
json_object_set_new (wire,
|
||||||
|
"salt",
|
||||||
|
GNUNET_JSON_from_data (&salt,
|
||||||
|
sizeof (salt)));
|
||||||
|
json_object_set_new (wire,
|
||||||
|
"sig",
|
||||||
|
GNUNET_JSON_from_data (&sig,
|
||||||
|
sizeof (sig)));
|
||||||
|
if (GNUNET_OK !=
|
||||||
|
plugin->wire_validate (plugin->cls,
|
||||||
|
wire,
|
||||||
|
&pub_key))
|
||||||
|
{
|
||||||
|
GNUNET_break (0);
|
||||||
|
return GNUNET_SYSERR;
|
||||||
|
}
|
||||||
|
/* load wire details from file */
|
||||||
|
lwire = plugin->get_wire_details (plugin->cls,
|
||||||
|
cfg,
|
||||||
|
name);
|
||||||
|
if (NULL == lwire)
|
||||||
|
{
|
||||||
|
GNUNET_break (0);
|
||||||
|
return GNUNET_SYSERR;
|
||||||
|
}
|
||||||
|
if (GNUNET_OK !=
|
||||||
|
plugin->wire_validate (plugin->cls,
|
||||||
|
lwire,
|
||||||
|
&pub_key))
|
||||||
|
{
|
||||||
|
GNUNET_break (0);
|
||||||
|
json_decref (lwire);
|
||||||
|
return GNUNET_SYSERR;
|
||||||
|
}
|
||||||
|
json_decref (lwire);
|
||||||
|
return GNUNET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc,
|
main (int argc,
|
||||||
const char *const argv[])
|
const char *const argv[])
|
||||||
{
|
{
|
||||||
json_t *wire;
|
json_t *wire;
|
||||||
json_error_t error;
|
|
||||||
int ret;
|
int ret;
|
||||||
struct GNUNET_CONFIGURATION_Handle *cfg;
|
|
||||||
struct TALER_WIRE_Plugin *plugin;
|
struct TALER_WIRE_Plugin *plugin;
|
||||||
const struct TestBlock *test;
|
const struct TestBlock *test;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
|
||||||
|
|
||||||
GNUNET_log_setup ("test-wire-plugin",
|
GNUNET_log_setup ("test-wire-plugin",
|
||||||
"WARNING",
|
"WARNING",
|
||||||
NULL);
|
NULL);
|
||||||
cfg = GNUNET_CONFIGURATION_create ();
|
cfg = GNUNET_CONFIGURATION_create ();
|
||||||
GNUNET_CONFIGURATION_set_value_string (cfg,
|
GNUNET_assert (GNUNET_OK ==
|
||||||
"exchange",
|
GNUNET_CONFIGURATION_load (cfg,
|
||||||
"currency",
|
"test_wire_plugin.conf"));
|
||||||
"EUR");
|
pk = GNUNET_CRYPTO_eddsa_key_create_from_file ("test_wire_plugin_key.priv");
|
||||||
|
priv_key.eddsa_priv = *pk;
|
||||||
|
GNUNET_free (pk);
|
||||||
|
GNUNET_CRYPTO_eddsa_key_get_public (&priv_key.eddsa_priv,
|
||||||
|
&pub_key.eddsa_pub);
|
||||||
ret = GNUNET_OK;
|
ret = GNUNET_OK;
|
||||||
for (i=0;NULL != (test = &tests[i])->plugin_name;i++)
|
for (i=0;NULL != (test = &tests[i])->plugin_name;i++)
|
||||||
{
|
{
|
||||||
@ -82,7 +172,7 @@ main (int argc,
|
|||||||
GNUNET_assert (NULL != plugin);
|
GNUNET_assert (NULL != plugin);
|
||||||
wire = json_loads (test->json_proto, 0, NULL);
|
wire = json_loads (test->json_proto, 0, NULL);
|
||||||
GNUNET_assert (NULL != wire);
|
GNUNET_assert (NULL != wire);
|
||||||
// FIXME: do test...
|
ret = run_test (test->plugin_name, plugin, wire);
|
||||||
json_decref (wire);
|
json_decref (wire);
|
||||||
TALER_WIRE_plugin_unload (plugin);
|
TALER_WIRE_plugin_unload (plugin);
|
||||||
if (GNUNET_OK != ret)
|
if (GNUNET_OK != ret)
|
||||||
|
21
src/wire/test_wire_plugin.conf
Normal file
21
src/wire/test_wire_plugin.conf
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# This file is in the public domain.
|
||||||
|
#
|
||||||
|
[test]
|
||||||
|
# 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 = test_wire_plugin_test.json
|
||||||
|
|
||||||
|
[sepa]
|
||||||
|
# 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 = test_wire_plugin_sepa.json
|
||||||
|
|
||||||
|
|
||||||
|
[wire-outgoing-test]
|
||||||
|
# For transfers made by the exchange, we need to know
|
||||||
|
# the URI of the bank (where the /admin/add/incoming API
|
||||||
|
# is avaialble).
|
||||||
|
BANK_URI = http://localhost/
|
||||||
|
|
||||||
|
[exchange]
|
||||||
|
CURRENCY = "EUR"
|
1
src/wire/test_wire_plugin_key.priv
Normal file
1
src/wire/test_wire_plugin_key.priv
Normal file
@ -0,0 +1 @@
|
|||||||
|
?Sg˙Ýb<C39D>@J€Ďs;Ť%aK¤ČŔȉís_ŢőHŃž
|
8
src/wire/test_wire_plugin_sepa.json
Normal file
8
src/wire/test_wire_plugin_sepa.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"salt": "32V01R7K4T02S74PZZMVXRQ1K7FR948RBNB9BJ5Z101HEQFH7CW7J82006GY3BPTGQ4FM775PSSRD3K9MY97HSNVVCGEVBPVSAQ2710",
|
||||||
|
"type": "sepa",
|
||||||
|
"iban": "DE67830654080004822650",
|
||||||
|
"sig": "K48GPPM715ZXX0DC597WESD5ECT3R0B3TAFQMB68SBF4K5CZ5KCE9NESN1JX412SPZ82PSV7JAPVJFXDDTZ63YV4295S5RC28E4221G",
|
||||||
|
"name": "GNUnet e.V.",
|
||||||
|
"bic": "GENODEF1SLR"
|
||||||
|
}
|
7
src/wire/test_wire_plugin_test.json
Normal file
7
src/wire/test_wire_plugin_test.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"type": "test",
|
||||||
|
"bank_uri": "http://localhost/",
|
||||||
|
"sig": "KX1CMHNFH1WE10244AEF07AXHJCF9PZDZVNZBC9P4EJEQ1MH1Y3C2TWF08VTQMK4N5TCV0V1VTGWSV0WB8TB9YQRZW87F5A6KCEZ81R",
|
||||||
|
"account_number": 42,
|
||||||
|
"salt": "EZV905MQPVAZEMGC6SEZQF2Z75P6ZKTN8TX00JHN11S7J81DQ78G8Z551K6TGR9WHPP0JW1X9J9X9CVRY48JTHBCP6Q4XKJ6R2G18G0"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user