diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-04-11 15:59:24 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-04-11 15:59:24 +0200 |
commit | a7f2496795a80dca6fbbfb5a20f0ee4b7a72650e (patch) | |
tree | da20ce6de3455c9a24b9ceed92e6fbe0a0e45bea /src/wire/test_wire_plugin.c | |
parent | 58373f2a92536be08db1fc7e9c4dc872e382c2c4 (diff) |
adding wire plugin tests, resolving #4357
Diffstat (limited to 'src/wire/test_wire_plugin.c')
-rw-r--r-- | src/wire/test_wire_plugin.c | 108 |
1 files changed, 99 insertions, 9 deletions
diff --git a/src/wire/test_wire_plugin.c b/src/wire/test_wire_plugin.c index 9f61b21fe..27b4366c1 100644 --- a/src/wire/test_wire_plugin.c +++ b/src/wire/test_wire_plugin.c @@ -23,6 +23,8 @@ #include "taler_util.h" #include "taler_wire_lib.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. */ static struct TestBlock tests[] = { - { "sepa", "{ \"iban\":3 }" }, - { "test", "{ \"bank_uri\":3 }" }, + { "sepa", "{ \"type\":\"sepa\", \"iban\":\"DE67830654080004822650\", \"name\":\"GNUnet e.V.\", \"bic\":\"GENODEF1SLR\" }" }, + { "test", "{ \"type\":\"test\", \"bank_uri\":\"http://localhost/\", \"account_number\":42 }" }, { 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 main (int argc, const char *const argv[]) { json_t *wire; - json_error_t error; int ret; - struct GNUNET_CONFIGURATION_Handle *cfg; struct TALER_WIRE_Plugin *plugin; const struct TestBlock *test; unsigned int i; + struct GNUNET_CRYPTO_EddsaPrivateKey *pk; GNUNET_log_setup ("test-wire-plugin", "WARNING", NULL); cfg = GNUNET_CONFIGURATION_create (); - GNUNET_CONFIGURATION_set_value_string (cfg, - "exchange", - "currency", - "EUR"); + GNUNET_assert (GNUNET_OK == + GNUNET_CONFIGURATION_load (cfg, + "test_wire_plugin.conf")); + 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; for (i=0;NULL != (test = &tests[i])->plugin_name;i++) { @@ -82,7 +172,7 @@ main (int argc, GNUNET_assert (NULL != plugin); wire = json_loads (test->json_proto, 0, NULL); GNUNET_assert (NULL != wire); - // FIXME: do test... + ret = run_test (test->plugin_name, plugin, wire); json_decref (wire); TALER_WIRE_plugin_unload (plugin); if (GNUNET_OK != ret) |