aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/exchangedb/Makefile.am11
-rw-r--r--src/exchangedb/test_exchangedb_auditors.c173
-rw-r--r--src/exchangedb/test_exchangedb_denomkeys.c2
-rw-r--r--src/exchangedb/test_exchangedb_signkeys.c2
-rw-r--r--src/include/taler_exchangedb_lib.h3
5 files changed, 186 insertions, 5 deletions
diff --git a/src/exchangedb/Makefile.am b/src/exchangedb/Makefile.am
index 7cc3a4da8..f6754e803 100644
--- a/src/exchangedb/Makefile.am
+++ b/src/exchangedb/Makefile.am
@@ -58,6 +58,7 @@ libtalerexchangedb_la_LDFLAGS = \
check_PROGRAMS = \
+ test-exchangedb-auditors \
test-exchangedb-denomkeys \
test-exchangedb-signkeys \
test-exchangedb-postgres \
@@ -66,17 +67,24 @@ check_PROGRAMS = \
AM_TESTS_ENVIRONMENT=export TALER_PREFIX=$${TALER_PREFIX:-@libdir@};export PATH=$${TALER_PREFIX:-@prefix@}/bin:$$PATH;
TESTS = \
+ test-exchangedb-auditors \
test-exchangedb-postgres \
test-exchangedb-signkeys \
test-perf-taler-exchangedb \
test-exchangedb-denomkeys
+test_exchangedb_auditors_SOURCES = \
+ test_exchangedb_auditors.c
+test_exchangedb_auditors_LDADD = \
+ libtalerexchangedb.la \
+ $(top_srcdir)/src/util/libtalerutil.la \
+ -lgnunetutil
+
test_exchangedb_denomkeys_SOURCES = \
test_exchangedb_denomkeys.c
test_exchangedb_denomkeys_LDADD = \
libtalerexchangedb.la \
$(top_srcdir)/src/util/libtalerutil.la \
- $(top_srcdir)/src/pq/libtalerpq.la \
-lgnunetutil
test_exchangedb_signkeys_SOURCES = \
@@ -84,7 +92,6 @@ test_exchangedb_signkeys_SOURCES = \
test_exchangedb_signkeys_LDADD = \
libtalerexchangedb.la \
$(top_srcdir)/src/util/libtalerutil.la \
- $(top_srcdir)/src/pq/libtalerpq.la \
-lgnunetutil
test_exchangedb_postgres_SOURCES = \
diff --git a/src/exchangedb/test_exchangedb_auditors.c b/src/exchangedb/test_exchangedb_auditors.c
new file mode 100644
index 000000000..b68a9e386
--- /dev/null
+++ b/src/exchangedb/test_exchangedb_auditors.c
@@ -0,0 +1,173 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2016 Inria & GNUnet e. V.
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file exchangedb/test_exchangedb_auditors.c
+ * @brief test cases for some functions in exchangedb/exchangedb_auditorkeys.c
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet/gnunet_util_lib.h"
+#include "taler_signatures.h"
+#include "taler_exchangedb_lib.h"
+
+
+#define RSA_KEY_SIZE 1024
+
+
+#define EXITIF(cond) \
+ do { \
+ if (cond) { GNUNET_break (0); goto EXITIF_exit; } \
+ } while (0)
+
+
+static struct TALER_AuditorPublicKeyP want_apub;
+
+static struct TALER_AuditorSignatureP want_asigs;
+
+static struct TALER_MasterPublicKeyP want_mpub;
+
+static struct TALER_DenominationKeyValidityPS want_dki;
+
+
+
+/**
+ * @brief Function called with auditor information.
+ *
+ * @param cls NULL
+ * @param apub the auditor's public key
+ * @param auditor_url URL of the auditor
+ * @param mpub the exchange's public key (as expected by the auditor)
+ * @param dki_len length of @a asig and @a dki arrays
+ * @param asigs array of the auditor's signatures over the @a dks, of length @a dki_len
+ * @param dki array of denomination coin data signed by the auditor, of length @a dki_len
+ * @return #GNUNET_OK to continue to iterate,
+ * #GNUNET_NO to stop iteration with no error,
+ * #GNUNET_SYSERR to abort iteration with error!
+ */
+static int
+auditor_cb (void *cls,
+ const struct TALER_AuditorPublicKeyP *apub,
+ const char *auditor_url,
+ const struct TALER_MasterPublicKeyP *mpub,
+ unsigned int dki_len,
+ const struct TALER_AuditorSignatureP *asigs,
+ const struct TALER_DenominationKeyValidityPS *dki)
+{
+ GNUNET_assert (NULL == cls);
+ if (0 != strcmp (auditor_url,
+ "http://auditor/"))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (1 != dki_len)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (0 != memcmp (&want_apub,
+ apub,
+ sizeof (struct TALER_AuditorPublicKeyP)))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (0 != memcmp (&want_mpub,
+ mpub,
+ sizeof (struct TALER_MasterPublicKeyP)))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (0 != memcmp (&want_asigs,
+ asigs,
+ sizeof (struct TALER_AuditorSignatureP)))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (0 != memcmp (&want_dki,
+ dki,
+ sizeof (struct TALER_DenominationKeyValidityPS)))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+int
+main (int argc,
+ const char *const argv[])
+{
+ char *tmpfile = NULL;
+ char *tmpdir;
+ struct GNUNET_CONFIGURATION_Handle *cfg = NULL;
+ int ret;
+
+ ret = 1;
+ GNUNET_log_setup ("test-exchangedb-auditors",
+ "WARNING",
+ NULL);
+ EXITIF (NULL == (tmpdir = GNUNET_DISK_mkdtemp ("test_exchangedb_auditors")));
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ &want_apub,
+ sizeof (want_apub));
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ &want_asigs,
+ sizeof (want_asigs));
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ &want_mpub,
+ sizeof (want_mpub));
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ &want_dki,
+ sizeof (struct TALER_DenominationKeyValidityPS));
+ EXITIF (NULL == (tmpdir = GNUNET_DISK_mkdtemp ("test_exchangedb_auditors")));
+ GNUNET_asprintf (&tmpfile,
+ "%s/%s",
+ tmpdir,
+ "testauditor");
+ EXITIF (GNUNET_OK !=
+ TALER_EXCHANGEDB_auditor_write (tmpfile,
+ &want_apub,
+ "http://auditor/",
+ &want_asigs,
+ &want_mpub,
+ 1,
+ &want_dki));
+ cfg = GNUNET_CONFIGURATION_create ();
+
+ GNUNET_CONFIGURATION_set_value_string (cfg,
+ "exchangedb",
+ "AUDITOR_BASE_DIR",
+ tmpdir);
+ EXITIF (1 !=
+ TALER_EXCHANGEDB_auditor_iterate (cfg,
+ &auditor_cb,
+ NULL));
+ ret = 0;
+ EXITIF_exit:
+ if (NULL != tmpdir)
+ {
+ (void) GNUNET_DISK_directory_remove (tmpdir);
+ GNUNET_free (tmpdir);
+ }
+ if (NULL != cfg)
+ GNUNET_CONFIGURATION_destroy (cfg);
+ GNUNET_free_non_null (tmpfile);
+ return ret;
+}
diff --git a/src/exchangedb/test_exchangedb_denomkeys.c b/src/exchangedb/test_exchangedb_denomkeys.c
index 0d6ff3a99..204396630 100644
--- a/src/exchangedb/test_exchangedb_denomkeys.c
+++ b/src/exchangedb/test_exchangedb_denomkeys.c
@@ -136,7 +136,7 @@ main (int argc,
GNUNET_free_non_null (enc);
if (NULL != tmpfile)
{
- (void) unlink (tmpfile);
+ (void) GNUNET_DISK_directory_remove (tmpfile);
GNUNET_free (tmpfile);
}
GNUNET_free_non_null (enc_read);
diff --git a/src/exchangedb/test_exchangedb_signkeys.c b/src/exchangedb/test_exchangedb_signkeys.c
index c7916e17c..45b5f631b 100644
--- a/src/exchangedb/test_exchangedb_signkeys.c
+++ b/src/exchangedb/test_exchangedb_signkeys.c
@@ -89,7 +89,7 @@ main (int argc,
EXITIF_exit:
if (NULL != tmpfile)
{
- (void) unlink (tmpfile);
+ (void) GNUNET_DISK_directory_remove (tmpfile);
GNUNET_free (tmpfile);
}
return ret;
diff --git a/src/include/taler_exchangedb_lib.h b/src/include/taler_exchangedb_lib.h
index fd2149229..5da8452d1 100644
--- a/src/include/taler_exchangedb_lib.h
+++ b/src/include/taler_exchangedb_lib.h
@@ -239,7 +239,8 @@ typedef int
/**
- * Call @a it with information for each auditor found in the @a exchange_base_dir.
+ * Call @a it with information for each auditor found in the
+ * directory with auditor information as specified in @a cfg.
*
* @param cfg configuration to use
* @param it function to call with auditor information