refactor uri parsing logic, prepare for unit test
This commit is contained in:
parent
cba9f8614e
commit
2edee5ac4a
@ -270,7 +270,7 @@ TALER_BANK_credit_history (struct GNUNET_CURL_Context *ctx,
|
|||||||
hh->bank_base_url = GNUNET_strdup (bank_base_url);
|
hh->bank_base_url = GNUNET_strdup (bank_base_url);
|
||||||
hh->request_url = TALER_BANK_path_to_url_ (bank_base_url,
|
hh->request_url = TALER_BANK_path_to_url_ (bank_base_url,
|
||||||
url);
|
url);
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||||
"Requesting history at `%s'\n",
|
"Requesting history at `%s'\n",
|
||||||
hh->request_url);
|
hh->request_url);
|
||||||
eh = curl_easy_init ();
|
eh = curl_easy_init ();
|
||||||
|
@ -273,7 +273,7 @@ TALER_BANK_debit_history (struct GNUNET_CURL_Context *ctx,
|
|||||||
hh->request_url = TALER_BANK_path_to_url_ (bank_base_url,
|
hh->request_url = TALER_BANK_path_to_url_ (bank_base_url,
|
||||||
url);
|
url);
|
||||||
|
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||||
"Requesting history at `%s'\n",
|
"Requesting history at `%s'\n",
|
||||||
hh->request_url);
|
hh->request_url);
|
||||||
eh = curl_easy_init ();
|
eh = curl_easy_init ();
|
||||||
|
@ -1111,7 +1111,7 @@ serve (struct TALER_FAKEBANK_Handle *h,
|
|||||||
size_t *upload_data_size,
|
size_t *upload_data_size,
|
||||||
void **con_cls)
|
void **con_cls)
|
||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||||
"Fakebank, serving URL `%s' for account `%s'\n",
|
"Fakebank, serving URL `%s' for account `%s'\n",
|
||||||
url,
|
url,
|
||||||
account);
|
account);
|
||||||
@ -1198,6 +1198,9 @@ handle_mhd_request (void *cls,
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
(void) version;
|
(void) version;
|
||||||
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||||
|
"Handling request for `%s'\n",
|
||||||
|
url);
|
||||||
if ( (strlen (url) > 1) &&
|
if ( (strlen (url) > 1) &&
|
||||||
(NULL != (end = strchr (url + 1, '/'))) )
|
(NULL != (end = strchr (url + 1, '/'))) )
|
||||||
{
|
{
|
||||||
|
@ -765,7 +765,7 @@ create_denomkey_issue (const struct CoinTypeParams *params,
|
|||||||
GNUNET_assert (NULL != dki->denom_priv.rsa_private_key);
|
GNUNET_assert (NULL != dki->denom_priv.rsa_private_key);
|
||||||
dki->denom_pub.rsa_public_key
|
dki->denom_pub.rsa_public_key
|
||||||
= GNUNET_CRYPTO_rsa_private_key_get_public (
|
= 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,
|
GNUNET_CRYPTO_rsa_public_key_hash (dki->denom_pub.rsa_public_key,
|
||||||
&dki->issue.properties.denom_hash);
|
&dki->issue.properties.denom_hash);
|
||||||
dki->issue.properties.master = master_public_key;
|
dki->issue.properties.master = master_public_key;
|
||||||
|
@ -771,9 +771,9 @@ handle_refresh_reveal_json (struct MHD_Connection *connection,
|
|||||||
{
|
{
|
||||||
rctx->ev_sigs[i].rsa_signature
|
rctx->ev_sigs[i].rsa_signature
|
||||||
= GNUNET_CRYPTO_rsa_sign_blinded (
|
= GNUNET_CRYPTO_rsa_sign_blinded (
|
||||||
rctx->dkis[i]->denom_priv.rsa_private_key,
|
rctx->dkis[i]->denom_priv.rsa_private_key,
|
||||||
rctx->rcds[i].coin_ev,
|
rctx->rcds[i].coin_ev,
|
||||||
rctx->rcds[i].coin_ev_size);
|
rctx->rcds[i].coin_ev_size);
|
||||||
if (NULL == rctx->ev_sigs[i].rsa_signature)
|
if (NULL == rctx->ev_sigs[i].rsa_signature)
|
||||||
{
|
{
|
||||||
GNUNET_break (0);
|
GNUNET_break (0);
|
||||||
|
@ -403,4 +403,27 @@ char *
|
|||||||
TALER_payto_xtalerbank_make (const char *bank_url,
|
TALER_payto_xtalerbank_make (const char *bank_url,
|
||||||
const char *account_name);
|
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
|
#endif
|
||||||
|
@ -1262,7 +1262,7 @@ keys_completed_cb (void *cls,
|
|||||||
for (unsigned int i = 0; i<kd_old.num_denom_keys; i++)
|
for (unsigned int i = 0; i<kd_old.num_denom_keys; i++)
|
||||||
kd.denom_keys[i].key.rsa_public_key
|
kd.denom_keys[i].key.rsa_public_key
|
||||||
= GNUNET_CRYPTO_rsa_public_key_dup (
|
= 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.num_auditors = kd_old.num_auditors;
|
||||||
kd.auditors = GNUNET_new_array (kd.num_auditors,
|
kd.auditors = GNUNET_new_array (kd.num_auditors,
|
||||||
|
@ -374,9 +374,6 @@ TALER_TESTING_prepare_fakebank (const char *config_filename,
|
|||||||
{
|
{
|
||||||
struct GNUNET_CONFIGURATION_Handle *cfg;
|
struct GNUNET_CONFIGURATION_Handle *cfg;
|
||||||
char *payto_url;
|
char *payto_url;
|
||||||
char *fakebank_url;
|
|
||||||
const char *start;
|
|
||||||
const char *end;
|
|
||||||
|
|
||||||
cfg = GNUNET_CONFIGURATION_create ();
|
cfg = GNUNET_CONFIGURATION_create ();
|
||||||
if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg,
|
if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg,
|
||||||
@ -395,38 +392,30 @@ TALER_TESTING_prepare_fakebank (const char *config_filename,
|
|||||||
return GNUNET_SYSERR;
|
return GNUNET_SYSERR;
|
||||||
}
|
}
|
||||||
GNUNET_CONFIGURATION_destroy (cfg);
|
GNUNET_CONFIGURATION_destroy (cfg);
|
||||||
if (0 != strncasecmp (payto_url,
|
bc->bank_url
|
||||||
"payto://x-taler-bank/",
|
= TALER_xtalerbank_base_url_from_payto (payto_url);
|
||||||
strlen ("payto://x-taler-bank/")))
|
if (NULL == bc->bank_url)
|
||||||
{
|
{
|
||||||
GNUNET_log_config_invalid
|
GNUNET_log_config_invalid
|
||||||
(GNUNET_ERROR_TYPE_WARNING,
|
(GNUNET_ERROR_TYPE_WARNING,
|
||||||
config_section,
|
config_section,
|
||||||
"URL",
|
"URL",
|
||||||
"expected `x-taler-bank' payto://-URL");
|
"expected `x-taler-bank' payto://-URL");
|
||||||
GNUNET_CONFIGURATION_destroy (cfg);
|
|
||||||
GNUNET_free (payto_url);
|
GNUNET_free (payto_url);
|
||||||
return GNUNET_SYSERR;
|
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 !=
|
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;
|
return GNUNET_SYSERR;
|
||||||
}
|
}
|
||||||
bc->bank_url = fakebank_url;
|
bc->exchange_account_url
|
||||||
GNUNET_asprintf (&bc->exchange_account_url,
|
= TALER_xtalerbank_account_url_from_payto (payto_url);
|
||||||
"%s/%s",
|
GNUNET_assert (NULL != bc->exchange_account_url);
|
||||||
bc->bank_url,
|
GNUNET_free (payto_url);
|
||||||
EXCHANGE_ACCOUNT_NAME);
|
|
||||||
bc->exchange_auth.method = TALER_BANK_AUTH_NONE;
|
bc->exchange_auth.method = TALER_BANK_AUTH_NONE;
|
||||||
bc->exchange_payto = TALER_payto_xtalerbank_make (bc->bank_url, "2");
|
bc->exchange_payto = TALER_payto_xtalerbank_make (bc->bank_url, "2");
|
||||||
bc->user42_payto = TALER_payto_xtalerbank_make (bc->bank_url, "42");
|
bc->user42_payto = TALER_payto_xtalerbank_make (bc->bank_url, "42");
|
||||||
|
@ -56,16 +56,16 @@ libtalerutil_la_LDFLAGS = \
|
|||||||
-version-info 0:0:0 \
|
-version-info 0:0:0 \
|
||||||
-export-dynamic -no-undefined
|
-export-dynamic -no-undefined
|
||||||
|
|
||||||
TESTS = \
|
|
||||||
test_amount \
|
|
||||||
test_crypto \
|
|
||||||
test_url
|
|
||||||
|
|
||||||
check_PROGRAMS = \
|
check_PROGRAMS = \
|
||||||
test_amount \
|
test_amount \
|
||||||
test_crypto \
|
test_crypto \
|
||||||
|
test_payto \
|
||||||
test_url
|
test_url
|
||||||
|
|
||||||
|
TESTS = \
|
||||||
|
$(check_PROGRAMS)
|
||||||
|
|
||||||
|
|
||||||
test_amount_SOURCES = \
|
test_amount_SOURCES = \
|
||||||
test_amount.c
|
test_amount.c
|
||||||
@ -79,6 +79,12 @@ test_crypto_LDADD = \
|
|||||||
-lgnunetutil \
|
-lgnunetutil \
|
||||||
libtalerutil.la
|
libtalerutil.la
|
||||||
|
|
||||||
|
test_payto_SOURCES = \
|
||||||
|
test_payto.c
|
||||||
|
test_payto_LDADD = \
|
||||||
|
-lgnunetutil \
|
||||||
|
libtalerutil.la
|
||||||
|
|
||||||
test_url_SOURCES = \
|
test_url_SOURCES = \
|
||||||
test_url.c
|
test_url.c
|
||||||
test_url_LDADD = \
|
test_url_LDADD = \
|
||||||
|
35
src/util/test_payto.c
Normal file
35
src/util/test_payto.c
Normal 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 */
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
This file is part of TALER
|
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
|
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
|
terms of the GNU General Public License as published by the Free Software
|
||||||
@ -45,7 +45,6 @@ int
|
|||||||
main (int argc,
|
main (int argc,
|
||||||
const char *const argv[])
|
const char *const argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
cf (TALER_urlencode (""), "");
|
cf (TALER_urlencode (""), "");
|
||||||
cf (TALER_urlencode ("abc"), "abc");
|
cf (TALER_urlencode ("abc"), "abc");
|
||||||
cf (TALER_urlencode ("~~"), "~~");
|
cf (TALER_urlencode ("~~"), "~~");
|
||||||
|
@ -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 */
|
/* end of util.c */
|
||||||
|
Loading…
Reference in New Issue
Block a user