LCOV - code coverage report
Current view: top level - testing - test_auditor_api_version.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 72.3 % 65 47
Test Date: 2026-04-14 15:39:31 Functions: 80.0 % 5 4

            Line data    Source code
       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_auditor_service.h"
      29              : #include "taler/taler_json_lib.h"
      30              : #include <gnunet/gnunet_util_lib.h>
      31              : #include <microhttpd.h>
      32              : #include "taler/taler_bank_service.h"
      33              : #include "taler/taler_testing_lib.h"
      34              : 
      35              : 
      36              : /**
      37              :  * Configuration file we use.  One (big) configuration is used
      38              :  * for the various components for this test.
      39              :  */
      40              : #define CONFIG_FILE "test_auditor_api-rsa.conf"
      41              : 
      42              : static struct TALER_AUDITOR_GetConfigHandle *ah;
      43              : 
      44              : static struct GNUNET_CURL_Context *ctx;
      45              : 
      46              : static struct GNUNET_CURL_RescheduleContext *rc;
      47              : 
      48              : static int global_ret;
      49              : 
      50              : static struct GNUNET_SCHEDULER_Task *tt;
      51              : 
      52              : 
      53              : static void
      54            1 : do_shutdown (void *cls)
      55              : {
      56              :   (void) cls;
      57              : 
      58            1 :   if (NULL != tt)
      59              :   {
      60            1 :     GNUNET_SCHEDULER_cancel (tt);
      61            1 :     tt = NULL;
      62              :   }
      63            1 :   if (NULL != ah)
      64              :   {
      65            0 :     TALER_AUDITOR_get_config_cancel (ah);
      66            0 :     ah = NULL;
      67              :   }
      68            1 :   GNUNET_CURL_fini (ctx);
      69            1 :   GNUNET_CURL_gnunet_rc_destroy (rc);
      70            1 : }
      71              : 
      72              : 
      73              : static void
      74            0 : do_timeout (void *cls)
      75              : {
      76              :   (void) cls;
      77            0 :   tt = NULL;
      78            0 :   global_ret = 3;
      79            0 :   GNUNET_SCHEDULER_shutdown ();
      80            0 : }
      81              : 
      82              : 
      83              : /**
      84              :  * Function called with information about the auditor.
      85              :  *
      86              :  * @param cls closure
      87              :  * @param vr response details
      88              :  */
      89              : static void
      90            1 : version_cb (void *cls,
      91              :             const struct TALER_AUDITOR_ConfigResponse *vr)
      92              : {
      93              :   (void) cls;
      94            1 :   ah = NULL;
      95            1 :   if ( (MHD_HTTP_OK == vr->hr.http_status) &&
      96            1 :        (TALER_AUDITOR_VC_MATCH == vr->details.ok.compat) )
      97            1 :     global_ret = 0;
      98              :   else
      99            0 :     global_ret = 2;
     100            1 :   GNUNET_SCHEDULER_shutdown ();
     101            1 : }
     102              : 
     103              : 
     104              : /**
     105              :  * Main function that will tell the interpreter what commands to
     106              :  * run.
     107              :  *
     108              :  * @param cls closure
     109              :  */
     110              : static void
     111            1 : run (void *cls)
     112              : {
     113            1 :   const char *auditor_url = "http://localhost:8083/";
     114              : 
     115              :   (void) cls;
     116            1 :   ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
     117              :                           &rc);
     118            1 :   rc = GNUNET_CURL_gnunet_rc_create (ctx);
     119            1 :   ah = TALER_AUDITOR_get_config (ctx,
     120              :                                  auditor_url,
     121              :                                  &version_cb,
     122              :                                  NULL);
     123            1 :   GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
     124              :                                  NULL);
     125            1 :   tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
     126              :                                      &do_timeout,
     127              :                                      NULL);
     128            1 : }
     129              : 
     130              : 
     131              : int
     132            1 : main (int argc,
     133              :       char *const *argv)
     134              : {
     135              :   struct GNUNET_Process *proc;
     136              : 
     137              :   (void) argc;
     138              :   (void) argv;
     139              :   /* These environment variables get in the way... */
     140            1 :   unsetenv ("XDG_DATA_HOME");
     141            1 :   unsetenv ("XDG_CONFIG_HOME");
     142            1 :   GNUNET_log_setup ("test-auditor-api-version",
     143              :                     "INFO",
     144              :                     NULL);
     145            1 :   proc = GNUNET_process_create (GNUNET_OS_INHERIT_STD_ALL);
     146            1 :   if (GNUNET_OK !=
     147            1 :       GNUNET_process_run_command_va (proc,
     148              :                                      "taler-auditor-dbinit",
     149              :                                      "taler-auditor-dbinit",
     150              :                                      "-c", CONFIG_FILE,
     151              :                                      "-L", "INFO",
     152              :                                      NULL))
     153              :   {
     154            0 :     GNUNET_log (
     155              :       GNUNET_ERROR_TYPE_ERROR,
     156              :       "Failed to run `taler-auditor-dbinit`, is your PATH correct?\n");
     157            0 :     GNUNET_process_destroy (proc);
     158            0 :     return 77;
     159              :   }
     160            1 :   GNUNET_break (GNUNET_OK ==
     161              :                 GNUNET_process_wait (proc,
     162              :                                      true,
     163              :                                      NULL,
     164              :                                      NULL));
     165            1 :   GNUNET_process_destroy (proc);
     166            1 :   proc = GNUNET_process_create (GNUNET_OS_INHERIT_STD_ALL);
     167            1 :   if (GNUNET_OK !=
     168            1 :       GNUNET_process_run_command_va (proc,
     169              :                                      "taler-exchange-dbinit",
     170              :                                      "taler-exchange-dbinit",
     171              :                                      "-c", CONFIG_FILE,
     172              :                                      "-L", "INFO",
     173              :                                      NULL))
     174              :   {
     175            0 :     GNUNET_log (
     176              :       GNUNET_ERROR_TYPE_ERROR,
     177              :       "Failed to run `taler-auditor-dbinit`, is your PATH correct?\n");
     178            0 :     GNUNET_process_destroy (proc);
     179            0 :     return 77;
     180              :   }
     181            1 :   GNUNET_break (GNUNET_OK ==
     182              :                 GNUNET_process_wait (proc,
     183              :                                      true,
     184              :                                      NULL,
     185              :                                      NULL));
     186            1 :   GNUNET_process_destroy (proc);
     187            1 :   proc = GNUNET_process_create (GNUNET_OS_INHERIT_STD_ALL);
     188            1 :   if (GNUNET_OK !=
     189            1 :       GNUNET_process_run_command_va (proc,
     190              :                                      "taler-auditor-httpd",
     191              :                                      "taler-auditor-httpd",
     192              :                                      "-c", CONFIG_FILE,
     193              :                                      "-L", "INFO",
     194              :                                      NULL))
     195              :   {
     196            0 :     GNUNET_log (
     197              :       GNUNET_ERROR_TYPE_ERROR,
     198              :       "Failed to run `taler-auditor-httpd`, is your PATH correct?\n");
     199            0 :     GNUNET_process_destroy (proc);
     200            0 :     return 77;
     201              :   }
     202            1 :   global_ret = TALER_TESTING_wait_httpd_ready ("http://localhost:8083/");
     203            1 :   if (0 != global_ret)
     204              :   {
     205            0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     206              :                 "Failed to launch `taler-auditor-httpd`\n");
     207              :   }
     208              :   else
     209              :   {
     210            1 :     GNUNET_SCHEDULER_run (&run,
     211              :                           NULL);
     212              :   }
     213            1 :   GNUNET_break (GNUNET_OK ==
     214              :                 GNUNET_process_kill (proc,
     215              :                                      SIGTERM));
     216            1 :   GNUNET_break (GNUNET_OK ==
     217              :                 GNUNET_process_wait (proc,
     218              :                                      true,
     219              :                                      NULL,
     220              :                                      NULL));
     221            1 :   GNUNET_process_destroy (proc);
     222            1 :   return global_ret;
     223              : }
     224              : 
     225              : 
     226              : /* end of test_auditor_api_version.c */
        

Generated by: LCOV version 2.0-1