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