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 "platform.h"
26 : #include "taler_util.h"
27 : #include "taler_signatures.h"
28 : #include "taler_exchange_service.h"
29 : #include "taler_auditor_service.h"
30 : #include "taler_json_lib.h"
31 : #include <gnunet/gnunet_util_lib.h>
32 : #include <microhttpd.h>
33 : #include "taler_bank_service.h"
34 : #include "taler_fakebank_lib.h"
35 : #include "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 1 : do_shutdown (void *cls)
57 : {
58 : (void) cls;
59 :
60 1 : if (NULL != tt)
61 : {
62 1 : GNUNET_SCHEDULER_cancel (tt);
63 1 : tt = NULL;
64 : }
65 1 : if (NULL != ah)
66 : {
67 0 : TALER_AUDITOR_get_config_cancel (ah);
68 0 : ah = NULL;
69 : }
70 1 : GNUNET_CURL_fini (ctx);
71 1 : GNUNET_CURL_gnunet_rc_destroy (rc);
72 1 : }
73 :
74 :
75 : static void
76 0 : do_timeout (void *cls)
77 : {
78 : (void) cls;
79 0 : tt = NULL;
80 0 : global_ret = 3;
81 0 : GNUNET_SCHEDULER_shutdown ();
82 0 : }
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 1 : version_cb (void *cls,
93 : const struct TALER_AUDITOR_ConfigResponse *vr)
94 : {
95 : (void) cls;
96 1 : ah = NULL;
97 1 : if ( (MHD_HTTP_OK == vr->hr.http_status) &&
98 1 : (TALER_AUDITOR_VC_MATCH == vr->details.ok.compat) )
99 1 : global_ret = 0;
100 : else
101 0 : global_ret = 2;
102 1 : GNUNET_SCHEDULER_shutdown ();
103 1 : }
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 1 : run (void *cls)
114 : {
115 1 : const char *auditor_url = "http://localhost:8083/";
116 :
117 : (void) cls;
118 1 : ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
119 : &rc);
120 1 : rc = GNUNET_CURL_gnunet_rc_create (ctx);
121 1 : ah = TALER_AUDITOR_get_config (ctx,
122 : auditor_url,
123 : &version_cb,
124 : NULL);
125 1 : GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
126 : NULL);
127 1 : tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
128 : &do_timeout,
129 : NULL);
130 1 : }
131 :
132 :
133 : int
134 1 : 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 1 : unsetenv ("XDG_DATA_HOME");
143 1 : unsetenv ("XDG_CONFIG_HOME");
144 1 : GNUNET_log_setup ("test-auditor-api-version",
145 : "INFO",
146 : NULL);
147 1 : 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 1 : if (NULL == proc)
155 : {
156 0 : GNUNET_log (
157 : GNUNET_ERROR_TYPE_ERROR,
158 : "Failed to run `taler-auditor-dbinit`, is your PATH correct?\n");
159 0 : return 77;
160 : }
161 1 : GNUNET_OS_process_wait (proc);
162 1 : GNUNET_OS_process_destroy (proc);
163 1 : 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 1 : if (NULL == proc)
171 : {
172 0 : GNUNET_log (
173 : GNUNET_ERROR_TYPE_ERROR,
174 : "Failed to run `taler-auditor-dbinit`, is your PATH correct?\n");
175 0 : return 77;
176 : }
177 1 : GNUNET_OS_process_wait (proc);
178 1 : GNUNET_OS_process_destroy (proc);
179 1 : 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 1 : if (NULL == proc)
187 : {
188 0 : GNUNET_log (
189 : GNUNET_ERROR_TYPE_ERROR,
190 : "Failed to run `taler-auditor-httpd`, is your PATH correct?\n");
191 0 : return 77;
192 : }
193 1 : global_ret = TALER_TESTING_wait_httpd_ready ("http://localhost:8083/");
194 1 : if (0 != global_ret)
195 : {
196 0 : GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
197 : "Failed to launch `taler-auditor-httpd`\n");
198 : }
199 : else
200 : {
201 1 : GNUNET_SCHEDULER_run (&run,
202 : NULL);
203 : }
204 1 : GNUNET_OS_process_kill (proc,
205 : SIGTERM);
206 1 : GNUNET_OS_process_wait (proc);
207 1 : GNUNET_OS_process_destroy (proc);
208 1 : return global_ret;
209 : }
210 :
211 :
212 : /* end of test_auditor_api_version.c */
|