aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_config.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_api_cmd_config.c')
-rw-r--r--src/testing/testing_api_cmd_config.c206
1 files changed, 206 insertions, 0 deletions
diff --git a/src/testing/testing_api_cmd_config.c b/src/testing/testing_api_cmd_config.c
new file mode 100644
index 0000000..8906261
--- /dev/null
+++ b/src/testing/testing_api_cmd_config.c
@@ -0,0 +1,206 @@
1/*
2 This file is part of TALER
3 Copyright (C) 2019, 2021 Taler Systems SA
4
5 TALER is free software; you can redistribute it and/or modify it under the
6 terms of the GNU Affero General Public License as published by the Free Software
7 Foundation; either version 3, or (at your option) any later version.
8
9 TALER 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 Affero General Public License for more details.
12
13 You should have received a copy of the GNU Affero General Public License along with
14 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
15*/
16/**
17 * @file lib/testing_api_cmd_config.c
18 * @brief command to obtain the configuration of an anastasis backend service.
19 * @author Dennis Neufeld
20 * @author Dominik Meister
21 */
22
23#include "platform.h"
24#include "anastasis_testing_lib.h"
25#include <taler/taler_util.h>
26#include <taler/taler_testing_lib.h>
27
28
29/**
30 * State for a "config" CMD.
31 */
32struct ConfigState
33{
34 /**
35 * The interpreter state.
36 */
37 struct TALER_TESTING_Interpreter *is;
38
39 /**
40 * URL of the anastasis backend.
41 */
42 const char *anastasis_url;
43
44 /**
45 * Expected status code.
46 */
47 unsigned int http_status;
48
49 /**
50 * The /config GET operation handle.
51 */
52 struct ANASTASIS_ConfigOperation *so;
53
54 /**
55 * The salt value from server.
56 */
57 struct ANASTASIS_CRYPTO_ProviderSaltP salt;
58};
59
60
61/**
62 * Function called with the results of a #ANASTASIS_config().
63 *
64 * @param cls closure
65 * @param http_status HTTP status of the request
66 * @param config config from the server
67 */
68static void
69config_cb (void *cls,
70 unsigned int http_status,
71 const struct ANASTASIS_Config *config)
72{
73 struct ConfigState *ss = cls;
74
75 ss->so = NULL;
76 if (http_status != ss->http_status)
77 {
78 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
79 "Unexpected response code %u to command %s in %s:%u\n",
80 http_status,
81 ss->is->commands[ss->is->ip].label,
82 __FILE__,
83 __LINE__);
84 TALER_TESTING_interpreter_fail (ss->is);
85 return;
86 }
87 if (NULL == config)
88 {
89 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
90 "Config is NULL, command %s in %s:%u\n",
91 ss->is->commands[ss->is->ip].label,
92 __FILE__,
93 __LINE__);
94 TALER_TESTING_interpreter_fail (ss->is);
95 return;
96 }
97 ss->salt = config->salt;
98 TALER_TESTING_interpreter_next (ss->is);
99}
100
101
102/**
103 * Run a "config" CMD.
104 *
105 * @param cls closure.
106 * @param cmd command currently being run.
107 * @param is interpreter state.
108 */
109static void
110config_run (void *cls,
111 const struct TALER_TESTING_Command *cmd,
112 struct TALER_TESTING_Interpreter *is)
113{
114 struct ConfigState *ss = cls;
115
116 ss->is = is;
117 ss->so = ANASTASIS_get_config (is->ctx,
118 ss->anastasis_url,
119 &config_cb,
120 ss);
121 if (NULL == ss->so)
122 {
123 GNUNET_break (0);
124 TALER_TESTING_interpreter_fail (ss->is);
125 return;
126 }
127}
128
129
130/**
131 * Free the state of a "config" CMD, and possibly
132 * cancel it if it did not complete.
133 *
134 * @param cls closure.
135 * @param cmd command being freed.
136 */
137static void
138config_cleanup (void *cls,
139 const struct TALER_TESTING_Command *cmd)
140{
141 struct ConfigState *ss = cls;
142
143 if (NULL != ss->so)
144 {
145 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
146 "Command '%s' did not complete (config)\n",
147 cmd->label);
148 ANASTASIS_config_cancel (ss->so);
149 ss->so = NULL;
150 }
151 GNUNET_free (ss);
152}
153
154
155/**
156 * Offer internal data to other commands.
157 *
158 * @param cls closure
159 * @param ret[out] result (could be anything)
160 * @param trait name of the trait
161 * @param index index number of the object to extract.
162 * @return #GNUNET_OK on success
163 */
164static int
165config_traits (void *cls,
166 const void **ret,
167 const char *trait,
168 unsigned int index)
169{
170 struct ConfigState *ss = cls;
171
172 struct TALER_TESTING_Trait traits[] = {
173 ANASTASIS_TESTING_make_trait_salt (0,
174 &ss->salt),
175 TALER_TESTING_trait_end ()
176 };
177
178 return TALER_TESTING_get_trait (traits,
179 ret,
180 trait,
181 index);
182}
183
184
185struct TALER_TESTING_Command
186ANASTASIS_TESTING_cmd_config (const char *label,
187 const char *anastasis_url,
188 unsigned int http_status)
189{
190 struct ConfigState *ss;
191
192 ss = GNUNET_new (struct ConfigState);
193 ss->http_status = http_status;
194 ss->anastasis_url = anastasis_url;
195 {
196 struct TALER_TESTING_Command cmd = {
197 .cls = ss,
198 .label = label,
199 .run = &config_run,
200 .cleanup = &config_cleanup,
201 .traits = &config_traits
202 };
203
204 return cmd;
205 }
206}