diff options
Diffstat (limited to 'src/bank-lib')
-rw-r--r-- | src/bank-lib/Makefile.am | 4 | ||||
-rw-r--r-- | src/bank-lib/bank.conf | 5 | ||||
-rw-r--r-- | src/bank-lib/bank_api_history.c | 12 | ||||
-rw-r--r-- | src/bank-lib/bank_api_parse.c | 133 | ||||
-rw-r--r-- | src/bank-lib/test_bank_api_with_fakebank_new.c | 5 | ||||
-rw-r--r-- | src/bank-lib/test_bank_interpreter.c | 40 | ||||
-rw-r--r-- | src/bank-lib/testing_api_cmd_history.c | 47 | ||||
-rw-r--r-- | src/bank-lib/testing_api_cmd_reject.c | 4 |
8 files changed, 182 insertions, 68 deletions
diff --git a/src/bank-lib/Makefile.am b/src/bank-lib/Makefile.am index abe820a64..9f2740b24 100644 --- a/src/bank-lib/Makefile.am +++ b/src/bank-lib/Makefile.am @@ -32,7 +32,8 @@ libtalerbank_la_SOURCES = \ bank_api_admin.c \ bank_api_common.c bank_api_common.h \ bank_api_history.c \ - bank_api_reject.c + bank_api_reject.c \ + bank_api_parse.c libtalerbank_la_LIBADD = \ $(top_builddir)/src/json/libtalerjson.la \ @@ -148,6 +149,7 @@ test_bank_api_new_SOURCES = \ test_bank_api_new_LDADD = \ $(top_builddir)/src/exchange-lib/libtalertesting.la \ + $(top_builddir)/src/json/libtalerjson.la \ libtalerbanktesting.la \ -ltalerexchange \ -lgnunetutil \ diff --git a/src/bank-lib/bank.conf b/src/bank-lib/bank.conf index f6e4e7fe0..9befeba9e 100644 --- a/src/bank-lib/bank.conf +++ b/src/bank-lib/bank.conf @@ -1,8 +1,11 @@ [taler] currency = KUDOS +[account-1] +URL = payto://x-taler-bank/localhost:8081/1 + [bank] -http_port = 8081 +HTTP_PORT = 8081 [exchange-wire-test] bank_url = http://localhost:8081/ diff --git a/src/bank-lib/bank_api_history.c b/src/bank-lib/bank_api_history.c index d2035e881..17cd9fd07 100644 --- a/src/bank-lib/bank_api_history.c +++ b/src/bank-lib/bank_api_history.c @@ -136,10 +136,12 @@ parse_account_history (struct TALER_BANK_HistoryHandle *hh, GNUNET_JSON_parse_free (hist_spec); return GNUNET_SYSERR; } - td.account_details = json_pack ("{s:s, s:s, s:I}", - "type", "test", - "bank_url", hh->bank_base_url, - "account_number", (json_int_t) other_account); + GNUNET_asprintf (&td.account_url, + ('/' == hh->bank_base_url[strlen(hh->bank_base_url)-1]) + ? "payto://x-taler-bank/%s%llu" + : "payto://x-taler-bank/%s/%llu", + hh->bank_base_url, + (unsigned long long) other_account); hh->hcb (hh->hcb_cls, MHD_HTTP_OK, TALER_EC_NONE, @@ -147,7 +149,7 @@ parse_account_history (struct TALER_BANK_HistoryHandle *hh, row_id, &td, transaction); - json_decref (td.account_details); + GNUNET_free (td.account_url); GNUNET_JSON_parse_free (hist_spec); } return GNUNET_OK; diff --git a/src/bank-lib/bank_api_parse.c b/src/bank-lib/bank_api_parse.c new file mode 100644 index 000000000..04cf7b85f --- /dev/null +++ b/src/bank-lib/bank_api_parse.c @@ -0,0 +1,133 @@ +/* + 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/> +*/ +/** + * @file bank-lib/bank_api_parse.c + * @brief Convenience function to parse authentication configuration + * @author Christian Grothoff + */ +#include "platform.h" +#include "taler_bank_service.h" + + +/** + * Parse configuration section with bank authentication data. + * + * @param cfg configuration to parse + * @param section the section with the configuration data + * @param auth[out] set to the configuration data found + * @return #GNUNET_OK on success + */ +int +TALER_BANK_auth_parse_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section, + struct TALER_BANK_AuthenticationData *auth) +{ + const struct { + const char *m; + enum TALER_BANK_AuthenticationMethod e; + } methods[] = { + { "NONE", TALER_BANK_AUTH_NONE }, + { "BASIC", TALER_BANK_AUTH_BASIC }, + { NULL, TALER_BANK_AUTH_NONE } + }; + char *method; + + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (cfg, + section, + "TALER_BANK_AUTH_METHOD", + &method)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + section, + "TALER_BANK_AUTH_METHOD"); + return GNUNET_SYSERR; + } + for (unsigned int i=0; NULL != methods[i].m;i++) + { + if (0 == strcasecmp (method, + methods[i].m)) + { + switch (methods[i].e) + { + case TALER_BANK_AUTH_NONE: + auth->method = TALER_BANK_AUTH_NONE; + return GNUNET_OK; + case TALER_BANK_AUTH_BASIC: + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (cfg, + section, + "USERNAME", + &auth->details.basic.username)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + section, + "USERNAME"); + return GNUNET_SYSERR; + } + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (cfg, + section, + "PASSWORD", + &auth->details.basic.password)) + { + GNUNET_free (auth->details.basic.username); + auth->details.basic.username = NULL; + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + section, + "USERNAME"); + return GNUNET_SYSERR; + } + auth->method = TALER_BANK_AUTH_BASIC; + return GNUNET_OK; + } + } + } + return GNUNET_SYSERR; +} + + +/** + * Free memory inside of @a auth (but not auth itself). + * Dual to #TALER_BANK_auth_parse_cfg(). + * + * @param auth authentication data to free + */ +void +TALER_BANK_auth_free (struct TALER_BANK_AuthenticationData *auth) +{ + switch (auth->method) + { + case TALER_BANK_AUTH_NONE: + break; + case TALER_BANK_AUTH_BASIC: + if (NULL != auth->details.basic.username) + { + GNUNET_free (auth->details.basic.username); + auth->details.basic.username = NULL; + } + if (NULL != auth->details.basic.password) + { + GNUNET_free (auth->details.basic.password); + auth->details.basic.password = NULL; + } + break; + } +} + + +/* end of bank_api_parse.c */ diff --git a/src/bank-lib/test_bank_api_with_fakebank_new.c b/src/bank-lib/test_bank_api_with_fakebank_new.c index 1a70f5714..002010b29 100644 --- a/src/bank-lib/test_bank_api_with_fakebank_new.c +++ b/src/bank-lib/test_bank_api_with_fakebank_new.c @@ -210,9 +210,10 @@ main (int argc, "DEBUG", NULL); if (NULL == - (fakebank_url = TALER_TESTING_prepare_fakebank (CONFIG_FILE))) + (fakebank_url = TALER_TESTING_prepare_fakebank (CONFIG_FILE, + "account-1"))) return 77; - + return (GNUNET_OK == TALER_TESTING_setup (&run, NULL, CONFIG_FILE, diff --git a/src/bank-lib/test_bank_interpreter.c b/src/bank-lib/test_bank_interpreter.c index 40adea54f..e503bd8dc 100644 --- a/src/bank-lib/test_bank_interpreter.c +++ b/src/bank-lib/test_bank_interpreter.c @@ -326,15 +326,10 @@ build_history (struct InterpreterState *is, h[total].direction = TALER_BANK_DIRECTION_CREDIT; if (GNUNET_YES == cancelled) h[total].direction |= TALER_BANK_DIRECTION_CANCEL; - h[total].details.account_details - = json_pack ("{s:s, s:s, s:I}", - "type", - "test", - "bank_url", - "http://localhost:8080", - "account_number", - (json_int_t) pos->details.admin_add_incoming.debit_account_no); - GNUNET_assert (NULL != h[total].details.account_details); + GNUNET_asprintf (&h[total].details.account_url, + "payto://x-taler-bank/%s/%llu", + "http://localhost:8080", + (unsigned long long) pos->details.admin_add_incoming.debit_account_no); } if ( (0 != (cmd->details.history.direction & TALER_BANK_DIRECTION_DEBIT)) && (cmd->details.history.account_number == @@ -343,15 +338,10 @@ build_history (struct InterpreterState *is, h[total].direction = TALER_BANK_DIRECTION_DEBIT; if (GNUNET_YES == cancelled) h[total].direction |= TALER_BANK_DIRECTION_CANCEL; - h[total].details.account_details - = json_pack ("{s:s, s:s, s:I}", - "type", - "test", - "bank_url", - "http://localhost:8080", - "account_number", - (json_int_t) pos->details.admin_add_incoming.credit_account_no); - GNUNET_assert (NULL != h[total].details.account_details); + GNUNET_asprintf (&h[total].details.account_url, + "payto://x-taler-bank/%s/%llu", + "http://localhost:8080", + (unsigned long long) pos->details.admin_add_incoming.credit_account_no); } if ( ( (0 != (cmd->details.history.direction & TALER_BANK_DIRECTION_CREDIT)) && (cmd->details.history.account_number == @@ -398,10 +388,6 @@ print_expected (struct History *h, "Expected history:\n"); for (uint64_t i=0;i<h_len;i++) { - char *acc; - - acc = json_dumps (h[i].details.account_details, - JSON_COMPACT); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "H(%llu): %s%s (serial: %llu, subject: %s, to: %s)\n", (unsigned long long) i, @@ -409,9 +395,7 @@ print_expected (struct History *h, TALER_amount2s (&h[i].details.amount), (unsigned long long) h[i].row_id, h[i].details.wire_transfer_subject, - acc); - if (NULL != acc) - free (acc); + h[i].details.account_url); } } @@ -429,7 +413,7 @@ free_history (struct History *h, for (uint64_t off = 0;off<h_len;off++) { GNUNET_free (h[off].details.wire_transfer_subject); - json_decref (h[off].details.account_details); + GNUNET_free (h[off].details.account_url); } GNUNET_free_non_null (h); } @@ -500,8 +484,8 @@ check_result (struct InterpreterState *is, details->wire_transfer_subject)) || (0 != TALER_amount_cmp (&h[off].details.amount, &details->amount)) || - (1 != json_equal (h[off].details.account_details, - details->account_details)) ) + (0 != strcasecmp (h[off].details.account_url, + details->account_url)) ) { GNUNET_break (0); print_expected (h, total, off); diff --git a/src/bank-lib/testing_api_cmd_history.c b/src/bank-lib/testing_api_cmd_history.c index 30090bf8c..e94009fb3 100644 --- a/src/bank-lib/testing_api_cmd_history.c +++ b/src/bank-lib/testing_api_cmd_history.c @@ -99,6 +99,7 @@ history_traits (void *cls, return GNUNET_SYSERR; } + /** * Test if the /admin/add/incoming transaction at offset @a off * has been /rejected. @@ -115,7 +116,8 @@ test_cancelled (struct TALER_TESTING_Interpreter *is, const struct TALER_TESTING_Command *current_cmd; current_cmd = &is->commands[off]; - TALER_LOG_INFO ("Is `%s' rejected?\n", current_cmd->label); + TALER_LOG_INFO ("Is `%s' rejected?\n", + current_cmd->label); for (unsigned int i=0;i<is->ip;i++) { const struct TALER_TESTING_Command *c = &is->commands[i]; @@ -140,6 +142,7 @@ test_cancelled (struct TALER_TESTING_Interpreter *is, return GNUNET_NO; } + /** * Free history @a h of length @a h_len. * @@ -153,11 +156,12 @@ free_history (struct History *h, for (uint64_t off = 0;off<h_len;off++) { GNUNET_free (h[off].details.wire_transfer_subject); - json_decref (h[off].details.account_details); + GNUNET_free (h[off].details.account_url); } GNUNET_free_non_null (h); } + /** * Log which history we expected. * @@ -178,10 +182,6 @@ print_expected (struct History *h, "Expected history:\n"); for (uint64_t i=0;i<h_len;i++) { - char *acc; - - acc = json_dumps (h[i].details.account_details, - JSON_COMPACT); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "H(%llu): %s%s (serial: %llu, subject: %s, to: %s)\n", (unsigned long long) i, @@ -189,12 +189,11 @@ print_expected (struct History *h, TALER_amount2s (&h[i].details.amount), (unsigned long long) h[i].row_id, h[i].details.wire_transfer_subject, - acc); - if (NULL != acc) - free (acc); + h[i].details.account_url); } } + /** * Build history of transactions matching the current * command in @a is. @@ -409,15 +408,10 @@ build_history (struct TALER_TESTING_Interpreter *is, h[total].direction = TALER_BANK_DIRECTION_CREDIT; if (GNUNET_YES == cancelled) h[total].direction |= TALER_BANK_DIRECTION_CANCEL; - h[total].details.account_details - = json_pack ("{s:s, s:s, s:I}", - "type", - "test", - "bank_url", - hs->bank_url, - "account_number", - (json_int_t) *debit_account_no); - GNUNET_assert (NULL != h[total].details.account_details); + GNUNET_asprintf (&h[total].details.account_url, + "payto://x-taler-bank/%s/%llu", + hs->bank_url, + (unsigned long long) *debit_account_no); } if ( (0 != (hs->direction & TALER_BANK_DIRECTION_DEBIT)) && (hs->account_no == *debit_account_no)) @@ -425,15 +419,10 @@ build_history (struct TALER_TESTING_Interpreter *is, h[total].direction = TALER_BANK_DIRECTION_DEBIT; if (GNUNET_YES == cancelled) h[total].direction |= TALER_BANK_DIRECTION_CANCEL; - h[total].details.account_details - = json_pack ("{s:s, s:s, s:I}", - "type", - "test", - "bank_url", - hs->bank_url, - "account_number", - (json_int_t) *credit_account_no); - GNUNET_assert (NULL != h[total].details.account_details); + GNUNET_asprintf (&h[total].details.account_url, + "payto://x-taler-bank/%s/%llu", + hs->bank_url, + (unsigned long long) *credit_account_no); } if ( ( (0 != (hs->direction & TALER_BANK_DIRECTION_CREDIT)) && (hs->account_no == *credit_account_no)) || @@ -533,8 +522,8 @@ check_result (struct TALER_TESTING_Interpreter *is, details->wire_transfer_subject)) || (0 != TALER_amount_cmp (&h[off].details.amount, &details->amount)) || - (1 != json_equal (h[off].details.account_details, - details->account_details)) ) + (0 != strcasecmp (h[off].details.account_url, + details->account_url)) ) { GNUNET_break (0); print_expected (h, total, off); diff --git a/src/bank-lib/testing_api_cmd_reject.c b/src/bank-lib/testing_api_cmd_reject.c index c01c27d87..2eb6d4f9b 100644 --- a/src/bank-lib/testing_api_cmd_reject.c +++ b/src/bank-lib/testing_api_cmd_reject.c @@ -127,7 +127,7 @@ reject_run (void *cls, (GNUNET_OK == TALER_TESTING_GET_TRAIT_ROW_ID (deposit_cmd, &row_id)); TALER_LOG_INFO ("Account %llu rejects deposit\n", - *credit_account); + (unsigned long long) *credit_account); rs->rh = TALER_BANK_reject (is->ctx, rs->bank_url, &AUTHS[*credit_account -1], @@ -180,7 +180,7 @@ TALER_TESTING_cmd_bank_reject (const char *label, rs = GNUNET_new (struct RejectState); rs->bank_url = bank_url; rs->deposit_reference = deposit_reference; - + cmd.cls = rs; cmd.run = &reject_run; cmd.cleanup = &reject_cleanup; |