testing_api_cmd_config.c (3732B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2020-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 /** 21 * @file src/testing/testing_api_cmd_config.c 22 * @brief command to test config request 23 * @author Christian Grothoff 24 */ 25 26 #include "platform.h" 27 struct ConfigState; 28 #define TALER_MERCHANT_GET_CONFIG_RESULT_CLOSURE struct ConfigState 29 #include <taler/taler_exchange_service.h> 30 #include <taler/taler_testing_lib.h> 31 #include "taler/taler_merchant_testing_lib.h" 32 #include <taler/merchant/get-config.h> 33 34 35 /** 36 * State for a "config" CMD. 37 */ 38 struct ConfigState 39 { 40 /** 41 * Operation handle for a GET /public/config request. 42 */ 43 struct TALER_MERCHANT_GetConfigHandle *vgh; 44 45 /** 46 * Base URL of the merchant serving the request. 47 */ 48 const char *merchant_url; 49 50 /** 51 * Expected HTTP response code. 52 */ 53 unsigned int http_code; 54 55 /** 56 * Interpreter state. 57 */ 58 struct TALER_TESTING_Interpreter *is; 59 60 }; 61 62 63 /** 64 * Free the state of a "config" CMD, and 65 * possibly cancel a pending "config" operation. 66 * 67 * @param cls closure with the `struct ConfigState` 68 * @param cmd command currently being freed. 69 */ 70 static void 71 config_cleanup (void *cls, 72 const struct TALER_TESTING_Command *cmd) 73 { 74 struct ConfigState *cs = cls; 75 76 if (NULL != cs->vgh) 77 { 78 TALER_LOG_WARNING ("config operation did not complete\n"); 79 TALER_MERCHANT_get_config_cancel (cs->vgh); 80 } 81 GNUNET_free (cs); 82 } 83 84 85 /** 86 * Process "GET /public/config" (lookup) response. 87 * 88 * @param cls closure 89 * @param cr response we got 90 */ 91 static void 92 config_cb (struct ConfigState *cs, 93 const struct TALER_MERCHANT_GetConfigResponse *cr) 94 { 95 96 cs->vgh = NULL; 97 if (cs->http_code != cr->hr.http_status) 98 TALER_TESTING_FAIL (cs->is); 99 if (MHD_HTTP_OK == cr->hr.http_status) 100 { 101 if (TALER_MERCHANT_GET_CONFIG_VC_MATCH != cr->details.ok.compat) 102 TALER_TESTING_FAIL (cs->is); 103 } 104 TALER_TESTING_interpreter_next (cs->is); 105 } 106 107 108 /** 109 * Run the "config" CMD. 110 * 111 * @param cls closure. 112 * @param cmd command being currently run. 113 * @param is interpreter state. 114 */ 115 static void 116 config_run (void *cls, 117 const struct TALER_TESTING_Command *cmd, 118 struct TALER_TESTING_Interpreter *is) 119 { 120 struct ConfigState *cs = cls; 121 122 cs->is = is; 123 cs->vgh = TALER_MERCHANT_get_config_create ( 124 TALER_TESTING_interpreter_get_context (is), 125 cs->merchant_url); 126 { 127 enum TALER_ErrorCode ec; 128 129 ec = TALER_MERCHANT_get_config_start (cs->vgh, 130 &config_cb, 131 cs); 132 GNUNET_assert (TALER_EC_NONE == ec); 133 } 134 } 135 136 137 struct TALER_TESTING_Command 138 TALER_TESTING_cmd_config (const char *label, 139 const char *merchant_url, 140 unsigned int http_code) 141 { 142 struct ConfigState *cs; 143 144 cs = GNUNET_new (struct ConfigState); 145 cs->merchant_url = merchant_url; 146 cs->http_code = http_code; 147 { 148 struct TALER_TESTING_Command cmd = { 149 .cls = cs, 150 .label = label, 151 .run = &config_run, 152 .cleanup = &config_cleanup 153 }; 154 155 return cmd; 156 } 157 } 158 159 160 /* end of testing_api_cmd_config.c */