exchange/src/bank-lib/test_bank_api_new.c

263 lines
7.9 KiB
C
Raw Normal View History

/*
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.
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.
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/>
*/
/**
2019-09-11 00:32:07 +02:00
* @file bank/test_bank_api_with_fakebank.c
* @brief testcase to test bank's HTTP API
2019-09-11 00:32:07 +02:00
* interface against the fakebank
* @author Marcello Stanisci
2019-09-11 00:32:07 +02:00
* @author Christian Grothoff
*/
#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"
#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
#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;
/**
2019-09-11 00:32:07 +02:00
* Handle to the Py-bank daemon.
*/
2019-09-11 00:32:07 +02:00
static struct GNUNET_OS_Process *bankd;
/**
2019-09-11 00:32:07 +02:00
* Flag indicating whether the test is running against the
* Fakebank. Set up at runtime.
*/
2019-09-11 00:32:07 +02:00
static int WITH_FAKEBANK;
2019-06-08 21:41:12 +02: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);
extern struct TALER_BANK_AuthenticationData AUTHS[];
2019-09-11 00:32:07 +02:00
struct TALER_TESTING_Command commands[] = {
2019-09-11 00:32:07 +02:00
TALER_TESTING_cmd_bank_history ("history-0",
bank_url,
2019-09-11 00:32:07 +02:00
BANK_ACCOUNT_NUMBER,
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' */
TALER_TESTING_cmd_fakebank_transfer_with_subject
2019-09-11 00:32:07 +02:00
("debit-1",
"KUDOS:5.01",
bank_url,
EXCHANGE_ACCOUNT_NUMBER,
BANK_ACCOUNT_NUMBER,
AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.username,
AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.password,
"subject 1",
"http://exchange.com/"),
TALER_TESTING_cmd_bank_history ("history-1c",
bank_url,
2019-09-11 00:32:07 +02:00
BANK_ACCOUNT_NUMBER,
TALER_BANK_DIRECTION_CREDIT,
GNUNET_YES,
NULL,
5),
2019-09-11 00:32:07 +02:00
TALER_TESTING_cmd_bank_history ("history-1d",
bank_url,
2019-09-11 00:32:07 +02:00
BANK_ACCOUNT_NUMBER,
TALER_BANK_DIRECTION_DEBIT,
GNUNET_YES,
NULL,
5),
2019-09-11 00:32:07 +02:00
TALER_TESTING_cmd_fakebank_transfer_with_subject
("debit-2",
"KUDOS:3.21",
bank_url,
EXCHANGE_ACCOUNT_NUMBER, // debit account.
USER_ACCOUNT_NUMBER,
AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.username,
AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.password,
"subject 2",
"http://exchange.org/"),
TALER_TESTING_cmd_fakebank_transfer_with_subject
("credit-2",
"KUDOS:3.22",
bank_url,
USER_ACCOUNT_NUMBER, // debit account.
EXCHANGE_ACCOUNT_NUMBER,
AUTHS[USER_ACCOUNT_NUMBER - 1].details.basic.username,
AUTHS[USER_ACCOUNT_NUMBER - 1].details.basic.password,
"credit 2",
"http://exchange.org/"),
TALER_TESTING_cmd_bank_history ("history-2b",
bank_url,
EXCHANGE_ACCOUNT_NUMBER,
2019-09-11 00:32:07 +02:00
TALER_BANK_DIRECTION_BOTH,
GNUNET_YES,
NULL,
5),
2019-09-11 00:32:07 +02:00
TALER_TESTING_cmd_bank_history ("history-2bi",
bank_url,
EXCHANGE_ACCOUNT_NUMBER,
2019-09-11 00:32:07 +02:00
TALER_BANK_DIRECTION_BOTH,
GNUNET_YES,
2019-09-11 00:32:07 +02:00
"debit-1",
5),
2019-09-11 00:32:07 +02:00
TALER_TESTING_cmd_fakebank_transfer_with_subject
("credit-for-reject-1",
"KUDOS:1.01",
bank_url,
BANK_ACCOUNT_NUMBER,
EXCHANGE_ACCOUNT_NUMBER,
AUTHS[BANK_ACCOUNT_NUMBER - 1].details.basic.username,
AUTHS[BANK_ACCOUNT_NUMBER - 1].details.basic.password,
"subject 3",
"http://exchange.net/"),
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),
/**
* End the suite. Fixme: better to have a label for this
* too, as it shows a "(null)" token on logs.
*/
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);
}
int
2019-08-25 16:18:24 +02:00
main (int argc,
char *const *argv)
{
2019-09-11 00:32:07 +02:00
int rv;
/* 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);
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");
if (NULL == (bank_url = TALER_TESTING_prepare_fakebank
(CONFIG_FILE,
"account-1")))
{
GNUNET_break (0);
return 77;
}
}
else
{
TALER_LOG_DEBUG ("Running against the Pybank.\n");
if (NULL == (bank_url = TALER_TESTING_prepare_bank
(CONFIG_FILE)))
{
GNUNET_break (0);
return 77;
}
2019-09-11 00:32:07 +02:00
if (NULL == (bankd = TALER_TESTING_run_bank
(CONFIG_FILE,
bank_url)))
{
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)
{
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);
}
return rv;
}
2019-09-11 00:32:07 +02:00
/* end of test_bank_api_with_fakebank_new.c */