adding tests for /wire

This commit is contained in:
Christian Grothoff 2015-09-15 17:27:02 +02:00
parent 1b0f860990
commit e68446e0a8
8 changed files with 125 additions and 25 deletions

View File

@ -2,7 +2,7 @@
# Currency supported by the mint (can only be one)
CURRENCY = EUR
# Wire format supproted by the mint (currently only SEPA is implemented)
# Wire format supported by the mint (currently only SEPA is implemented)
WIREFORMAT = SEPA
# HTTP port the mint listens to
@ -19,3 +19,9 @@ TESTRUN = YES
[mintdb-postgres]
DB_CONN_STR = "postgres:///talercheck"
[mint-wire-sepa]
SEPA_RESPONSE_FILE = "sepa.json"
[mint-wire-test]
REDIRECT_URL = "http://test/"

View File

@ -435,6 +435,29 @@ MAC_download_get_result (struct MAC_DownloadBuffer *db,
{
json_t *json;
json_error_t error;
char *ct;
if ( (CURLE_OK !=
curl_easy_getinfo (eh,
CURLINFO_CONTENT_TYPE,
&ct)) ||
(NULL == ct) ||
(0 != strcasecmp (ct,
"application/json")) )
{
/* No content type or explicitly not JSON, refuse to parse
(but keep response code) */
if (CURLE_OK !=
curl_easy_getinfo (eh,
CURLINFO_RESPONSE_CODE,
response_code))
{
/* unexpected error... */
GNUNET_break (0);
*response_code = 0;
}
return NULL;
}
json = NULL;
if (0 == db->eno)

View File

@ -284,6 +284,7 @@ handle_wire_method_finished (void *cls,
NULL);
json_decref (json);
TALER_MINT_wire_cancel (wh);
return;
}
/* pass on successful reply */
wh->cb (wh->cb_cls,
@ -345,6 +346,11 @@ request_wire_method (struct TALER_MINT_WireHandle *wh)
curl_easy_setopt (eh,
CURLOPT_WRITEDATA,
&wh->db));
/* The default is 'disabled', but let's be sure */
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_FOLLOWLOCATION,
(long) 0));
ctx = MAH_handle_to_context (wh->mint);
wh->job = MAC_job_add (ctx,
eh,
@ -514,7 +520,8 @@ handle_wire_finished (void *cls,
0,
NULL,
NULL);
json_decref (json);
if (NULL != json)
json_decref (json);
TALER_MINT_wire_cancel (wh);
}

View File

@ -2,9 +2,12 @@
# Currency supported by the mint (can only be one)
CURRENCY = EUR
# Wire format supproted by the mint
# TEST is used for testing... (what a shock)
WIREFORMAT = TEST
# Wire format supported by the mint
# We use 'test' for testing, in principle we should
# run tests for all supported wire formats...
# (we should first implement support for a mint running
# with multiple formats at the same time).
WIREFORMAT = test
# HTTP port the mint listens to
PORT = 8081
@ -21,3 +24,9 @@ TESTRUN = YES
[mintdb-postgres]
DB_CONN_STR = "postgres:///talercheck"
[mint-wire-sepa]
SEPA_RESPONSE_FILE = "test-mint-home/sepa.json"
[mint-wire-test]
REDIRECT_URL = "http://www.taler.net/"

View File

@ -0,0 +1,6 @@
{
"receiver_name": "Max Mustermann",
"iban": "DE89370400440532013000",
"bic": "COBADEFF370",
"sig": "8M5YJXM68PRAXKH76HYEBCJW657B23JA0RFGNDMZK2379YZMT626H1BN89KC0M1KJBWGYEN5Z763Q0Y7MCTZQ6BPPT7D9KFCTW60C10"
}

View File

@ -26,6 +26,15 @@
#include <gnunet/gnunet_util_lib.h>
#include <microhttpd.h>
/**
* Is the configuration file is set to include wire format 'test'?
*/
#define WIRE_TEST 1
/**
* Is the configuration file is set to include wire format 'sepa'?
*/
#define WIRE_SEPA 0
/**
* Main execution context for the main loop.
@ -1357,7 +1366,6 @@ interpreter_run (void *cls,
&coin_pub.eddsa_pub);
cmd->details.withdraw_sign.blinding_key.rsa_blinding_key
= GNUNET_CRYPTO_rsa_blinding_key_create (GNUNET_CRYPTO_rsa_public_key_len (cmd->details.withdraw_sign.pk->key.rsa_public_key));
cmd->details.withdraw_sign.wsh
= TALER_MINT_withdraw_sign (mint,
cmd->details.withdraw_sign.pk,
@ -1442,7 +1450,6 @@ interpreter_run (void *cls,
fail (is);
return;
}
GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv,
&coin_pub.eddsa_pub);
@ -1464,6 +1471,7 @@ interpreter_run (void *cls,
{
struct TALER_DepositRequestPS dr;
memset (&dr, 0, sizeof (dr));
dr.purpose.size = htonl (sizeof (struct TALER_DepositRequestPS));
dr.purpose.purpose = htonl (TALER_SIGNATURE_WALLET_COIN_DEPOSIT);
dr.h_contract = h_contract;
@ -1482,7 +1490,6 @@ interpreter_run (void *cls,
GNUNET_CRYPTO_eddsa_sign (&coin_priv->eddsa_priv,
&dr.purpose,
&coin_sig.eddsa_signature));
}
cmd->details.deposit.dh
= TALER_MINT_deposit (mint,
@ -1980,6 +1987,26 @@ run (void *cls,
};
static struct Command commands[] =
{
/* *************** start of /wire testing ************** */
#if WIRE_TEST
{ .oc = OC_WIRE,
.label = "wire",
/* /wire/test replies with a 302 redirect */
.expected_response_code = MHD_HTTP_FOUND },
#endif
#if WIRE_SEPA
{ .oc = OC_WIRE,
.label = "wire",
/* /wire/sepa replies with a 200 redirect */
.expected_response_code = MHD_HTTP_OK },
#endif
/* *************** end of /wire testing ************** */
#if WIRE_TEST
/* None of this works if 'test' is not allowed as we do
/admin/add/incoming with format 'test' */
/* Fill reserve with EUR:5.01, as withdraw fee is 1 ct per config */
{ .oc = OC_ADMIN_ADD_INCOMING,
.label = "create-reserve-1",
@ -2126,8 +2153,8 @@ run (void *cls,
// FIXME: also test with coin that was already melted
// (signature differs from coin that was deposited...)
/* *************** end of /refresh testing ************** */
#endif
{ .oc = OC_END }
};

View File

@ -177,7 +177,7 @@ handle_mhd_request (void *cls,
{ "/wire/test", MHD_HTTP_METHOD_GET, "application/json",
NULL, 0,
&TMH_WIRE_handler_wire_test, MHD_HTTP_OK },
&TMH_WIRE_handler_wire_test, MHD_HTTP_FOUND },
{ "/wire/test", NULL, "text/plain",
"Only GET is allowed", 0,
&TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED },

View File

@ -63,7 +63,7 @@ TMH_WIRE_handler_wire (struct TMH_RequestHandler *rh,
json_string (TMH_expected_wire_format));
return TMH_RESPONSE_reply_json_pack (connection,
MHD_HTTP_OK,
"{s:s, s:o, s:o}",
"{s:o, s:o, s:o}",
"methods", methods,
"sig", TALER_json_from_data (&sig,
sizeof (sig)),
@ -100,26 +100,30 @@ TMH_WIRE_handler_wire_test (struct TMH_RequestHandler *rh,
GNUNET_break (0);
return MHD_NO;
}
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"mint-wire-test",
"REDIRECT_URL",
&wire_test_redirect))
if (0 != strcasecmp ("test",
TMH_expected_wire_format))
{
/* Return 501: not implemented */
ret = MHD_queue_response (connection,
MHD_HTTP_NOT_IMPLEMENTED,
response);
MHD_destroy_response (response);
return ret;
}
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"mint-wire-test",
"REDIRECT_URL",
&wire_test_redirect))
{
/* oopsie, configuration error */
return TMH_RESPONSE_reply_internal_error (connection,
"REDIRECT_URL not configured");
}
MHD_add_response_header (response,
MHD_HTTP_HEADER_LOCATION,
wire_test_redirect);
GNUNET_free (wire_test_redirect);
if (NULL != rh->mime_type)
(void) MHD_add_response_header (response,
MHD_HTTP_HEADER_CONTENT_TYPE,
rh->mime_type);
ret = MHD_queue_response (connection,
rh->response_code,
response);
@ -151,11 +155,29 @@ TMH_WIRE_handler_wire_sepa (struct TMH_RequestHandler *rh,
int fd;
struct stat sbuf;
if (0 != strcasecmp ("sepa",
TMH_expected_wire_format))
{
/* Return 501: not implemented */
response = MHD_create_response_from_buffer (0, NULL,
MHD_RESPMEM_PERSISTENT);
if (NULL == response)
{
GNUNET_break (0);
return MHD_NO;
}
ret = MHD_queue_response (connection,
MHD_HTTP_NOT_IMPLEMENTED,
response);
MHD_destroy_response (response);
return ret;
}
/* Fetch reply */
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"mint-wire-sepa",
"SEPA_RESPONSE_FILE",
&sepa_wire_file))
GNUNET_CONFIGURATION_get_value_filename (cfg,
"mint-wire-sepa",
"SEPA_RESPONSE_FILE",
&sepa_wire_file))
{
return TMH_RESPONSE_reply_internal_error (connection,
"SEPA_RESPONSE_FILE not configured");