2018-02-22 14:51:12 +01:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
|
|
|
Copyright (C) 2016, 2017 GNUnet e.V.
|
|
|
|
|
|
|
|
TALER is free software; you can redistribute it and/or modify
|
2019-09-11 00:32:07 +02:00
|
|
|
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.
|
2018-02-22 14:51:12 +01:00
|
|
|
|
2019-09-11 00:32:07 +02:00
|
|
|
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.
|
2018-02-22 14:51:12 +01:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public
|
|
|
|
License along with TALER; see the file COPYING. If not,
|
2019-06-08 21:41:12 +02:00
|
|
|
see <http://www.gnu.org/licenses/>
|
2018-02-22 14:51:12 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2019-12-14 23:14:59 +01:00
|
|
|
* @file bank/test_bank_api_new.c
|
2018-02-22 14:51:12 +01:00
|
|
|
* @brief testcase to test bank's HTTP API
|
2019-09-11 00:32:07 +02:00
|
|
|
* interface against the fakebank
|
2018-02-22 14:51:12 +01:00
|
|
|
* @author Marcello Stanisci
|
2019-09-11 00:32:07 +02:00
|
|
|
* @author Christian Grothoff
|
2018-02-22 14:51:12 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "platform.h"
|
|
|
|
#include "taler_util.h"
|
|
|
|
#include "taler_signatures.h"
|
|
|
|
#include "taler_bank_service.h"
|
2019-09-11 00:32:07 +02:00
|
|
|
#include "taler_exchange_service.h"
|
2018-02-22 14:51:12 +01:00
|
|
|
#include <gnunet/gnunet_util_lib.h>
|
|
|
|
#include <gnunet/gnunet_curl_lib.h>
|
|
|
|
#include <microhttpd.h>
|
|
|
|
#include "test_bank_interpreter.h"
|
|
|
|
#include "taler_testing_lib.h"
|
|
|
|
#include "taler_testing_bank_lib.h"
|
|
|
|
|
2019-09-11 00:32:07 +02:00
|
|
|
|
2018-02-22 14:51:12 +01:00
|
|
|
#define CONFIG_FILE "bank.conf"
|
|
|
|
|
2019-04-09 18:12:11 +02:00
|
|
|
/**
|
2019-09-11 00:32:07 +02:00
|
|
|
* Fakebank URL.
|
2019-04-09 18:12:11 +02:00
|
|
|
*/
|
2019-09-11 00:32:07 +02:00
|
|
|
static char *bank_url;
|
|
|
|
|
2018-02-22 14:51:12 +01:00
|
|
|
/**
|
2019-09-11 00:32:07 +02:00
|
|
|
* Handle to the Py-bank daemon.
|
2018-02-22 14:51:12 +01:00
|
|
|
*/
|
2019-09-11 00:32:07 +02:00
|
|
|
static struct GNUNET_OS_Process *bankd;
|
2018-02-22 14:51:12 +01:00
|
|
|
|
|
|
|
/**
|
2019-09-11 00:32:07 +02:00
|
|
|
* Flag indicating whether the test is running against the
|
|
|
|
* Fakebank. Set up at runtime.
|
2018-02-22 14:51:12 +01:00
|
|
|
*/
|
2019-09-11 00:32:07 +02:00
|
|
|
static int WITH_FAKEBANK;
|
2019-06-08 21:41:12 +02:00
|
|
|
|
2019-10-05 15:42:08 +02:00
|
|
|
/**
|
|
|
|
* Transfer @a amount from @a src account to @a dst using
|
|
|
|
* @a subject and the @a label for the command.
|
|
|
|
*/
|
|
|
|
#define TRANSFER(label,amount,src,dst,subject) \
|
|
|
|
TALER_TESTING_cmd_fakebank_transfer_with_subject (label, \
|
|
|
|
amount, \
|
|
|
|
bank_url, \
|
|
|
|
src, \
|
|
|
|
dst, \
|
|
|
|
AUTHS[src \
|
|
|
|
- 1].details.basic. \
|
|
|
|
username, \
|
|
|
|
AUTHS[src \
|
|
|
|
- 1].details.basic. \
|
|
|
|
password, \
|
|
|
|
subject, \
|
|
|
|
"http://exchange.net/")
|
|
|
|
|
|
|
|
|
2018-02-22 14:51:12 +01:00
|
|
|
/**
|
|
|
|
* Main function that will tell the interpreter what commands to
|
|
|
|
* run.
|
|
|
|
*
|
|
|
|
* @param cls closure
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
run (void *cls,
|
|
|
|
struct TALER_TESTING_Interpreter *is)
|
|
|
|
{
|
2019-09-11 00:32:07 +02:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
|
|
|
"Bank serves at `%s'\n",
|
|
|
|
bank_url);
|
2018-02-22 14:51:12 +01:00
|
|
|
extern struct TALER_BANK_AuthenticationData AUTHS[];
|
|
|
|
struct TALER_TESTING_Command commands[] = {
|
|
|
|
TALER_TESTING_cmd_bank_history ("history-0",
|
|
|
|
bank_url,
|
2019-09-11 00:32:07 +02:00
|
|
|
BANK_ACCOUNT_NUMBER,
|
2018-02-22 14:51:12 +01:00
|
|
|
TALER_BANK_DIRECTION_BOTH,
|
2019-09-11 00:32:07 +02:00
|
|
|
GNUNET_YES,
|
|
|
|
NULL,
|
|
|
|
1),
|
|
|
|
/* WARNING: old API has expected http response code among
|
|
|
|
* the parameters, although it was always set as '200 OK' */
|
2019-10-05 15:42:08 +02:00
|
|
|
TRANSFER ("debit-1",
|
|
|
|
"KUDOS:5.01",
|
|
|
|
EXCHANGE_ACCOUNT_NUMBER,
|
|
|
|
BANK_ACCOUNT_NUMBER,
|
|
|
|
"subject 1"),
|
2018-02-22 14:51:12 +01:00
|
|
|
TALER_TESTING_cmd_bank_history ("history-1c",
|
|
|
|
bank_url,
|
2019-09-11 00:32:07 +02:00
|
|
|
BANK_ACCOUNT_NUMBER,
|
2018-02-22 14:51:12 +01:00
|
|
|
TALER_BANK_DIRECTION_CREDIT,
|
2019-03-21 18:47:35 +01:00
|
|
|
GNUNET_YES,
|
2018-02-22 14:51:12 +01:00
|
|
|
NULL,
|
2019-03-21 18:47:35 +01:00
|
|
|
5),
|
2018-02-22 14:51:12 +01:00
|
|
|
TALER_TESTING_cmd_bank_history ("history-1d",
|
|
|
|
bank_url,
|
2019-09-11 00:32:07 +02:00
|
|
|
BANK_ACCOUNT_NUMBER,
|
2018-02-22 14:51:12 +01:00
|
|
|
TALER_BANK_DIRECTION_DEBIT,
|
2019-03-21 18:47:35 +01:00
|
|
|
GNUNET_YES,
|
2018-02-22 14:51:12 +01:00
|
|
|
NULL,
|
|
|
|
5),
|
2019-10-05 15:42:08 +02:00
|
|
|
TRANSFER ("debit-2",
|
|
|
|
"KUDOS:3.21",
|
|
|
|
EXCHANGE_ACCOUNT_NUMBER,
|
|
|
|
USER_ACCOUNT_NUMBER,
|
|
|
|
"subject 2"),
|
|
|
|
TRANSFER ("credit-2",
|
|
|
|
"KUDOS:3.22",
|
|
|
|
USER_ACCOUNT_NUMBER,
|
|
|
|
EXCHANGE_ACCOUNT_NUMBER,
|
|
|
|
"credit 2"),
|
2019-09-11 00:32:07 +02:00
|
|
|
TALER_TESTING_cmd_bank_history ("history-2b",
|
2018-02-22 14:51:12 +01:00
|
|
|
bank_url,
|
|
|
|
EXCHANGE_ACCOUNT_NUMBER,
|
2019-09-11 00:32:07 +02:00
|
|
|
TALER_BANK_DIRECTION_BOTH,
|
2019-03-21 18:47:35 +01:00
|
|
|
GNUNET_YES,
|
2018-02-22 14:51:12 +01:00
|
|
|
NULL,
|
2019-03-21 18:47:35 +01:00
|
|
|
5),
|
2019-09-11 00:32:07 +02:00
|
|
|
TALER_TESTING_cmd_bank_history ("history-2bi",
|
2018-02-22 14:51:12 +01:00
|
|
|
bank_url,
|
|
|
|
EXCHANGE_ACCOUNT_NUMBER,
|
2019-09-11 00:32:07 +02:00
|
|
|
TALER_BANK_DIRECTION_BOTH,
|
2019-03-21 18:47:35 +01:00
|
|
|
GNUNET_YES,
|
2019-09-11 00:32:07 +02:00
|
|
|
"debit-1",
|
2018-02-22 14:51:12 +01:00
|
|
|
5),
|
2019-10-05 15:42:08 +02:00
|
|
|
TRANSFER ("credit-for-reject-1",
|
|
|
|
"KUDOS:1.01",
|
|
|
|
BANK_ACCOUNT_NUMBER,
|
|
|
|
EXCHANGE_ACCOUNT_NUMBER,
|
|
|
|
"subject 3"),
|
2018-02-22 14:51:12 +01:00
|
|
|
TALER_TESTING_cmd_bank_reject ("reject-1",
|
|
|
|
bank_url,
|
2019-09-11 00:32:07 +02:00
|
|
|
"credit-for-reject-1"),
|
|
|
|
TALER_TESTING_cmd_bank_history ("history-r1",
|
|
|
|
bank_url,
|
|
|
|
BANK_ACCOUNT_NUMBER,
|
|
|
|
TALER_BANK_DIRECTION_BOTH,
|
|
|
|
GNUNET_YES,
|
|
|
|
NULL,
|
|
|
|
5),
|
|
|
|
TALER_TESTING_cmd_bank_history ("history-r1c",
|
|
|
|
bank_url,
|
|
|
|
BANK_ACCOUNT_NUMBER,
|
|
|
|
TALER_BANK_DIRECTION_BOTH
|
|
|
|
| TALER_BANK_DIRECTION_CANCEL,
|
|
|
|
GNUNET_YES,
|
|
|
|
NULL,
|
|
|
|
5),
|
2018-02-22 14:51:12 +01:00
|
|
|
TALER_TESTING_cmd_end ()
|
|
|
|
};
|
|
|
|
|
2019-09-11 00:32:07 +02:00
|
|
|
if (GNUNET_YES == WITH_FAKEBANK)
|
|
|
|
TALER_TESTING_run_with_fakebank (is,
|
|
|
|
commands,
|
|
|
|
bank_url);
|
|
|
|
else
|
|
|
|
TALER_TESTING_run (is,
|
|
|
|
commands);
|
2018-02-22 14:51:12 +01:00
|
|
|
}
|
|
|
|
|
2019-10-31 12:59:50 +01:00
|
|
|
|
2018-02-22 14:51:12 +01:00
|
|
|
int
|
2019-08-25 16:18:24 +02:00
|
|
|
main (int argc,
|
|
|
|
char *const *argv)
|
2018-02-22 14:51:12 +01:00
|
|
|
{
|
2019-09-11 00:32:07 +02:00
|
|
|
int rv;
|
2019-12-14 23:14:59 +01:00
|
|
|
|
2018-02-22 14:51:12 +01:00
|
|
|
/* These environment variables get in the way... */
|
|
|
|
unsetenv ("XDG_DATA_HOME");
|
|
|
|
unsetenv ("XDG_CONFIG_HOME");
|
2019-09-11 00:32:07 +02:00
|
|
|
GNUNET_log_setup ("test-bank-api-with-(fake)bank-new",
|
|
|
|
"DEBUG",
|
|
|
|
NULL);
|
2018-02-22 14:51:12 +01:00
|
|
|
|
2019-09-11 00:32:07 +02:00
|
|
|
WITH_FAKEBANK = TALER_TESTING_has_in_name (argv[0],
|
|
|
|
"_with_fakebank");
|
|
|
|
if (GNUNET_YES == WITH_FAKEBANK)
|
|
|
|
{
|
|
|
|
TALER_LOG_DEBUG ("Running against the Fakebank.\n");
|
2019-10-05 15:42:08 +02:00
|
|
|
if (NULL == (bank_url = TALER_TESTING_prepare_fakebank (CONFIG_FILE,
|
|
|
|
"account-1")))
|
2019-09-11 00:32:07 +02:00
|
|
|
{
|
|
|
|
GNUNET_break (0);
|
|
|
|
return 77;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TALER_LOG_DEBUG ("Running against the Pybank.\n");
|
2019-10-05 15:42:08 +02:00
|
|
|
if (NULL == (bank_url = TALER_TESTING_prepare_bank (CONFIG_FILE)))
|
2019-09-11 00:32:07 +02:00
|
|
|
{
|
|
|
|
GNUNET_break (0);
|
|
|
|
return 77;
|
|
|
|
}
|
2018-02-22 14:51:12 +01:00
|
|
|
|
2019-10-05 15:42:08 +02:00
|
|
|
if (NULL == (bankd = TALER_TESTING_run_bank (CONFIG_FILE,
|
|
|
|
bank_url)))
|
2019-09-11 00:32:07 +02:00
|
|
|
{
|
|
|
|
GNUNET_break (0);
|
|
|
|
return 77;
|
|
|
|
}
|
|
|
|
}
|
2019-06-08 21:41:12 +02:00
|
|
|
|
2019-09-11 00:32:07 +02:00
|
|
|
rv = (GNUNET_OK == TALER_TESTING_setup (&run,
|
|
|
|
NULL,
|
|
|
|
CONFIG_FILE,
|
|
|
|
NULL,
|
|
|
|
GNUNET_NO)) ? 0 : 1;
|
|
|
|
if (GNUNET_NO == WITH_FAKEBANK)
|
|
|
|
{
|
2018-02-22 14:51:12 +01:00
|
|
|
|
2019-09-11 00:32:07 +02:00
|
|
|
GNUNET_OS_process_kill (bankd,
|
|
|
|
SIGKILL);
|
|
|
|
GNUNET_OS_process_wait (bankd);
|
|
|
|
GNUNET_OS_process_destroy (bankd);
|
|
|
|
GNUNET_free (bank_url);
|
|
|
|
}
|
2019-10-05 15:42:08 +02:00
|
|
|
|
2019-09-11 00:32:07 +02:00
|
|
|
return rv;
|
2018-02-22 14:51:12 +01:00
|
|
|
}
|
|
|
|
|
2019-09-11 00:32:07 +02:00
|
|
|
|
2019-12-14 23:14:59 +01:00
|
|
|
/* end of test_bank_api_new.c */
|