exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

test_auditor_api_version.c (5793B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2014-2023 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify
      6   it under the terms of the GNU General Public License as
      7   published by the Free Software Foundation; either version 3, or
      8   (at your option) any later version.
      9 
     10   TALER is distributed in the hope that it will be useful, but
     11   WITHOUT ANY WARRANTY; without even the implied warranty of
     12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13   GNU General Public License for more details.
     14 
     15   You should have received a copy of the GNU General Public
     16   License along with TALER; see the file COPYING.  If not, see
     17   <http://www.gnu.org/licenses/>
     18 */
     19 /**
     20  * @file testing/test_auditor_api_version.c
     21  * @brief testcase to test auditor's HTTP API interface to fetch /version
     22  * @author Christian Grothoff
     23  * @author Marcello Stanisci
     24  */
     25 #include "taler/platform.h"
     26 #include "taler/taler_util.h"
     27 #include "taler/taler_signatures.h"
     28 #include "taler/taler_exchange_service.h"
     29 #include "taler/taler_auditor_service.h"
     30 #include "taler/taler_json_lib.h"
     31 #include <gnunet/gnunet_util_lib.h>
     32 #include <microhttpd.h>
     33 #include "taler/taler_bank_service.h"
     34 #include "taler/taler_fakebank_lib.h"
     35 #include "taler/taler_testing_lib.h"
     36 
     37 
     38 /**
     39  * Configuration file we use.  One (big) configuration is used
     40  * for the various components for this test.
     41  */
     42 #define CONFIG_FILE "test_auditor_api-rsa.conf"
     43 
     44 static struct TALER_AUDITOR_GetConfigHandle *ah;
     45 
     46 static struct GNUNET_CURL_Context *ctx;
     47 
     48 static struct GNUNET_CURL_RescheduleContext *rc;
     49 
     50 static int global_ret;
     51 
     52 static struct GNUNET_SCHEDULER_Task *tt;
     53 
     54 
     55 static void
     56 do_shutdown (void *cls)
     57 {
     58   (void) cls;
     59 
     60   if (NULL != tt)
     61   {
     62     GNUNET_SCHEDULER_cancel (tt);
     63     tt = NULL;
     64   }
     65   if (NULL != ah)
     66   {
     67     TALER_AUDITOR_get_config_cancel (ah);
     68     ah = NULL;
     69   }
     70   GNUNET_CURL_fini (ctx);
     71   GNUNET_CURL_gnunet_rc_destroy (rc);
     72 }
     73 
     74 
     75 static void
     76 do_timeout (void *cls)
     77 {
     78   (void) cls;
     79   tt = NULL;
     80   global_ret = 3;
     81   GNUNET_SCHEDULER_shutdown ();
     82 }
     83 
     84 
     85 /**
     86  * Function called with information about the auditor.
     87  *
     88  * @param cls closure
     89  * @param vr response details
     90  */
     91 static void
     92 version_cb (void *cls,
     93             const struct TALER_AUDITOR_ConfigResponse *vr)
     94 {
     95   (void) cls;
     96   ah = NULL;
     97   if ( (MHD_HTTP_OK == vr->hr.http_status) &&
     98        (TALER_AUDITOR_VC_MATCH == vr->details.ok.compat) )
     99     global_ret = 0;
    100   else
    101     global_ret = 2;
    102   GNUNET_SCHEDULER_shutdown ();
    103 }
    104 
    105 
    106 /**
    107  * Main function that will tell the interpreter what commands to
    108  * run.
    109  *
    110  * @param cls closure
    111  */
    112 static void
    113 run (void *cls)
    114 {
    115   const char *auditor_url = "http://localhost:8083/";
    116 
    117   (void) cls;
    118   ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
    119                           &rc);
    120   rc = GNUNET_CURL_gnunet_rc_create (ctx);
    121   ah = TALER_AUDITOR_get_config (ctx,
    122                                  auditor_url,
    123                                  &version_cb,
    124                                  NULL);
    125   GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
    126                                  NULL);
    127   tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
    128                                      &do_timeout,
    129                                      NULL);
    130 }
    131 
    132 
    133 int
    134 main (int argc,
    135       char *const *argv)
    136 {
    137   struct GNUNET_OS_Process *proc;
    138 
    139   (void) argc;
    140   (void) argv;
    141   /* These environment variables get in the way... */
    142   unsetenv ("XDG_DATA_HOME");
    143   unsetenv ("XDG_CONFIG_HOME");
    144   GNUNET_log_setup ("test-auditor-api-version",
    145                     "INFO",
    146                     NULL);
    147   proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
    148                                   NULL, NULL, NULL,
    149                                   "taler-auditor-dbinit",
    150                                   "taler-auditor-dbinit",
    151                                   "-c", CONFIG_FILE,
    152                                   "-L", "INFO",
    153                                   NULL);
    154   if (NULL == proc)
    155   {
    156     GNUNET_log (
    157       GNUNET_ERROR_TYPE_ERROR,
    158       "Failed to run `taler-auditor-dbinit`, is your PATH correct?\n");
    159     return 77;
    160   }
    161   GNUNET_OS_process_wait (proc);
    162   GNUNET_OS_process_destroy (proc);
    163   proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
    164                                   NULL, NULL, NULL,
    165                                   "taler-exchange-dbinit",
    166                                   "taler-exchange-dbinit",
    167                                   "-c", CONFIG_FILE,
    168                                   "-L", "INFO",
    169                                   NULL);
    170   if (NULL == proc)
    171   {
    172     GNUNET_log (
    173       GNUNET_ERROR_TYPE_ERROR,
    174       "Failed to run `taler-auditor-dbinit`, is your PATH correct?\n");
    175     return 77;
    176   }
    177   GNUNET_OS_process_wait (proc);
    178   GNUNET_OS_process_destroy (proc);
    179   proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
    180                                   NULL, NULL, NULL,
    181                                   "taler-auditor-httpd",
    182                                   "taler-auditor-httpd",
    183                                   "-c", CONFIG_FILE,
    184                                   "-L", "INFO",
    185                                   NULL);
    186   if (NULL == proc)
    187   {
    188     GNUNET_log (
    189       GNUNET_ERROR_TYPE_ERROR,
    190       "Failed to run `taler-auditor-httpd`, is your PATH correct?\n");
    191     return 77;
    192   }
    193   global_ret = TALER_TESTING_wait_httpd_ready ("http://localhost:8083/");
    194   if (0 != global_ret)
    195   {
    196     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
    197                 "Failed to launch `taler-auditor-httpd`\n");
    198   }
    199   else
    200   {
    201     GNUNET_SCHEDULER_run (&run,
    202                           NULL);
    203   }
    204   GNUNET_OS_process_kill (proc,
    205                           SIGTERM);
    206   GNUNET_OS_process_wait (proc);
    207   GNUNET_OS_process_destroy (proc);
    208   return global_ret;
    209 }
    210 
    211 
    212 /* end of test_auditor_api_version.c */