exchange/src/testing/test_exchange_api_revocation.c

308 lines
12 KiB
C
Raw Normal View History

2020-01-16 20:20:12 +01:00
/*
This file is part of TALER
Copyright (C) 2014--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 testing/test_exchange_api_revocation.c
2020-01-16 20:20:12 +01:00
* @brief testcase to test key revocation handling via the exchange's HTTP API interface
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
* @author Christian Grothoff
* @author Marcello Stanisci
*/
#include "platform.h"
#include "taler_util.h"
#include "taler_signatures.h"
#include "taler_exchange_service.h"
#include "taler_json_lib.h"
#include <gnunet/gnunet_util_lib.h>
2022-02-07 11:01:54 +01:00
#include <gnunet/gnunet_testing_lib.h>
2020-01-16 20:20:12 +01:00
#include <microhttpd.h>
#include "taler_bank_service.h"
#include "taler_fakebank_lib.h"
#include "taler_testing_lib.h"
/**
* Configuration file we use. One (big) configuration is used
* for the various components for this test.
*/
2022-02-04 18:45:42 +01:00
static char *config_file;
2020-01-16 20:20:12 +01:00
/**
* Exchange configuration data.
*/
static struct TALER_TESTING_ExchangeConfiguration ec;
/**
* Bank configuration data.
*/
static struct TALER_TESTING_BankConfiguration bc;
/**
* Main function that will tell the interpreter what commands to
* run.
*
* @param cls closure
*/
static void
run (void *cls,
struct TALER_TESTING_Interpreter *is)
{
struct TALER_TESTING_Command revocation[] = {
2020-12-11 23:44:01 +01:00
TALER_TESTING_cmd_auditor_add ("add-auditor-OK",
MHD_HTTP_NO_CONTENT,
false),
TALER_TESTING_cmd_wire_add ("add-wire-account",
"payto://x-taler-bank/localhost/2?receiver-name=2",
2020-12-11 23:44:01 +01:00
MHD_HTTP_NO_CONTENT,
false),
TALER_TESTING_cmd_exec_offline_sign_keys ("offline-sign-future-keys",
2022-02-04 18:45:42 +01:00
config_file),
2020-12-11 23:44:01 +01:00
TALER_TESTING_cmd_check_keys_pull_all_keys ("refetch /keys",
1),
2020-01-16 20:20:12 +01:00
/**
* Fill reserve with EUR:10.02, as withdraw fee is 1 ct per
2020-01-16 20:20:12 +01:00
* config.
*/
TALER_TESTING_cmd_admin_add_incoming ("create-reserve-1",
"EUR:10.02",
2020-01-16 20:20:12 +01:00
&bc.exchange_auth,
bc.user42_payto),
TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-reserve-1",
"EUR:10.02",
2020-01-16 20:20:12 +01:00
bc.user42_payto,
bc.exchange_payto,
"create-reserve-1"),
/**
* Run wire-watch to trigger the reserve creation.
*/
TALER_TESTING_cmd_exec_wirewatch ("wirewatch-4",
2022-02-04 18:45:42 +01:00
config_file),
2020-01-16 20:20:12 +01:00
/* Withdraw a 5 EUR coin, at fee of 1 ct */
TALER_TESTING_cmd_withdraw_amount ("withdraw-revocation-coin-1",
"create-reserve-1",
"EUR:5",
[age restriction] progress 14/n - withdraw and deposit Age restriction support for - withdraw is done and tested - deposit is done and tested TODOs: - melt/refresh/reveal - link ------ Added functions - TALER_age_restriction_commit - TALER_age_commitment_derive - TALER_age_commitment_hash - TALER_age_restriction_commitment_free_inside - Hash of age commitment passed around API boundaries Exchangedb adjustments for denominations - all prepared statements re: denominations now handle age_mask - signature parameters adjusted Hash and signature verification of /keys adjusted - Hashes of (normal) denominations and age-restricted denominations are calculated seperately - The hash of the age-restricted ones will then be added to the other hash - The total hash is signed/verified Tests for withdraw with age restriction added - TALER_EXCHANGE_DenomPublickey now carries age_mask - TALER_TESTING_cmd_withdraw_amount* takes age parameter - TALER_TESTING_find_pk takes boolean age_restricted - WithdrawState carries age_commitment and its hash - withdraw_run derives new age commitment, if applicable - Added age parameter to testing (13 as example) Various Fixes and changes - Fixes of post handler for /management/extensions - Fixes for offline tool extensions signing - Slight refactoring of extensions - Age restriction extension simplified - config is now global to extension - added global TEH_age_restriction_enabled and TEH_age_mask in taler-exchange-httpd - helper functions and macros introduced
2022-02-16 22:01:05 +01:00
0, /* age restriction off */
2020-01-16 20:20:12 +01:00
MHD_HTTP_OK),
/* Withdraw another 5 EUR coin, at fee of 1 ct */
TALER_TESTING_cmd_withdraw_amount ("withdraw-revocation-coin-2",
"create-reserve-1",
"EUR:5",
[age restriction] progress 14/n - withdraw and deposit Age restriction support for - withdraw is done and tested - deposit is done and tested TODOs: - melt/refresh/reveal - link ------ Added functions - TALER_age_restriction_commit - TALER_age_commitment_derive - TALER_age_commitment_hash - TALER_age_restriction_commitment_free_inside - Hash of age commitment passed around API boundaries Exchangedb adjustments for denominations - all prepared statements re: denominations now handle age_mask - signature parameters adjusted Hash and signature verification of /keys adjusted - Hashes of (normal) denominations and age-restricted denominations are calculated seperately - The hash of the age-restricted ones will then be added to the other hash - The total hash is signed/verified Tests for withdraw with age restriction added - TALER_EXCHANGE_DenomPublickey now carries age_mask - TALER_TESTING_cmd_withdraw_amount* takes age parameter - TALER_TESTING_find_pk takes boolean age_restricted - WithdrawState carries age_commitment and its hash - withdraw_run derives new age commitment, if applicable - Added age parameter to testing (13 as example) Various Fixes and changes - Fixes of post handler for /management/extensions - Fixes for offline tool extensions signing - Slight refactoring of extensions - Age restriction extension simplified - config is now global to extension - added global TEH_age_restriction_enabled and TEH_age_mask in taler-exchange-httpd - helper functions and macros introduced
2022-02-16 22:01:05 +01:00
0, /* age restriction off */
MHD_HTTP_OK),
2020-01-16 20:20:12 +01:00
/* Try to partially spend (deposit) 1 EUR of the 5 EUR coin (in full)
* (merchant would receive EUR:0.99 due to 1 ct deposit fee) *///
TALER_TESTING_cmd_deposit ("deposit-partial",
"withdraw-revocation-coin-1",
0,
bc.user42_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":\"EUR:1\"}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:1",
MHD_HTTP_OK),
/* Deposit another coin in full */
TALER_TESTING_cmd_deposit ("deposit-full",
"withdraw-revocation-coin-2",
0,
bc.user42_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":\"EUR:5\"}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:5",
MHD_HTTP_OK),
2020-01-16 20:20:12 +01:00
/**
* Melt SOME of the rest of the coin's value
2021-11-01 22:57:46 +01:00
* (EUR:3.17 = 3x EUR:1.03 + 7x EUR:0.13)
*/
TALER_TESTING_cmd_melt ("refresh-melt-1",
"withdraw-revocation-coin-1",
MHD_HTTP_OK,
NULL),
2020-01-16 20:20:12 +01:00
/**
* Complete (successful) melt operation, and withdraw the coins
*/
TALER_TESTING_cmd_refresh_reveal ("refresh-reveal-1",
"refresh-melt-1",
MHD_HTTP_OK),
/* Try to recoup before it's allowed */
TALER_TESTING_cmd_recoup_refresh ("recoup-not-allowed",
MHD_HTTP_GONE,
"refresh-reveal-1#0",
"refresh-melt-1",
"EUR:0.1"),
2020-01-16 20:20:12 +01:00
/* Make refreshed coin invalid */
TALER_TESTING_cmd_revoke ("revoke-2-EUR:5",
MHD_HTTP_OK,
"refresh-melt-1",
2022-02-04 18:45:42 +01:00
config_file),
/* Also make fully spent coin invalid (should be same denom) */
TALER_TESTING_cmd_revoke ("revoke-2-EUR:5",
MHD_HTTP_OK,
"withdraw-revocation-coin-2",
2022-02-04 18:45:42 +01:00
config_file),
/* Refund fully spent coin (which should fail) */
TALER_TESTING_cmd_recoup ("recoup-fully-spent",
MHD_HTTP_CONFLICT,
"withdraw-revocation-coin-2",
2021-12-16 20:18:44 +01:00
"EUR:0.1"),
2020-01-16 20:20:12 +01:00
/* Refund coin to original coin */
TALER_TESTING_cmd_recoup_refresh ("recoup-1a",
MHD_HTTP_OK,
"refresh-reveal-1#0",
"refresh-melt-1",
"EUR:1"),
TALER_TESTING_cmd_recoup_refresh ("recoup-1b",
MHD_HTTP_OK,
"refresh-reveal-1#1",
"refresh-melt-1",
"EUR:1"),
TALER_TESTING_cmd_recoup_refresh ("recoup-1c",
MHD_HTTP_OK,
"refresh-reveal-1#2",
"refresh-melt-1",
"EUR:1"),
/* Repeat recoup to test idempotency */
TALER_TESTING_cmd_recoup_refresh ("recoup-1c",
MHD_HTTP_OK,
"refresh-reveal-1#2",
"refresh-melt-1",
"EUR:1"),
TALER_TESTING_cmd_recoup_refresh ("recoup-1c",
MHD_HTTP_OK,
"refresh-reveal-1#2",
"refresh-melt-1",
"EUR:1"),
TALER_TESTING_cmd_recoup_refresh ("recoup-1c",
MHD_HTTP_OK,
"refresh-reveal-1#2",
"refresh-melt-1",
"EUR:1"),
TALER_TESTING_cmd_recoup_refresh ("recoup-1c",
MHD_HTTP_OK,
"refresh-reveal-1#2",
"refresh-melt-1",
"EUR:1"),
2020-01-18 23:49:37 +01:00
/* Now we have EUR:3.83 EUR back after 3x EUR:1 in recoups */
2020-01-16 20:20:12 +01:00
/* Melt original coin AGAIN, but only create one 0.1 EUR coin;
This costs EUR:0.03 in refresh and EUR:01 in withdraw fees,
leaving EUR:3.69. */
TALER_TESTING_cmd_melt ("refresh-melt-2",
"withdraw-revocation-coin-1",
MHD_HTTP_OK,
"EUR:0.1",
NULL),
2020-01-16 20:20:12 +01:00
/**
* Complete (successful) melt operation, and withdraw the coins
*/
TALER_TESTING_cmd_refresh_reveal ("refresh-reveal-2",
"refresh-melt-2",
MHD_HTTP_OK),
/* Revokes refreshed EUR:0.1 coin */
TALER_TESTING_cmd_revoke ("revoke-3-EUR:0.1",
MHD_HTTP_OK,
"refresh-reveal-2",
2022-02-04 18:45:42 +01:00
config_file),
2020-01-16 20:20:12 +01:00
/* Revoke also original coin denomination */
TALER_TESTING_cmd_revoke ("revoke-4-EUR:5",
MHD_HTTP_OK,
"withdraw-revocation-coin-1",
2022-02-04 18:45:42 +01:00
config_file),
2020-01-16 20:20:12 +01:00
/* Refund coin EUR:0.1 to original coin, creating zombie! */
TALER_TESTING_cmd_recoup_refresh ("recoup-2",
MHD_HTTP_OK,
"refresh-reveal-2",
"refresh-melt-2",
"EUR:0.1"),
2020-01-18 23:49:37 +01:00
/* Due to recoup, original coin is now at EUR:3.79 */
2020-01-16 20:20:12 +01:00
/* Refund original (now zombie) coin to reserve */
2020-01-18 23:49:37 +01:00
TALER_TESTING_cmd_recoup ("recoup-3",
MHD_HTTP_OK,
"withdraw-revocation-coin-1",
2020-03-28 20:45:53 +01:00
"EUR:3.79"),
2020-01-16 20:20:12 +01:00
/* Check the money is back with the reserve */
2020-01-18 23:49:37 +01:00
TALER_TESTING_cmd_status ("recoup-reserve-status-1",
2020-01-16 20:20:12 +01:00
"create-reserve-1",
"EUR:3.79",
MHD_HTTP_OK),
TALER_TESTING_cmd_end ()
};
2021-11-19 20:56:53 +01:00
(void) cls;
2020-01-16 20:20:12 +01:00
TALER_TESTING_run_with_fakebank (is,
revocation,
2020-01-18 04:00:35 +01:00
bc.exchange_auth.wire_gateway_url);
2020-01-16 20:20:12 +01:00
}
int
main (int argc,
char *const *argv)
{
2022-02-09 09:25:32 +01:00
char *cipher;
2022-02-04 18:45:42 +01:00
2021-11-19 20:56:53 +01:00
(void) argc;
2020-01-16 20:20:12 +01:00
/* These environment variables get in the way... */
unsetenv ("XDG_DATA_HOME");
unsetenv ("XDG_CONFIG_HOME");
2022-02-04 18:45:42 +01:00
GNUNET_log_setup (argv[0],
2020-01-16 20:20:12 +01:00
"INFO",
NULL);
2022-02-04 18:45:42 +01:00
cipher = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
GNUNET_assert (NULL != cipher);
GNUNET_asprintf (&config_file,
"test_exchange_api-%s.conf",
cipher);
2022-02-09 09:25:32 +01:00
GNUNET_free (cipher);
2020-01-16 20:20:12 +01:00
/* Check fakebank port is available and get config */
if (GNUNET_OK !=
2022-02-04 18:45:42 +01:00
TALER_TESTING_prepare_fakebank (config_file,
2020-01-19 18:48:14 +01:00
"exchange-account-2",
2020-01-16 20:20:12 +01:00
&bc))
return 77;
2022-02-04 18:45:42 +01:00
TALER_TESTING_cleanup_files (config_file);
2020-01-16 20:20:12 +01:00
/* @helpers. Run keyup, create tables, ... Note: it
* fetches the port number from config in order to see
* if it's available. */
2022-02-04 18:45:42 +01:00
switch (TALER_TESTING_prepare_exchange (config_file,
GNUNET_YES,
2020-01-16 20:20:12 +01:00
&ec))
{
case GNUNET_SYSERR:
GNUNET_break (0);
return 1;
case GNUNET_NO:
return 77;
case GNUNET_OK:
if (GNUNET_OK !=
/* Set up event loop and reschedule context, plus
* start/stop the exchange. It calls TALER_TESTING_setup
* which creates the 'is' object.
*/
TALER_TESTING_setup_with_exchange (&run,
NULL,
2022-02-04 18:45:42 +01:00
config_file))
2020-01-16 20:20:12 +01:00
return 1;
break;
default:
GNUNET_break (0);
return 1;
}
return 0;
}
/* end of test_exchange_api_revocation.c */