refactor uri parsing logic, prepare for unit test

This commit is contained in:
Christian Grothoff 2020-01-14 15:57:36 +01:00
parent cba9f8614e
commit 2edee5ac4a
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
12 changed files with 149 additions and 36 deletions

View File

@ -270,7 +270,7 @@ TALER_BANK_credit_history (struct GNUNET_CURL_Context *ctx,
hh->bank_base_url = GNUNET_strdup (bank_base_url);
hh->request_url = TALER_BANK_path_to_url_ (bank_base_url,
url);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Requesting history at `%s'\n",
hh->request_url);
eh = curl_easy_init ();

View File

@ -273,7 +273,7 @@ TALER_BANK_debit_history (struct GNUNET_CURL_Context *ctx,
hh->request_url = TALER_BANK_path_to_url_ (bank_base_url,
url);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Requesting history at `%s'\n",
hh->request_url);
eh = curl_easy_init ();

View File

@ -1111,7 +1111,7 @@ serve (struct TALER_FAKEBANK_Handle *h,
size_t *upload_data_size,
void **con_cls)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Fakebank, serving URL `%s' for account `%s'\n",
url,
account);
@ -1198,6 +1198,9 @@ handle_mhd_request (void *cls,
int ret;
(void) version;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Handling request for `%s'\n",
url);
if ( (strlen (url) > 1) &&
(NULL != (end = strchr (url + 1, '/'))) )
{

View File

@ -765,7 +765,7 @@ create_denomkey_issue (const struct CoinTypeParams *params,
GNUNET_assert (NULL != dki->denom_priv.rsa_private_key);
dki->denom_pub.rsa_public_key
= GNUNET_CRYPTO_rsa_private_key_get_public (
dki->denom_priv.rsa_private_key);
dki->denom_priv.rsa_private_key);
GNUNET_CRYPTO_rsa_public_key_hash (dki->denom_pub.rsa_public_key,
&dki->issue.properties.denom_hash);
dki->issue.properties.master = master_public_key;

View File

@ -771,9 +771,9 @@ handle_refresh_reveal_json (struct MHD_Connection *connection,
{
rctx->ev_sigs[i].rsa_signature
= GNUNET_CRYPTO_rsa_sign_blinded (
rctx->dkis[i]->denom_priv.rsa_private_key,
rctx->rcds[i].coin_ev,
rctx->rcds[i].coin_ev_size);
rctx->dkis[i]->denom_priv.rsa_private_key,
rctx->rcds[i].coin_ev,
rctx->rcds[i].coin_ev_size);
if (NULL == rctx->ev_sigs[i].rsa_signature)
{
GNUNET_break (0);

View File

@ -403,4 +403,27 @@ char *
TALER_payto_xtalerbank_make (const char *bank_url,
const char *account_name);
/**
* Given an x-taler-bank payto:// URL, compute
* the HTTP(S) base URL of the account.
*
* @param payto the payto URL
* @return bank URL of the account, NULL if not x-taler-bak payto URL
*/
char *
TALER_xtalerbank_base_url_from_payto (const char *payto);
/**
* Given an x-taler-bank payto:// URL, compute
* the HTTP(S) base URL of the account.
*
* @param payto the payto URL
* @return bank URL of the account, NULL if not x-taler-bak payto URL
*/
char *
TALER_xtalerbank_account_url_from_payto (const char *payto);
#endif

View File

@ -1262,7 +1262,7 @@ keys_completed_cb (void *cls,
for (unsigned int i = 0; i<kd_old.num_denom_keys; i++)
kd.denom_keys[i].key.rsa_public_key
= GNUNET_CRYPTO_rsa_public_key_dup (
kd_old.denom_keys[i].key.rsa_public_key);
kd_old.denom_keys[i].key.rsa_public_key);
kd.num_auditors = kd_old.num_auditors;
kd.auditors = GNUNET_new_array (kd.num_auditors,

View File

@ -374,9 +374,6 @@ TALER_TESTING_prepare_fakebank (const char *config_filename,
{
struct GNUNET_CONFIGURATION_Handle *cfg;
char *payto_url;
char *fakebank_url;
const char *start;
const char *end;
cfg = GNUNET_CONFIGURATION_create ();
if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg,
@ -395,38 +392,30 @@ TALER_TESTING_prepare_fakebank (const char *config_filename,
return GNUNET_SYSERR;
}
GNUNET_CONFIGURATION_destroy (cfg);
if (0 != strncasecmp (payto_url,
"payto://x-taler-bank/",
strlen ("payto://x-taler-bank/")))
bc->bank_url
= TALER_xtalerbank_base_url_from_payto (payto_url);
if (NULL == bc->bank_url)
{
GNUNET_log_config_invalid
(GNUNET_ERROR_TYPE_WARNING,
config_section,
"URL",
"expected `x-taler-bank' payto://-URL");
GNUNET_CONFIGURATION_destroy (cfg);
GNUNET_free (payto_url);
return GNUNET_SYSERR;
}
start = &payto_url [strlen ("payto://x-taler-bank/")];
end = strchr (start,
(unsigned char) '/');
if (NULL == end)
end = &start[strlen (start)];
fakebank_url = GNUNET_strndup (start,
end - start);
GNUNET_free (payto_url);
if (GNUNET_OK !=
TALER_TESTING_url_port_free (fakebank_url))
TALER_TESTING_url_port_free (bc->bank_url))
{
GNUNET_free (fakebank_url);
GNUNET_free (bc->bank_url);
bc->bank_url = NULL;
GNUNET_free (payto_url);
return GNUNET_SYSERR;
}
bc->bank_url = fakebank_url;
GNUNET_asprintf (&bc->exchange_account_url,
"%s/%s",
bc->bank_url,
EXCHANGE_ACCOUNT_NAME);
bc->exchange_account_url
= TALER_xtalerbank_account_url_from_payto (payto_url);
GNUNET_assert (NULL != bc->exchange_account_url);
GNUNET_free (payto_url);
bc->exchange_auth.method = TALER_BANK_AUTH_NONE;
bc->exchange_payto = TALER_payto_xtalerbank_make (bc->bank_url, "2");
bc->user42_payto = TALER_payto_xtalerbank_make (bc->bank_url, "42");

View File

@ -56,16 +56,16 @@ libtalerutil_la_LDFLAGS = \
-version-info 0:0:0 \
-export-dynamic -no-undefined
TESTS = \
test_amount \
test_crypto \
test_url
check_PROGRAMS = \
test_amount \
test_crypto \
test_payto \
test_url
TESTS = \
$(check_PROGRAMS)
test_amount_SOURCES = \
test_amount.c
@ -79,6 +79,12 @@ test_crypto_LDADD = \
-lgnunetutil \
libtalerutil.la
test_payto_SOURCES = \
test_payto.c
test_payto_LDADD = \
-lgnunetutil \
libtalerutil.la
test_url_SOURCES = \
test_url.c
test_url_LDADD = \

35
src/util/test_payto.c Normal file
View File

@ -0,0 +1,35 @@
/*
This file is part of TALER
(C) 2020 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 util/test_payto.c
* @brief Tests for payto helpers
* @author Christian Grothoff
*/
#include "platform.h"
#include "taler_util.h"
int
main (int argc,
const char *const argv[])
{
return 0;
}
/* end of test_payto.c */

View File

@ -1,6 +1,6 @@
/*
This file is part of TALER
(C) 2015 GNUnet e.V.
(C) 2015-2020 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
@ -45,7 +45,6 @@ int
main (int argc,
const char *const argv[])
{
cf (TALER_urlencode (""), "");
cf (TALER_urlencode ("abc"), "abc");
cf (TALER_urlencode ("~~"), "~~");

View File

@ -805,4 +805,62 @@ TALER_payto_xtalerbank_make (const char *bank_url,
}
/**
* Given an x-taler-bank payto:// URL, compute
* the HTTP(S) base URL of the account.
*
* @param payto the payto URL
* @return bank URL of the account, NULL if not x-taler-bak payto URL
*/
char *
TALER_xtalerbank_base_url_from_payto (const char *payto)
{
const char *start;
const char *end;
if (0 != strncasecmp (payto,
"payto://x-taler-bank/",
strlen ("payto://x-taler-bank/")))
{
return NULL;
}
start = &payto [strlen ("payto://x-taler-bank/")];
end = strchr (start,
(unsigned char) '/');
if (NULL == end)
end = &start[strlen (start)];
return GNUNET_strndup (start,
end - start);
}
/**
* Given an x-taler-bank payto:// URL, compute
* the HTTP(S) base URL of the account.
*
* @param payto the payto URL
* @return bank URL of the account, NULL if not x-taler-bak payto URL
*/
char *
TALER_xtalerbank_account_url_from_payto (const char *payto)
{
const char *start;
const char *end;
if (0 != strncasecmp (payto,
"payto://x-taler-bank/",
strlen ("payto://x-taler-bank/")))
{
return NULL;
}
start = &payto [strlen ("payto://x-taler-bank/")];
end = strchr (start,
(unsigned char) '?');
if (NULL == end)
end = &start[strlen (start)];
return GNUNET_strndup (start,
end - start);
}
/* end of util.c */