2018-11-11 16:45:09 +01:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
|
|
|
Copyright (C) 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/>
|
|
|
|
*/
|
|
|
|
/**
|
2020-01-19 15:23:19 +01:00
|
|
|
* @file testing/testing_api_helpers_auditor.c
|
2018-11-11 16:45:09 +01:00
|
|
|
* @brief helper functions
|
|
|
|
* @author Christian Grothoff
|
|
|
|
*/
|
|
|
|
#include "platform.h"
|
|
|
|
#include "taler_json_lib.h"
|
|
|
|
#include <gnunet/gnunet_curl_lib.h>
|
|
|
|
#include "taler_testing_lib.h"
|
|
|
|
#include "taler_auditor_service.h"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Closure for #cleanup_auditor.
|
|
|
|
*/
|
|
|
|
struct CleanupContext
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Where we find the state to clean up.
|
|
|
|
*/
|
|
|
|
struct TALER_TESTING_Interpreter *is;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Next cleanup routine to call, NULL for none.
|
|
|
|
*/
|
|
|
|
GNUNET_SCHEDULER_TaskCallback fcb;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Closure for @e fcb
|
|
|
|
*/
|
|
|
|
void *fcb_cls;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to clean up the auditor connection.
|
|
|
|
*
|
|
|
|
* @param cls a `struct CleanupContext`
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
cleanup_auditor (void *cls)
|
|
|
|
{
|
|
|
|
struct CleanupContext *cc = cls;
|
|
|
|
struct TALER_TESTING_Interpreter *is = cc->is;
|
|
|
|
|
|
|
|
TALER_AUDITOR_disconnect (is->auditor);
|
|
|
|
is->auditor = NULL;
|
|
|
|
if (NULL != cc->fcb)
|
|
|
|
cc->fcb (cc->fcb_cls);
|
|
|
|
GNUNET_free (cc);
|
|
|
|
}
|
|
|
|
|
2019-10-31 12:59:50 +01:00
|
|
|
|
2018-11-11 16:45:09 +01:00
|
|
|
/**
|
|
|
|
* Closure for #auditor_main_wrapper()
|
|
|
|
*/
|
|
|
|
struct MainWrapperContext
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Main function to launch.
|
|
|
|
*/
|
|
|
|
TALER_TESTING_Main main_cb;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Closure for @e main_cb.
|
|
|
|
*/
|
|
|
|
void *main_cb_cls;
|
|
|
|
|
2018-11-18 14:41:27 +01:00
|
|
|
/**
|
|
|
|
* Configuration we use.
|
|
|
|
*/
|
|
|
|
const struct GNUNET_CONFIGURATION_Handle *cfg;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Name of the configuration file.
|
|
|
|
*/
|
|
|
|
const char *config_filename;
|
|
|
|
|
2018-11-11 16:45:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-01-25 15:57:27 +01:00
|
|
|
/**
|
|
|
|
* Function called with information about the auditor.
|
|
|
|
*
|
|
|
|
* @param cls closure
|
2020-04-05 22:05:38 +02:00
|
|
|
* @param hr http response details
|
2019-01-25 15:57:27 +01:00
|
|
|
* @param vi basic information about the auditor
|
|
|
|
* @param compat protocol compatibility information
|
|
|
|
*/
|
|
|
|
static void
|
2020-01-18 17:06:24 +01:00
|
|
|
auditor_version_cb (void *cls,
|
2020-04-05 22:05:38 +02:00
|
|
|
const struct TALER_AUDITOR_HttpResponse *hr,
|
2020-01-18 17:06:24 +01:00
|
|
|
const struct TALER_AUDITOR_VersionInformation *vi,
|
|
|
|
enum TALER_AUDITOR_VersionCompatibility compat)
|
2019-01-25 15:57:27 +01:00
|
|
|
{
|
|
|
|
struct TALER_TESTING_Interpreter *is = cls;
|
|
|
|
|
2020-04-05 22:05:38 +02:00
|
|
|
(void) hr;
|
2019-01-25 16:03:46 +01:00
|
|
|
if (TALER_AUDITOR_VC_MATCH != compat)
|
|
|
|
{
|
|
|
|
TALER_TESTING_interpreter_fail (is);
|
|
|
|
return;
|
|
|
|
}
|
2019-01-25 15:57:27 +01:00
|
|
|
is->auditor_working = GNUNET_YES;
|
|
|
|
}
|
|
|
|
|
2019-10-31 12:59:50 +01:00
|
|
|
|
2018-11-11 16:45:09 +01:00
|
|
|
/**
|
|
|
|
* Setup the @a is 'auditor' member before running the main test loop.
|
|
|
|
*
|
|
|
|
* @param cls must be a `struct MainWrapperContext *`
|
2020-01-18 17:06:24 +01:00
|
|
|
* @param[in,out] is interpreter state to setup
|
2018-11-11 16:45:09 +01:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
auditor_main_wrapper (void *cls,
|
|
|
|
struct TALER_TESTING_Interpreter *is)
|
|
|
|
{
|
|
|
|
struct MainWrapperContext *mwc = cls;
|
|
|
|
struct CleanupContext *cc;
|
|
|
|
char *auditor_base_url;
|
|
|
|
|
|
|
|
if (GNUNET_OK !=
|
2018-11-18 14:41:27 +01:00
|
|
|
GNUNET_CONFIGURATION_get_value_string (mwc->cfg,
|
2018-11-11 16:45:09 +01:00
|
|
|
"auditor",
|
|
|
|
"BASE_URL",
|
|
|
|
&auditor_base_url))
|
2019-08-25 16:18:24 +02:00
|
|
|
{
|
2018-11-11 16:45:09 +01:00
|
|
|
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
|
|
|
|
"auditor",
|
|
|
|
"BASE_URL");
|
|
|
|
return;
|
|
|
|
}
|
2019-01-24 17:53:10 +01:00
|
|
|
|
2019-01-25 15:57:27 +01:00
|
|
|
is->auditor = TALER_AUDITOR_connect (is->ctx,
|
|
|
|
auditor_base_url,
|
|
|
|
&auditor_version_cb,
|
|
|
|
is);
|
2018-11-11 16:45:09 +01:00
|
|
|
GNUNET_free (auditor_base_url);
|
2019-01-25 15:57:27 +01:00
|
|
|
|
|
|
|
if (NULL == is->auditor)
|
|
|
|
{
|
|
|
|
GNUNET_break (0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-11 16:45:09 +01:00
|
|
|
cc = GNUNET_new (struct CleanupContext);
|
|
|
|
cc->is = is;
|
|
|
|
cc->fcb = is->final_cleanup_cb;
|
2020-01-17 15:08:58 +01:00
|
|
|
cc->fcb_cls = is->final_cleanup_cb_cls;
|
2019-01-25 15:57:27 +01:00
|
|
|
is->final_cleanup_cb = cleanup_auditor;
|
2018-11-11 16:45:09 +01:00
|
|
|
is->final_cleanup_cb_cls = cc;
|
|
|
|
mwc->main_cb (mwc->main_cb_cls,
|
|
|
|
is);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-18 14:41:27 +01:00
|
|
|
/**
|
|
|
|
* Install signal handlers plus schedules the main wrapper
|
|
|
|
* around the "run" method.
|
|
|
|
*
|
|
|
|
* @param cls our `struct MainWrapperContext`
|
|
|
|
* @param cfg configuration we use
|
|
|
|
* @return #GNUNET_OK if all is okay, != #GNUNET_OK otherwise.
|
|
|
|
* non-GNUNET_OK codes are #GNUNET_SYSERR most of the
|
|
|
|
* times.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
setup_with_cfg (void *cls,
|
|
|
|
const struct GNUNET_CONFIGURATION_Handle *cfg)
|
|
|
|
{
|
|
|
|
struct MainWrapperContext *mwc = cls;
|
|
|
|
struct TALER_TESTING_SetupContext setup_ctx = {
|
|
|
|
.config_filename = mwc->config_filename,
|
|
|
|
.main_cb = &auditor_main_wrapper,
|
|
|
|
.main_cb_cls = mwc
|
|
|
|
};
|
|
|
|
|
|
|
|
mwc->cfg = cfg;
|
|
|
|
return TALER_TESTING_setup_with_auditor_and_exchange_cfg (&setup_ctx,
|
|
|
|
cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-11 16:45:09 +01:00
|
|
|
/**
|
|
|
|
* Install signal handlers plus schedules the main wrapper
|
|
|
|
* around the "run" method.
|
|
|
|
*
|
|
|
|
* @param main_cb the "run" method which contains all the
|
|
|
|
* commands.
|
|
|
|
* @param main_cb_cls a closure for "run", typically NULL.
|
|
|
|
* @param config_filename configuration filename.
|
|
|
|
* @return #GNUNET_OK if all is okay, != #GNUNET_OK otherwise.
|
|
|
|
* non-GNUNET_OK codes are #GNUNET_SYSERR most of the
|
|
|
|
* times.
|
|
|
|
*/
|
|
|
|
int
|
2020-01-18 14:24:55 +01:00
|
|
|
TALER_TESTING_auditor_setup (TALER_TESTING_Main main_cb,
|
2018-11-11 16:45:09 +01:00
|
|
|
void *main_cb_cls,
|
|
|
|
const char *config_filename)
|
|
|
|
{
|
|
|
|
struct MainWrapperContext mwc = {
|
|
|
|
.main_cb = main_cb,
|
2018-11-18 14:41:27 +01:00
|
|
|
.main_cb_cls = main_cb_cls,
|
|
|
|
.config_filename = config_filename
|
2018-11-11 16:45:09 +01:00
|
|
|
};
|
|
|
|
|
2018-11-18 14:41:27 +01:00
|
|
|
return GNUNET_CONFIGURATION_parse_and_run (config_filename,
|
|
|
|
&setup_with_cfg,
|
|
|
|
&mwc);
|
2018-11-11 16:45:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* end of testing_auditor_api_helpers.c */
|