testing_api_cmd_config.c (3591B)
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 "platform.h" 27 #include <taler/taler_exchange_service.h> 28 #include <taler/taler_testing_lib.h> 29 #include "taler_merchant_service.h" 30 #include "taler_merchant_testing_lib.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_ConfigGetHandle *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_config_get_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_ConfigResponse *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_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_config_get (TALER_TESTING_interpreter_get_context ( 123 is), 124 cs->merchant_url, 125 &config_cb, 126 cs); 127 GNUNET_assert (NULL != cs->vgh); 128 } 129 130 131 struct TALER_TESTING_Command 132 TALER_TESTING_cmd_config (const char *label, 133 const char *merchant_url, 134 unsigned int http_code) 135 { 136 struct ConfigState *cs; 137 138 cs = GNUNET_new (struct ConfigState); 139 cs->merchant_url = merchant_url; 140 cs->http_code = http_code; 141 { 142 struct TALER_TESTING_Command cmd = { 143 .cls = cs, 144 .label = label, 145 .run = &config_run, 146 .cleanup = &config_cleanup 147 }; 148 149 return cmd; 150 } 151 } 152 153 154 /* end of testing_api_cmd_config.c */