test_auditor_api_version.c (6460B)
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_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_process_create (GNUNET_OS_INHERIT_STD_ALL); 148 if (GNUNET_OK != 149 GNUNET_process_run_command_va (proc, 150 "taler-auditor-dbinit", 151 "taler-auditor-dbinit", 152 "-c", CONFIG_FILE, 153 "-L", "INFO", 154 NULL)) 155 { 156 GNUNET_log ( 157 GNUNET_ERROR_TYPE_ERROR, 158 "Failed to run `taler-auditor-dbinit`, is your PATH correct?\n"); 159 GNUNET_process_destroy (proc); 160 return 77; 161 } 162 GNUNET_break (GNUNET_OK == 163 GNUNET_process_wait (proc, 164 true, 165 NULL, 166 NULL)); 167 GNUNET_process_destroy (proc); 168 proc = GNUNET_process_create (GNUNET_OS_INHERIT_STD_ALL); 169 if (GNUNET_OK != 170 GNUNET_process_run_command_va (proc, 171 "taler-exchange-dbinit", 172 "taler-exchange-dbinit", 173 "-c", CONFIG_FILE, 174 "-L", "INFO", 175 NULL)) 176 { 177 GNUNET_log ( 178 GNUNET_ERROR_TYPE_ERROR, 179 "Failed to run `taler-auditor-dbinit`, is your PATH correct?\n"); 180 GNUNET_process_destroy (proc); 181 return 77; 182 } 183 GNUNET_break (GNUNET_OK == 184 GNUNET_process_wait (proc, 185 true, 186 NULL, 187 NULL)); 188 GNUNET_process_destroy (proc); 189 proc = GNUNET_process_create (GNUNET_OS_INHERIT_STD_ALL); 190 if (GNUNET_OK != 191 GNUNET_process_run_command_va (proc, 192 "taler-auditor-httpd", 193 "taler-auditor-httpd", 194 "-c", CONFIG_FILE, 195 "-L", "INFO", 196 NULL)) 197 { 198 GNUNET_log ( 199 GNUNET_ERROR_TYPE_ERROR, 200 "Failed to run `taler-auditor-httpd`, is your PATH correct?\n"); 201 GNUNET_process_destroy (proc); 202 return 77; 203 } 204 global_ret = TALER_TESTING_wait_httpd_ready ("http://localhost:8083/"); 205 if (0 != global_ret) 206 { 207 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 208 "Failed to launch `taler-auditor-httpd`\n"); 209 } 210 else 211 { 212 GNUNET_SCHEDULER_run (&run, 213 NULL); 214 } 215 GNUNET_break (GNUNET_OK == 216 GNUNET_process_kill (proc, 217 SIGTERM)); 218 GNUNET_break (GNUNET_OK == 219 GNUNET_process_wait (proc, 220 true, 221 NULL, 222 NULL)); 223 GNUNET_process_destroy (proc); 224 return global_ret; 225 } 226 227 228 /* end of test_auditor_api_version.c */