adding separate test just for /verison API
This commit is contained in:
parent
dabcf7f42e
commit
9de8b77625
1
src/lib/.gitignore
vendored
Normal file
1
src/lib/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
test_auditor_api_version
|
@ -158,6 +158,7 @@ check_PROGRAMS = \
|
|||||||
test_exchange_api_overlapping_keys_bug \
|
test_exchange_api_overlapping_keys_bug \
|
||||||
test_exchange_api_interpreter_on-off \
|
test_exchange_api_interpreter_on-off \
|
||||||
test_exchange_api_new \
|
test_exchange_api_new \
|
||||||
|
test_auditor_api_version \
|
||||||
test_auditor_api
|
test_auditor_api
|
||||||
|
|
||||||
if HAVE_TWISTER
|
if HAVE_TWISTER
|
||||||
@ -257,6 +258,17 @@ test_auditor_api_LDADD = \
|
|||||||
-ljansson
|
-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 = \
|
EXTRA_DIST = \
|
||||||
test_exchange_api_home/.local/share/taler/exchange/offline-keys/master.priv \
|
test_exchange_api_home/.local/share/taler/exchange/offline-keys/master.priv \
|
||||||
|
@ -307,6 +307,7 @@ version_completed_cb (void *cls,
|
|||||||
case MHD_HTTP_OK:
|
case MHD_HTTP_OK:
|
||||||
if (NULL == resp_obj)
|
if (NULL == resp_obj)
|
||||||
{
|
{
|
||||||
|
GNUNET_break_op (0);
|
||||||
response_code = 0;
|
response_code = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -316,6 +317,7 @@ version_completed_cb (void *cls,
|
|||||||
&auditor->vi,
|
&auditor->vi,
|
||||||
&vc))
|
&vc))
|
||||||
{
|
{
|
||||||
|
GNUNET_break_op (0);
|
||||||
response_code = 0;
|
response_code = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -329,6 +331,10 @@ version_completed_cb (void *cls,
|
|||||||
}
|
}
|
||||||
if (MHD_HTTP_OK != response_code)
|
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;
|
auditor->vr = NULL;
|
||||||
free_version_request (vr);
|
free_version_request (vr);
|
||||||
auditor->state = MHS_FAILED;
|
auditor->state = MHS_FAILED;
|
||||||
@ -343,6 +349,9 @@ version_completed_cb (void *cls,
|
|||||||
auditor->vr = NULL;
|
auditor->vr = NULL;
|
||||||
free_version_request (vr);
|
free_version_request (vr);
|
||||||
auditor->state = MHS_VERSION;
|
auditor->state = MHS_VERSION;
|
||||||
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||||
|
"Auditor %p is now READY!\n",
|
||||||
|
auditor);
|
||||||
/* notify application about the key information */
|
/* notify application about the key information */
|
||||||
auditor->version_cb (auditor->version_cb_cls,
|
auditor->version_cb (auditor->version_cb_cls,
|
||||||
&auditor->vi,
|
&auditor->vi,
|
||||||
@ -375,6 +384,10 @@ MAH_handle_to_context (struct TALER_AUDITOR_Handle *h)
|
|||||||
int
|
int
|
||||||
MAH_handle_is_ready (struct TALER_AUDITOR_Handle *h)
|
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;
|
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;
|
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 = GNUNET_new (struct TALER_AUDITOR_Handle);
|
||||||
auditor->ctx = ctx;
|
auditor->ctx = ctx;
|
||||||
auditor->url = GNUNET_strdup (url);
|
auditor->url = GNUNET_strdup (url);
|
||||||
@ -475,18 +491,24 @@ request_version (void *cls)
|
|||||||
vr->auditor = auditor;
|
vr->auditor = auditor;
|
||||||
vr->url = MAH_path_to_url (auditor,
|
vr->url = MAH_path_to_url (auditor,
|
||||||
"/version");
|
"/version");
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||||
"Requesting version with URL `%s'.\n",
|
"Requesting auditor version with URL `%s'.\n",
|
||||||
vr->url);
|
vr->url);
|
||||||
eh = TAL_curl_easy_get (vr->url);
|
eh = TAL_curl_easy_get (vr->url);
|
||||||
|
#if 0
|
||||||
GNUNET_assert (CURLE_OK ==
|
GNUNET_assert (CURLE_OK ==
|
||||||
curl_easy_setopt (eh,
|
curl_easy_setopt (eh,
|
||||||
CURLOPT_VERBOSE,
|
CURLOPT_VERBOSE,
|
||||||
0));
|
0L));
|
||||||
|
GNUNET_assert (CURLE_OK ==
|
||||||
|
curl_easy_setopt (eh,
|
||||||
|
CURLOPT_FRESH_CONNECT,
|
||||||
|
0L));
|
||||||
GNUNET_assert (CURLE_OK ==
|
GNUNET_assert (CURLE_OK ==
|
||||||
curl_easy_setopt (eh,
|
curl_easy_setopt (eh,
|
||||||
CURLOPT_TIMEOUT,
|
CURLOPT_TIMEOUT,
|
||||||
(long) 300));
|
(long) 300));
|
||||||
|
#endif
|
||||||
GNUNET_assert (CURLE_OK ==
|
GNUNET_assert (CURLE_OK ==
|
||||||
curl_easy_setopt (eh,
|
curl_easy_setopt (eh,
|
||||||
CURLOPT_HEADERDATA,
|
CURLOPT_HEADERDATA,
|
||||||
|
163
src/lib/test_auditor_api_version.c
Normal file
163
src/lib/test_auditor_api_version.c
Normal file
@ -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 */
|
Loading…
Reference in New Issue
Block a user