aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-01-24 18:45:47 +0100
committerChristian Grothoff <christian@grothoff.org>2019-01-24 18:45:47 +0100
commit9de8b7762547e4064d618cf2ad1e4da8a1f6994b (patch)
tree304c1b733a5b3eed64a7ebcad3cac39f4dc4fc74
parentdabcf7f42e4d15fa86f54e1dbf300c19a9adcb6e (diff)
adding separate test just for /verison API
-rw-r--r--src/lib/.gitignore1
-rw-r--r--src/lib/Makefile.am12
-rw-r--r--src/lib/auditor_api_handle.c28
-rw-r--r--src/lib/test_auditor_api_version.c163
4 files changed, 201 insertions, 3 deletions
diff --git a/src/lib/.gitignore b/src/lib/.gitignore
new file mode 100644
index 000000000..202684432
--- /dev/null
+++ b/src/lib/.gitignore
@@ -0,0 +1 @@
+test_auditor_api_version
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 6f4ffbdf9..b44eccbc8 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -158,6 +158,7 @@ check_PROGRAMS = \
test_exchange_api_overlapping_keys_bug \
test_exchange_api_interpreter_on-off \
test_exchange_api_new \
+ test_auditor_api_version \
test_auditor_api
if HAVE_TWISTER
@@ -257,6 +258,17 @@ test_auditor_api_LDADD = \
-ljansson
+test_auditor_api_version_SOURCES = \
+ test_auditor_api_version.c
+test_auditor_api_version_LDADD = \
+ libtalerauditor.la \
+ $(LIBGCRYPT_LIBS) \
+ $(top_builddir)/src/util/libtalerutil.la \
+ -lgnunetcurl \
+ -lgnunetutil \
+ -ljansson
+
+
EXTRA_DIST = \
test_exchange_api_home/.local/share/taler/exchange/offline-keys/master.priv \
diff --git a/src/lib/auditor_api_handle.c b/src/lib/auditor_api_handle.c
index fffbd39d0..13dd63df6 100644
--- a/src/lib/auditor_api_handle.c
+++ b/src/lib/auditor_api_handle.c
@@ -307,6 +307,7 @@ version_completed_cb (void *cls,
case MHD_HTTP_OK:
if (NULL == resp_obj)
{
+ GNUNET_break_op (0);
response_code = 0;
break;
}
@@ -316,6 +317,7 @@ version_completed_cb (void *cls,
&auditor->vi,
&vc))
{
+ GNUNET_break_op (0);
response_code = 0;
break;
}
@@ -329,6 +331,10 @@ version_completed_cb (void *cls,
}
if (MHD_HTTP_OK != response_code)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "/version failed for auditor %p: %u!\n",
+ auditor,
+ (unsigned int) response_code);
auditor->vr = NULL;
free_version_request (vr);
auditor->state = MHS_FAILED;
@@ -343,6 +349,9 @@ version_completed_cb (void *cls,
auditor->vr = NULL;
free_version_request (vr);
auditor->state = MHS_VERSION;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Auditor %p is now READY!\n",
+ auditor);
/* notify application about the key information */
auditor->version_cb (auditor->version_cb_cls,
&auditor->vi,
@@ -375,6 +384,10 @@ MAH_handle_to_context (struct TALER_AUDITOR_Handle *h)
int
MAH_handle_is_ready (struct TALER_AUDITOR_Handle *h)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Checking if auditor %p is now ready: %s\n",
+ h,
+ (MHD_VERSION == h->state) ? "yes" : "no");
return (MHS_VERSION == h->state) ? GNUNET_YES : GNUNET_NO;
}
@@ -446,6 +459,9 @@ TALER_AUDITOR_connect (struct GNUNET_CURL_Context *ctx,
{
struct TALER_AUDITOR_Handle *auditor;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Connecting to auditor at URL `%s'.\n",
+ url);
auditor = GNUNET_new (struct TALER_AUDITOR_Handle);
auditor->ctx = ctx;
auditor->url = GNUNET_strdup (url);
@@ -475,18 +491,24 @@ request_version (void *cls)
vr->auditor = auditor;
vr->url = MAH_path_to_url (auditor,
"/version");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Requesting version with URL `%s'.\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Requesting auditor version with URL `%s'.\n",
vr->url);
eh = TAL_curl_easy_get (vr->url);
+#if 0
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_VERBOSE,
- 0));
+ 0L));
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_FRESH_CONNECT,
+ 0L));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_TIMEOUT,
(long) 300));
+#endif
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_HEADERDATA,
diff --git a/src/lib/test_auditor_api_version.c b/src/lib/test_auditor_api_version.c
new file mode 100644
index 000000000..7a21430da
--- /dev/null
+++ b/src/lib/test_auditor_api_version.c
@@ -0,0 +1,163 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014-2018 Taler Systems SA
+
+ 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, see
+ <http://www.gnu.org/licenses/>
+*/
+
+/**
+ * @file auditor-lib/test_auditor_api_version.c
+ * @brief testcase to test auditor's HTTP API interface to fetch /version
+ * @author Christian Grothoff
+ * @author Marcello Stanisci
+ */
+#include "platform.h"
+#include "taler_util.h"
+#include "taler_signatures.h"
+#include "taler_exchange_service.h"
+#include "taler_auditor_service.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <microhttpd.h>
+#include "taler_bank_service.h"
+#include "taler_fakebank_lib.h"
+#include "taler_testing_lib.h"
+#include "taler_testing_auditor_lib.h"
+
+/**
+ * Configuration file we use. One (big) configuration is used
+ * for the various components for this test.
+ */
+#define CONFIG_FILE "test_auditor_api.conf"
+
+static struct TALER_AUDITOR_Handle *ah;
+
+static struct GNUNET_CURL_Context *ctx;
+
+static struct GNUNET_CURL_RescheduleContext *rc;
+
+static int global_ret;
+
+static struct GNUNET_SCHEDULER_Task *tt;
+
+static void
+do_shutdown (void *cls)
+{
+ (void) cls;
+
+ if (NULL != tt)
+ {
+ GNUNET_SCHEDULER_cancel (tt);
+ tt = NULL;
+ }
+ TALER_AUDITOR_disconnect (ah);
+ GNUNET_CURL_fini (ctx);
+ GNUNET_CURL_gnunet_rc_destroy (rc);
+}
+
+
+static void
+do_timeout (void *cls)
+{
+ (void) cls;
+ tt = NULL;
+ global_ret = 3;
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
+/**
+ * Function called with information about the auditor.
+ *
+ * @param cls closure
+ * @param vi basic information about the auditor
+ * @param compat protocol compatibility information
+ */
+static void
+version_cb (void *cls,
+ const struct TALER_AUDITOR_VersionInformation *vi,
+ enum TALER_AUDITOR_VersionCompatibility compat)
+{
+ if ( (NULL != vi) &&
+ (TALER_AUDITOR_VC_MATCH == compat) )
+ global_ret = 0;
+ else
+ global_ret = 2;
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
+/**
+ * Main function that will tell the interpreter what commands to
+ * run.
+ *
+ * @param cls closure
+ */
+static void
+run (void *cls)
+{
+ const char *auditor_url = "http://localhost:8083/";
+
+ (void) cls;
+ ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
+ &rc);
+ rc = GNUNET_CURL_gnunet_rc_create (ctx);
+ ah = TALER_AUDITOR_connect (ctx,
+ auditor_url,
+ &version_cb,
+ NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
+ tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &do_timeout,
+ NULL);
+}
+
+
+int
+main (int argc,
+ char * const *argv)
+{
+ struct GNUNET_OS_Process *proc;
+
+ /* These environment variables get in the way... */
+ unsetenv ("XDG_DATA_HOME");
+ unsetenv ("XDG_CONFIG_HOME");
+ GNUNET_log_setup ("test-auditor-api-version",
+ "INFO",
+ NULL);
+ proc = GNUNET_OS_start_process (GNUNET_NO,
+ GNUNET_OS_INHERIT_STD_ALL,
+ NULL, NULL, NULL,
+ "taler-auditor-httpd",
+ "taler-auditor-httpd",
+ "-c", CONFIG_FILE,
+ NULL);
+ if (NULL == proc)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to run `taler-auditor-httpd`,"
+ " is your PATH correct?\n");
+ return 77;
+ }
+ GNUNET_SCHEDULER_run (&run,
+ NULL);
+ GNUNET_OS_process_kill (proc, SIGTERM);
+ GNUNET_OS_process_wait (proc);
+ GNUNET_OS_process_destroy (proc);
+ return global_ret;
+}
+
+/* end of test_auditor_api_version.c */