/*
This file is part of TALER
Copyright (C) 2023 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
*/
/**
* @file testing/testing_api_cmd_checkserver.c
* @brief Implement a CMD to run an Checkserver service for faking the legitimation service
* @author Priscilla HUANG
*/
#include "platform.h"
#include "taler/taler_json_lib.h"
#include
#include "taler/taler_testing_lib.h"
#include "taler/taler_mhd_lib.h"
#include "taler_merchant_testing_lib.h"
#include "taler_merchant_service.h"
#include
/**
* State for a "check_aml_decision" CMD.
*/
struct CheckState
{
/**
* Handle to the "testserver" service.
*/
struct MHD_Daemon *mhd;
/**
* Our interpreter.
*/
struct TALER_TESTING_Interpreter *is;
/**
* Index to know which web server we check.
*/
unsigned int index;
/**
* Reference to command to the previous set server status operation.
*/
const char *ref_operation;
/**
* Expected method of the pending webhook.
*/
char *expected_method;
/**
* Expected url of the pending webhook.
*/
char *expected_url;
/**
* Expected header of the pending webhook.
*/
char *expected_header;
/**
* Expected body of the pending webhook.
*/
char *expected_body;
};
/**
* Run the command.
*
* @param cls closure.
* @param cmd the command to execute.
* @param is the interpreter state.
*/
static void
checkserver_run (void *cls,
const struct TALER_TESTING_Command *cmd,
struct TALER_TESTING_Interpreter *is)
{
struct CheckState *cs = cls;
const struct TALER_TESTING_Command *ref;
(void) cmd;
cs->is = is;
ref = TALER_TESTING_interpreter_lookup_command (is,
cs->ref_operation);
if (NULL == ref)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"ref NULL\n");
GNUNET_break (0);
TALER_TESTING_interpreter_fail (is);
return;
}
char **expected_url;
if (GNUNET_OK !=
TALER_TESTING_get_trait_urls (ref,
cs->index,
&expected_url))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Trait url does not work\n");
GNUNET_break (0);
TALER_TESTING_interpreter_fail (is);
return;
}
if (NULL == *expected_url)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Trait for url is NULL!?\n");
GNUNET_break (0);
TALER_TESTING_interpreter_fail (is);
return;
}
if (0 != strcmp (cs->expected_url,
*expected_url))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"URL does not match: `%s' != `%s'\n",
cs->expected_url,
*expected_url);
TALER_TESTING_interpreter_fail (is);
return;
}
char **expected_http_method;
if (GNUNET_OK !=
TALER_TESTING_get_trait_http_methods (ref,
cs->index,
&expected_http_method))
TALER_TESTING_interpreter_fail (is);
if (0 != strcmp (cs->expected_method,
*expected_http_method))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"http_method does not match\n");
TALER_TESTING_interpreter_fail (is);
return;
}
char **expected_header;
if (GNUNET_OK !=
TALER_TESTING_get_trait_http_header (ref,
cs->index,
&expected_header))
TALER_TESTING_interpreter_fail (is);
if ( ( (NULL == cs->expected_header) && (NULL != *expected_header)) ||
( (NULL != cs->expected_header) && (NULL == expected_header)) ||
( (NULL != cs->expected_header) &&
(0 != strcmp (cs->expected_header,
*expected_header)) ) )
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"header does not match: `%s' != `%s'\n",
cs->expected_header,
*expected_header);
TALER_TESTING_interpreter_fail (is);
return;
}
char **expected_body;
if (GNUNET_OK !=
TALER_TESTING_get_trait_http_body (ref,
cs->index,
&expected_body))
TALER_TESTING_interpreter_fail (is);
if ( ( (NULL == cs->expected_body) && (NULL != *expected_body)) ||
( (NULL != cs->expected_body) && (NULL == expected_body)) ||
( (NULL != cs->expected_body) &&
(0 != strcmp (cs->expected_body,
*expected_body) ) ) )
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"body does not match : `%s' and `%s'\n",
cs->expected_body,
*expected_body);
TALER_TESTING_interpreter_fail (is);
return;
}
TALER_TESTING_interpreter_next (is);
}
/**
* This function is used to check the web server
*
* @param label command label
* @param ref_operation reference to command to the previous set server status operation.
* @param index index to know which web server we check.
* @param url of the webhook
* @param http_method of the webhook
* @param header of the webhook
* @param body of the webhook
*/
struct TALER_TESTING_Command
TALER_TESTING_cmd_checkserver2 (const char *label,
const char *ref_operation,
unsigned int index,
char *expected_url,
char *expected_method,
char *expected_header,
char *expected_body)
{
struct CheckState *cs;
cs = GNUNET_new (struct CheckState);
cs->ref_operation = ref_operation;
cs->index = index;
cs->expected_url = expected_url;
cs->expected_method = expected_method;
cs->expected_header = expected_header;
cs->expected_body = expected_body;
{
struct TALER_TESTING_Command cmd = {
.cls = cs,
.label = label,
.run = &checkserver_run
};
return cmd;
}
}
struct TALER_TESTING_Command
TALER_TESTING_cmd_checkserver (const char *label,
const char *ref_operation,
unsigned int index)
{
return TALER_TESTING_cmd_checkserver2 (label,
ref_operation,
index,
"/",
"POST",
"EFEHYJS-Bakery",
"5.0 EUR");
}
/* end of testing_api_cmd_checkserver.c */