anastasis

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

test_anastasis_api.c (12515B)


      1 /*
      2   This file is part of Anastasis
      3   Copyright (C) 2020, 2021 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_api.c
     18  * @brief testcase to test anastasis' HTTP API interface
     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  * Test credentials.  The bank accounts of the payer (@e user42_payto) and
     48  * 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  * Anastasis process.
     70  */
     71 static struct GNUNET_Process *anastasisd;
     72 
     73 /**
     74  * Name of the file for exchanging the secret.
     75  */
     76 static char *file_secret;
     77 
     78 /**
     79  * Execute the taler-exchange-wirewatch command with our configuration
     80  * file.
     81  *
     82  * @param label label to use for the command.
     83  */
     84 static struct TALER_TESTING_Command
     85 cmd_exec_wirewatch (const char *label)
     86 {
     87   return TALER_TESTING_cmd_exec_wirewatch (label,
     88                                            CONFIG_FILE);
     89 }
     90 
     91 
     92 /**
     93  * Run wire transfer of funds from some user's account to the
     94  * exchange.
     95  *
     96  * @param label label to use for the command.
     97  * @param amount amount to transfer, i.e. "EUR:1"
     98  * @param url exchange_url
     99  */
    100 static struct TALER_TESTING_Command
    101 cmd_transfer_to_exchange (const char *label,
    102                           const char *amount)
    103 {
    104   return TALER_TESTING_cmd_admin_add_incoming (label,
    105                                                amount,
    106                                                &cred.ba_admin,
    107                                                cred.user42_payto);
    108 }
    109 
    110 
    111 /**
    112  * Main function that will tell the interpreter what commands to run.
    113  *
    114  * @param cls closure
    115  */
    116 static void
    117 run (void *cls,
    118      struct TALER_TESTING_Interpreter *is)
    119 {
    120   struct TALER_TESTING_Command withdraw[] = {
    121     cmd_transfer_to_exchange ("create-reserve-1",
    122                               "EUR:10.02"),
    123     cmd_exec_wirewatch ("wirewatch-1"),
    124     TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-1",
    125                                        "create-reserve-1",
    126                                        "EUR:5",
    127                                        0, /* age */
    128                                        MHD_HTTP_OK),
    129     TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-2",
    130                                        "create-reserve-1",
    131                                        "EUR:5",
    132                                        0, /* age */
    133                                        MHD_HTTP_OK),
    134     TALER_TESTING_cmd_status ("withdraw-status-1",
    135                               "create-reserve-1",
    136                               "EUR:0",
    137                               MHD_HTTP_OK),
    138     TALER_TESTING_cmd_end ()
    139   };
    140 
    141   struct TALER_TESTING_Command policy[] = {
    142     ANASTASIS_TESTING_cmd_policy_store ("policy-store-1",
    143                                         anastasis_url,
    144                                         NULL /* prev upload */,
    145                                         MHD_HTTP_PAYMENT_REQUIRED,
    146                                         ANASTASIS_TESTING_PSO_NONE,
    147                                         "Test-1",
    148                                         strlen ("Test-1")),
    149     /* what would we have to pay? */
    150     TALER_TESTING_cmd_merchant_claim_order ("fetch-proposal",
    151                                             merchant_url,
    152                                             MHD_HTTP_OK,
    153                                             "policy-store-1",
    154                                             NULL),
    155     /* make the payment */
    156     TALER_TESTING_cmd_merchant_pay_order ("pay-account",
    157                                           merchant_url,
    158                                           MHD_HTTP_OK,
    159                                           "fetch-proposal",
    160                                           "withdraw-coin-1",
    161                                           "EUR:5",
    162                                           "EUR:4.99", /* must match ANNUAL_FEE in config! */
    163                                           NULL),
    164     ANASTASIS_TESTING_cmd_policy_store ("policy-store-2",
    165                                         anastasis_url,
    166                                         "policy-store-1",
    167                                         MHD_HTTP_NO_CONTENT,
    168                                         ANASTASIS_TESTING_PSO_NONE,
    169                                         "Test-1",
    170                                         strlen ("Test-1")),
    171     ANASTASIS_TESTING_cmd_policy_lookup ("policy-lookup-1",
    172                                          anastasis_url,
    173                                          MHD_HTTP_OK,
    174                                          "policy-store-2"),
    175     TALER_TESTING_cmd_end ()
    176   };
    177 
    178   struct TALER_TESTING_Command truth[] = {
    179     ANASTASIS_TESTING_cmd_truth_question (
    180       "truth-store-1",
    181       anastasis_url,
    182       NULL,
    183       "The-Answer",
    184       ANASTASIS_TESTING_TSO_NONE,
    185       MHD_HTTP_NO_CONTENT),
    186     ANASTASIS_TESTING_cmd_truth_solve (
    187       "keyshare-lookup-1",
    188       anastasis_url,
    189       "The-Answer",
    190       NULL, /* payment ref */
    191       "truth-store-1",
    192       0,
    193       MHD_HTTP_OK),
    194     ANASTASIS_TESTING_cmd_truth_store (
    195       "truth-store-2",
    196       anastasis_url,
    197       NULL,
    198       "file",
    199       "text/plain",
    200       strlen (file_secret),
    201       file_secret,
    202       ANASTASIS_TESTING_TSO_NONE,
    203       MHD_HTTP_NO_CONTENT),
    204     ANASTASIS_TESTING_cmd_truth_solve (
    205       "challenge-fail-1",
    206       anastasis_url,
    207       "Wrong-Answer",
    208       NULL, /* payment ref */
    209       "truth-store-1", /* upload ref */
    210       0, /* security question mode */
    211       MHD_HTTP_FORBIDDEN),
    212     ANASTASIS_TESTING_cmd_truth_challenge (
    213       "file-challenge-run-1",
    214       anastasis_url,
    215       NULL, /* payment ref */
    216       "truth-store-2", /* upload ref */
    217       MHD_HTTP_PAYMENT_REQUIRED),
    218     /* what would we have to pay? */
    219     TALER_TESTING_cmd_merchant_claim_order ("fetch-proposal-2",
    220                                             merchant_url,
    221                                             MHD_HTTP_OK,
    222                                             "file-challenge-run-1",
    223                                             NULL),
    224     /* make the payment */
    225     TALER_TESTING_cmd_merchant_pay_order ("pay-account-2",
    226                                           merchant_url,
    227                                           MHD_HTTP_OK,
    228                                           "fetch-proposal-2",
    229                                           "withdraw-coin-2",
    230                                           "EUR:1.01",
    231                                           "EUR:1",
    232                                           NULL),
    233 
    234     ANASTASIS_TESTING_cmd_truth_challenge (
    235       "file-challenge-run-2",
    236       anastasis_url,
    237       "file-challenge-run-1", /* payment ref */
    238       "truth-store-2",
    239       MHD_HTTP_OK),
    240     ANASTASIS_TESTING_cmd_truth_solve (
    241       "file-challenge-run-3",
    242       anastasis_url,
    243       "file-challenge-run-2", /* answer */
    244       "file-challenge-run-1", /* payment ref */
    245       "truth-store-2",
    246       1,
    247       MHD_HTTP_OK),
    248     TALER_TESTING_cmd_end ()
    249   };
    250 
    251   struct TALER_TESTING_Command commands[] = {
    252     /* general setup */
    253     TALER_TESTING_cmd_system_start ("start-taler",
    254                                     CONFIG_FILE,
    255                                     "-bem",
    256                                     "-d", "iban",
    257                                     "-u", "exchange-account-exchange",
    258                                     NULL),
    259     TALER_TESTING_cmd_get_exchange ("get-exchange",
    260                                     cred.cfg,
    261                                     NULL,
    262                                     true,
    263                                     true),
    264     /* Not TALER_TESTING_cmd_merchant_post_instances(): that one gives the
    265        instance a pay delay of two seconds, and the orders here are created
    266        by anastasis-httpd, not by the test, so a slow order creation would
    267        expire the offer before the test gets to pay it. */
    268     TALER_TESTING_cmd_merchant_post_instances2 ("instance-create-admin",
    269                                                 merchant_url,
    270                                                 "admin",
    271                                                 "admin",
    272                                                 json_pack ("{s:s}",
    273                                                            "city",
    274                                                            "shopcity"),
    275                                                 json_pack ("{s:s}",
    276                                                            "city",
    277                                                            "lawyercity"),
    278                                                 true, /* use STEFAN */
    279                                                 GNUNET_TIME_UNIT_ZERO,
    280                                                 GNUNET_TIME_UNIT_MINUTES,
    281                                                 NULL, /* auth token */
    282                                                 MHD_HTTP_NO_CONTENT),
    283     TALER_TESTING_cmd_merchant_post_account (
    284       "instance-create-default-account",
    285       merchant_url,
    286       merchant_payto,
    287       NULL, NULL,
    288       MHD_HTTP_OK),
    289     ANASTASIS_TESTING_cmd_config ("salt-request-1",
    290                                   anastasis_url,
    291                                   MHD_HTTP_OK),
    292     TALER_TESTING_cmd_batch ("withdraw",
    293                              withdraw),
    294     TALER_TESTING_cmd_batch ("policy",
    295                              policy),
    296     TALER_TESTING_cmd_batch ("truth",
    297                              truth),
    298     TALER_TESTING_cmd_end ()
    299   };
    300 
    301   TALER_TESTING_run (is,
    302                      commands);
    303 }
    304 
    305 
    306 int
    307 main (int argc,
    308       char *const *argv)
    309 {
    310   int ret;
    311 
    312   file_secret = ANASTASIS_TESTING_make_file_challenge_name (CONFIG_FILE);
    313   if (NULL == file_secret)
    314     return 77;
    315   merchant_payto.full_payto =
    316     (char *) "payto://iban/SANDBOXX/" MERCHANT_ACCOUNT_IBAN
    317     "?receiver-name=merchant";
    318   merchant_url = "http://localhost:8080/";
    319 
    320   if (NULL ==
    321       (anastasis_url = ANASTASIS_TESTING_prepare_anastasis (CONFIG_FILE)))
    322     return 77;
    323   if (NULL == (anastasisd =
    324                  ANASTASIS_TESTING_run_anastasis (CONFIG_FILE,
    325                                                   anastasis_url)))
    326   {
    327     GNUNET_break (0);
    328     return 1;
    329   }
    330   ret = TALER_TESTING_main (argv,
    331                             "INFO",
    332                             CONFIG_FILE,
    333                             "exchange-account-exchange",
    334                             TALER_TESTING_BS_IBAN,
    335                             &cred,
    336                             &run,
    337                             NULL);
    338   GNUNET_break (GNUNET_OK ==
    339                 GNUNET_process_kill (anastasisd,
    340                                      SIGTERM));
    341   GNUNET_break (GNUNET_OK ==
    342                 GNUNET_process_wait (anastasisd,
    343                                      true,
    344                                      NULL,
    345                                      NULL));
    346   GNUNET_process_destroy (anastasisd);
    347   GNUNET_free (anastasis_url);
    348   return ret;
    349 }
    350 
    351 
    352 /* end of test_anastasis_api.c */