testing_api_cmd_get_aml_officer.c (4582B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2026 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 */ 9 /** 10 * @file testing/testing_api_cmd_get_aml_officer.c 11 * @brief command for testing GET /aml/$OFFICER_PUB 12 */ 13 #include <gnunet/gnunet_curl_lib.h> 14 15 struct AmlOfficerState; 16 17 #define TALER_EXCHANGE_GET_AML_OFFICER_RESULT_CLOSURE struct AmlOfficerState 18 #include "taler/exchange/get-aml-OFFICER_PUB.h" 19 #include "taler/taler_testing_lib.h" 20 21 22 /** 23 * State for a GET AML officer command. 24 */ 25 struct AmlOfficerState 26 { 27 struct TALER_EXCHANGE_GetAmlOfficerHandle *handle; 28 struct TALER_TESTING_Interpreter *is; 29 const char *ref_officer; 30 const char *expected_name; 31 unsigned int expected_http_status; 32 bool expected_read_only; 33 }; 34 35 36 /** 37 * Process the AML officer response. 38 * 39 * @param state command state 40 * @param response exchange response 41 */ 42 static void 43 get_aml_officer_cb ( 44 TALER_EXCHANGE_GET_AML_OFFICER_RESULT_CLOSURE *state, 45 const struct TALER_EXCHANGE_GetAmlOfficerResponse *response) 46 { 47 state->handle = NULL; 48 if (state->expected_http_status != response->hr.http_status) 49 { 50 TALER_TESTING_unexpected_status (state->is, 51 response->hr.http_status, 52 state->expected_http_status); 53 return; 54 } 55 if (MHD_HTTP_OK == response->hr.http_status) 56 { 57 if ( (0 != strcmp (state->expected_name, 58 response->details.ok.officer_name)) || 59 (state->expected_read_only != response->details.ok.read_only) ) 60 { 61 GNUNET_break (0); 62 TALER_TESTING_interpreter_fail (state->is); 63 return; 64 } 65 } 66 TALER_TESTING_interpreter_next (state->is); 67 } 68 69 70 /** 71 * Run the command. 72 */ 73 static void 74 get_aml_officer_run ( 75 void *cls, 76 const struct TALER_TESTING_Command *cmd, 77 struct TALER_TESTING_Interpreter *is) 78 { 79 struct AmlOfficerState *state = cls; 80 const struct TALER_AmlOfficerPrivateKeyP *officer_priv; 81 const struct TALER_TESTING_Command *ref; 82 const struct TALER_TESTING_Command *exchange_cmd; 83 const char *exchange_url; 84 enum TALER_ErrorCode ec; 85 86 (void) cmd; 87 state->is = is; 88 exchange_cmd = TALER_TESTING_interpreter_get_command (is, 89 "exchange"); 90 GNUNET_assert (NULL != exchange_cmd); 91 GNUNET_assert ( 92 GNUNET_OK == 93 TALER_TESTING_get_trait_exchange_url (exchange_cmd, 94 &exchange_url)); 95 ref = TALER_TESTING_interpreter_lookup_command (is, 96 state->ref_officer); 97 if (NULL == ref) 98 { 99 GNUNET_break (0); 100 TALER_TESTING_interpreter_fail (is); 101 return; 102 } 103 GNUNET_assert ( 104 GNUNET_OK == 105 TALER_TESTING_get_trait_officer_priv (ref, 106 &officer_priv)); 107 state->handle = TALER_EXCHANGE_get_aml_officer_create ( 108 TALER_TESTING_interpreter_get_context (is), 109 exchange_url, 110 officer_priv); 111 GNUNET_assert (NULL != state->handle); 112 ec = TALER_EXCHANGE_get_aml_officer_start (state->handle, 113 &get_aml_officer_cb, 114 state); 115 if (TALER_EC_NONE != ec) 116 { 117 state->handle = NULL; 118 TALER_TESTING_interpreter_fail (is); 119 } 120 } 121 122 123 /** 124 * Clean up the command. 125 */ 126 static void 127 get_aml_officer_cleanup ( 128 void *cls, 129 const struct TALER_TESTING_Command *cmd) 130 { 131 struct AmlOfficerState *state = cls; 132 133 if (NULL != state->handle) 134 { 135 TALER_TESTING_command_incomplete (state->is, 136 cmd->label); 137 TALER_EXCHANGE_get_aml_officer_cancel (state->handle); 138 } 139 GNUNET_free (state); 140 } 141 142 143 struct TALER_TESTING_Command 144 TALER_TESTING_cmd_get_aml_officer ( 145 const char *label, 146 const char *ref_officer, 147 unsigned int expected_http_status, 148 const char *expected_name, 149 bool expected_read_only) 150 { 151 struct AmlOfficerState *state; 152 struct TALER_TESTING_Command cmd; 153 154 state = GNUNET_new (struct AmlOfficerState); 155 state->ref_officer = ref_officer; 156 state->expected_http_status = expected_http_status; 157 state->expected_name = expected_name; 158 state->expected_read_only = expected_read_only; 159 cmd = (struct TALER_TESTING_Command) { 160 .cls = state, 161 .label = label, 162 .run = &get_aml_officer_run, 163 .cleanup = &get_aml_officer_cleanup 164 }; 165 return cmd; 166 } 167 168 169 /* end of testing_api_cmd_get_aml_officer.c */