anastasis

Credential backup and recovery protocol and service
Log | Files | Refs | Submodules | README | LICENSE

test_anastasis.c (17040B)


      1 /*
      2   This file is part of Anastasis
      3   Copyright (C) 2020-2023 Anastasis SARL
      4 
      5   Anastasis is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU General Public License as published by the Free Software
      7   Foundation; either version 3, or (at your option) any later version.
      8 
      9   Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY
     10   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12 
     13   You should have received a copy of the GNU General Public License along with
     14   Anastasis; see the file COPYING.GPL.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 /**
     17  * @file testing/test_anastasis.c
     18  * @brief testcase to test anastasis
     19  * @author Christian Grothoff
     20  * @author Dennis Neufeld
     21  * @author Dominik Meister
     22  */
     23 #include "platform.h"
     24 #include "anastasis_testing_lib.h"
     25 #include <taler/taler_merchant_testing_lib.h>
     26 
     27 
     28 /**
     29  * Configuration file we use.  One (big) configuration is used
     30  * for the various components for this test.
     31  */
     32 #define CONFIG_FILE "test_anastasis_api.conf"
     33 
     34 /**
     35  * Exchange base URL.  Could also be taken from config.
     36  */
     37 #define EXCHANGE_URL "http://localhost:8081/"
     38 
     39 /**
     40  * IBAN of the account the merchant is paid into.  Unlike the accounts of
     41  * the payer and of the exchange, this one need not exist at the bank: the
     42  * test never runs the aggregator, so nothing is ever transferred to it.
     43  */
     44 #define MERCHANT_ACCOUNT_IBAN "DE89370400440532013000"
     45 
     46 /**
     47  * Credentials for the test.  The bank accounts of the payer
     48  * (@e user42_payto) and of the exchange (@e exchange_payto) are the ones
     49  * `taler-unified-setup.sh' registers at libeufin-bank.
     50  */
     51 static struct TALER_TESTING_Credentials cred;
     52 
     53 /**
     54  * Payto URI of the merchant (receiver).
     55  */
     56 static struct TALER_FullPayto merchant_payto;
     57 
     58 /**
     59  * Merchant base URL.
     60  */
     61 static const char *merchant_url;
     62 
     63 /**
     64  * Anastasis base URL.
     65  */
     66 static char *anastasis_url;
     67 
     68 /**
     69  * Name of the file for exchanging the secret.
     70  */
     71 static char *file_secret;
     72 
     73 /**
     74  * Anastasis process.
     75  */
     76 static struct GNUNET_Process *anastasisd;
     77 
     78 /**
     79  * Identity to use for testing.
     80  */
     81 static json_t *id_data;
     82 
     83 
     84 /**
     85  * Execute the taler-exchange-wirewatch command with
     86  * our configuration file.
     87  *
     88  * @param label label to use for the command.
     89  */
     90 static struct TALER_TESTING_Command
     91 cmd_exec_wirewatch (const char *label)
     92 {
     93   return TALER_TESTING_cmd_exec_wirewatch (label,
     94                                            CONFIG_FILE);
     95 }
     96 
     97 
     98 /**
     99  * Run wire transfer of funds from some user's account to the
    100  * exchange.
    101  *
    102  * @param label label to use for the command.
    103  * @param amount amount to transfer, i.e. "EUR:1"
    104  * @param url exchange_url
    105  */
    106 static struct TALER_TESTING_Command
    107 cmd_transfer_to_exchange (const char *label,
    108                           const char *amount)
    109 {
    110   return TALER_TESTING_cmd_admin_add_incoming (label,
    111                                                amount,
    112                                                &cred.ba_admin,
    113                                                cred.user42_payto);
    114 }
    115 
    116 
    117 /**
    118  * Main function that will tell the interpreter what commands to
    119  * run.
    120  *
    121  * @param cls closure
    122  */
    123 static void
    124 run (void *cls,
    125      struct TALER_TESTING_Interpreter *is)
    126 {
    127   struct TALER_TESTING_Command pay[] = {
    128     /**
    129      * Move money to the exchange's bank account.
    130      */
    131     cmd_transfer_to_exchange ("create-reserve-1",
    132                               "EUR:10.02"),
    133     /**
    134      * Make a reserve exist, according to the previous
    135      * transfer.
    136      */
    137     cmd_exec_wirewatch ("wirewatch-1"),
    138     TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-1",
    139                                        "create-reserve-1",
    140                                        "EUR:5",
    141                                        0, /* age */
    142                                        MHD_HTTP_OK),
    143     TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-2",
    144                                        "create-reserve-1",
    145                                        "EUR:5",
    146                                        0, /* age */
    147                                        MHD_HTTP_OK),
    148     /**
    149      * Check the reserve is depleted.
    150      */
    151     TALER_TESTING_cmd_status ("withdraw-status-1",
    152                               "create-reserve-1",
    153                               "EUR:0",
    154                               MHD_HTTP_OK),
    155     TALER_TESTING_cmd_end ()
    156   };
    157 
    158   struct TALER_TESTING_Command anastasis[] = {
    159     ANASTASIS_TESTING_cmd_config ("salt-request-1",
    160                                   anastasis_url,
    161                                   MHD_HTTP_OK),
    162     ANASTASIS_TESTING_cmd_truth_upload_question ("truth-create-1",
    163                                                  anastasis_url,
    164                                                  id_data,
    165                                                  "answer the question",
    166                                                  "text/plain",
    167                                                  "SomeTruth1",
    168                                                  MHD_HTTP_NO_CONTENT,
    169                                                  ANASTASIS_TESTING_TSO_NONE,
    170                                                  "salt-request-1"),
    171     ANASTASIS_TESTING_cmd_truth_upload_question ("truth-create-2",
    172                                                  anastasis_url,
    173                                                  id_data,
    174                                                  "answer the question",
    175                                                  "text/plain",
    176                                                  "SomeTruth2",
    177                                                  MHD_HTTP_NO_CONTENT,
    178                                                  ANASTASIS_TESTING_TSO_NONE,
    179                                                  "salt-request-1"),
    180     ANASTASIS_TESTING_cmd_truth_upload ("truth-create-3",
    181                                         anastasis_url,
    182                                         id_data,
    183                                         "file",
    184                                         "read the file",
    185                                         "text/plain",
    186                                         file_secret,
    187                                         strlen (file_secret),
    188                                         MHD_HTTP_NO_CONTENT,
    189                                         ANASTASIS_TESTING_TSO_NONE,
    190                                         "salt-request-1"),
    191     ANASTASIS_TESTING_cmd_policy_create ("policy-create-1",
    192                                          "truth-create-1",
    193                                          "truth-create-2",
    194                                          NULL),
    195     ANASTASIS_TESTING_cmd_policy_create ("policy-create-2",
    196                                          "truth-create-1",
    197                                          "truth-create-3",
    198                                          NULL),
    199     ANASTASIS_TESTING_cmd_policy_create ("policy-create-3",
    200                                          "truth-create-2",
    201                                          "truth-create-3",
    202                                          NULL),
    203     ANASTASIS_TESTING_cmd_secret_share ("secret-share-1",
    204                                         anastasis_url,
    205                                         "salt-request-1",
    206                                         NULL,
    207                                         id_data,
    208                                         "core secret",
    209                                         strlen ("core secret"),
    210                                         ANASTASIS_SHARE_STATUS_PAYMENT_REQUIRED,
    211                                         ANASTASIS_TESTING_SSO_NONE,
    212                                         "policy-create-1",
    213                                         "policy-create-2",
    214                                         "policy-create-3",
    215                                         NULL),
    216     /* what would we have to pay? */
    217     TALER_TESTING_cmd_merchant_claim_order ("fetch-proposal",
    218                                             merchant_url,
    219                                             MHD_HTTP_OK,
    220                                             "secret-share-1",
    221                                             NULL),
    222     /* make the payment */
    223     TALER_TESTING_cmd_merchant_pay_order ("pay-account",
    224                                           merchant_url,
    225                                           MHD_HTTP_OK,
    226                                           "fetch-proposal",
    227                                           "withdraw-coin-1",
    228                                           "EUR:5",
    229                                           "EUR:4.99", /* must match ANNUAL_FEE in config! */
    230                                           NULL),
    231     ANASTASIS_TESTING_cmd_secret_share ("secret-share-2",
    232                                         anastasis_url,
    233                                         "salt-request-1",
    234                                         "secret-share-1",
    235                                         id_data,
    236                                         "core secret",
    237                                         strlen ("core secret"),
    238                                         ANASTASIS_SHARE_STATUS_SUCCESS,
    239                                         ANASTASIS_TESTING_SSO_NONE,
    240                                         "policy-create-1",
    241                                         "policy-create-2",
    242                                         "policy-create-3",
    243                                         NULL),
    244     ANASTASIS_TESTING_cmd_recover_secret ("recover-secret-1",
    245                                           anastasis_url,
    246                                           id_data,
    247                                           0, /* version */
    248                                           ANASTASIS_TESTING_RSO_NONE,
    249                                           "salt-request-1",
    250                                           "secret-share-2"),
    251     ANASTASIS_TESTING_cmd_challenge_answer ("challenge-answer-1",
    252                                             NULL, /* payment ref */
    253                                             "recover-secret-1", /* challenge ref */
    254                                             0, /* challenge index */
    255                                             "SomeTruth1",
    256                                             0,  /* mode */
    257                                             ANASTASIS_CHALLENGE_ANSWER_STATUS_SOLVED),
    258 #if 0
    259     ANASTASIS_TESTING_cmd_challenge_answer ("challenge-answer-2",
    260                                             NULL, /* payment ref */
    261                                             "recover-secret-1",
    262                                             1, /* challenge index */
    263                                             "SomeTruth2",
    264                                             0, /* mode */
    265                                             ANASTASIS_CHALLENGE_ANSWER_STATUS_SOLVED),
    266 #endif
    267     ANASTASIS_TESTING_cmd_challenge_start ("challenge-start-3-pay",
    268                                            NULL,  /* payment ref */
    269                                            "recover-secret-1",
    270                                            2,  /* challenge index */
    271                                            ANASTASIS_CHALLENGE_START_STATUS_PAYMENT_REQUIRED),
    272     TALER_TESTING_cmd_merchant_claim_order ("fetch-challenge-pay-proposal",
    273                                             merchant_url,
    274                                             MHD_HTTP_OK,
    275                                             "challenge-start-3-pay",
    276                                             NULL),
    277     TALER_TESTING_cmd_merchant_pay_order ("pay-file-challenge",
    278                                           merchant_url,
    279                                           MHD_HTTP_OK,
    280                                           "fetch-challenge-pay-proposal",
    281                                           "withdraw-coin-2",
    282                                           "EUR:1",
    283                                           "EUR:1", /* must match COST in config! */
    284                                           NULL),
    285     ANASTASIS_TESTING_cmd_challenge_start ("challenge-start-3-paid",
    286                                            "challenge-start-3-pay",  /* payment ref */
    287                                            "recover-secret-1",
    288                                            2,  /* challenge index */
    289                                            ANASTASIS_CHALLENGE_START_STATUS_FILENAME_PROVIDED),
    290     ANASTASIS_TESTING_cmd_challenge_answer ("challenge-answer-3",
    291                                             "challenge-start-3-pay", /* payment ref */
    292                                             "recover-secret-1",
    293                                             2, /* challenge index */
    294                                             "challenge-start-3-paid", /* answer */
    295                                             1, /* mode */
    296                                             ANASTASIS_CHALLENGE_ANSWER_STATUS_SOLVED),
    297     ANASTASIS_TESTING_cmd_recover_secret_finish ("recover-finish-1",
    298                                                  "recover-secret-1",
    299                                                  GNUNET_TIME_UNIT_SECONDS),
    300     TALER_TESTING_cmd_end ()
    301   };
    302 
    303   struct TALER_TESTING_Command commands[] = {
    304     /* general setup */
    305     TALER_TESTING_cmd_system_start ("start-taler",
    306                                     CONFIG_FILE,
    307                                     "-bem",
    308                                     "-d", "iban",
    309                                     "-u", "exchange-account-exchange",
    310                                     NULL),
    311     TALER_TESTING_cmd_get_exchange ("get-exchange",
    312                                     cred.cfg,
    313                                     NULL,
    314                                     true,
    315                                     true),
    316     /* Not TALER_TESTING_cmd_merchant_post_instances(): that one gives the
    317        instance a pay delay of two seconds, and the orders here are created
    318        by anastasis-httpd, not by the test, so a slow order creation would
    319        expire the offer before the test gets to pay it. */
    320     TALER_TESTING_cmd_merchant_post_instances2 ("instance-create-admin",
    321                                                 merchant_url,
    322                                                 "admin",
    323                                                 "admin",
    324                                                 json_pack ("{s:s}",
    325                                                            "city",
    326                                                            "shopcity"),
    327                                                 json_pack ("{s:s}",
    328                                                            "city",
    329                                                            "lawyercity"),
    330                                                 true, /* use STEFAN */
    331                                                 GNUNET_TIME_UNIT_ZERO,
    332                                                 GNUNET_TIME_UNIT_MINUTES,
    333                                                 NULL, /* auth token */
    334                                                 MHD_HTTP_NO_CONTENT),
    335     TALER_TESTING_cmd_merchant_post_account (
    336       "instance-create-default-account",
    337       merchant_url,
    338       merchant_payto,
    339       NULL, NULL,
    340       MHD_HTTP_OK),
    341     TALER_TESTING_cmd_batch ("pay",
    342                              pay),
    343     TALER_TESTING_cmd_batch ("anastasis",
    344                              anastasis),
    345     TALER_TESTING_cmd_end ()
    346   };
    347 
    348   TALER_TESTING_run (is,
    349                      commands);
    350 }
    351 
    352 
    353 int
    354 main (int argc,
    355       char *const *argv)
    356 {
    357   int ret;
    358   file_secret = ANASTASIS_TESTING_make_file_challenge_name (CONFIG_FILE);
    359   if (NULL == file_secret)
    360     return 77;
    361   id_data = ANASTASIS_TESTING_make_id_data_example ("MaxMuster123456789");
    362   merchant_payto.full_payto =
    363     (char *) "payto://iban/SANDBOXX/" MERCHANT_ACCOUNT_IBAN
    364     "?receiver-name=merchant";
    365   merchant_url = "http://localhost:8080/";
    366 
    367   if (NULL ==
    368       (anastasis_url = ANASTASIS_TESTING_prepare_anastasis (CONFIG_FILE)))
    369     return 77;
    370   if (NULL == (anastasisd =
    371                  ANASTASIS_TESTING_run_anastasis (CONFIG_FILE,
    372                                                   anastasis_url)))
    373   {
    374     GNUNET_break (0);
    375     return 1;
    376   }
    377   ret = TALER_TESTING_main (argv,
    378                             "INFO",
    379                             CONFIG_FILE,
    380                             "exchange-account-exchange",
    381                             TALER_TESTING_BS_IBAN,
    382                             &cred,
    383                             &run,
    384                             NULL);
    385   GNUNET_break (GNUNET_OK ==
    386                 GNUNET_process_kill (anastasisd,
    387                                      SIGTERM));
    388   GNUNET_break (GNUNET_OK ==
    389                 GNUNET_process_wait (anastasisd,
    390                                      true,
    391                                      NULL,
    392                                      NULL));
    393   GNUNET_process_destroy (anastasisd);
    394   GNUNET_free (anastasis_url);
    395   return ret;
    396 }
    397 
    398 
    399 /* end of test_anastasis.c */