merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

testing_api_cmd_delete_account.c (5799B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 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  * @file testing_api_cmd_delete_account.c
     21  * @brief command to test DELETE /account/$H_WIRE
     22  * @author Christian Grothoff
     23  */
     24 #include "taler/platform.h"
     25 #include <taler/taler_exchange_service.h>
     26 #include <taler/taler_testing_lib.h>
     27 #include "taler/taler_merchant_service.h"
     28 #include "taler/taler_merchant_testing_lib.h"
     29 #include <taler/taler-merchant/delete-private-accounts-H_WIRE.h>
     30 
     31 
     32 /**
     33  * State of a "DELETE /accounts/$H_WIRE" CMD.
     34  */
     35 struct DeleteAccountState
     36 {
     37 
     38   /**
     39    * Handle for a "DELETE account" request.
     40    */
     41   struct TALER_MERCHANT_DeletePrivateAccountHandle *adh;
     42 
     43   /**
     44    * The interpreter state.
     45    */
     46   struct TALER_TESTING_Interpreter *is;
     47 
     48   /**
     49    * Base URL of the merchant serving the request.
     50    */
     51   const char *merchant_url;
     52 
     53   /**
     54    * ID of the command to get account details from.
     55    */
     56   const char *create_account_ref;
     57 
     58   /**
     59    * Expected HTTP response code.
     60    */
     61   unsigned int http_status;
     62 
     63 };
     64 
     65 
     66 /**
     67  * Callback for a DELETE /account/$H_WIRE operation.
     68  *
     69  * @param cls closure for this function
     70  * @param adr response being processed
     71  */
     72 static void
     73 delete_account_cb (void *cls,
     74                    const struct TALER_MERCHANT_DeletePrivateAccountResponse *adr
     75                    )
     76 {
     77   struct DeleteAccountState *das = cls;
     78 
     79   das->adh = NULL;
     80   if (das->http_status != adr->hr.http_status)
     81   {
     82     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     83                 "Unexpected response code %u (%d) to command %s\n",
     84                 adr->hr.http_status,
     85                 (int) adr->hr.ec,
     86                 TALER_TESTING_interpreter_get_current_label (das->is));
     87     TALER_TESTING_interpreter_fail (das->is);
     88     return;
     89   }
     90   switch (adr->hr.http_status)
     91   {
     92   case MHD_HTTP_NO_CONTENT:
     93     break;
     94   case MHD_HTTP_UNAUTHORIZED:
     95     break;
     96   case MHD_HTTP_NOT_FOUND:
     97     break;
     98   case MHD_HTTP_CONFLICT:
     99     break;
    100   default:
    101     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
    102                 "Unhandled HTTP status %u for DELETE account.\n",
    103                 adr->hr.http_status);
    104   }
    105   TALER_TESTING_interpreter_next (das->is);
    106 }
    107 
    108 
    109 /**
    110  * Run the "DELETE account" CMD.
    111  *
    112  * @param cls closure.
    113  * @param cmd command being run now.
    114  * @param is interpreter state.
    115  */
    116 static void
    117 delete_account_run (void *cls,
    118                     const struct TALER_TESTING_Command *cmd,
    119                     struct TALER_TESTING_Interpreter *is)
    120 {
    121   struct DeleteAccountState *das = cls;
    122   const struct TALER_TESTING_Command *ref;
    123   const struct TALER_MerchantWireHashP *h_wire;
    124   const char *merchant_url;
    125 
    126   das->is = is;
    127   ref = TALER_TESTING_interpreter_lookup_command (is,
    128                                                   das->create_account_ref);
    129   if (NULL == ref)
    130   {
    131     GNUNET_break (0);
    132     TALER_TESTING_FAIL (is);
    133     return;
    134   }
    135   if (GNUNET_OK !=
    136       TALER_TESTING_get_trait_merchant_base_url (ref,
    137                                                  &merchant_url))
    138   {
    139     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
    140                 "Command %s lacked merchant base URL\n",
    141                 das->create_account_ref);
    142     GNUNET_break (0);
    143     TALER_TESTING_FAIL (is);
    144     return;
    145   }
    146   if (GNUNET_OK !=
    147       TALER_TESTING_get_trait_h_wires (ref,
    148                                        0,
    149                                        &h_wire))
    150   {
    151     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
    152                 "Command %s did not return H_WIRE\n",
    153                 das->create_account_ref);
    154     GNUNET_break (0);
    155     TALER_TESTING_FAIL (is);
    156     return;
    157   }
    158   GNUNET_assert (NULL != h_wire);
    159   das->adh = TALER_MERCHANT_delete_private_account_create (
    160     TALER_TESTING_interpreter_get_context (is),
    161     merchant_url,
    162     h_wire);
    163   {
    164     enum TALER_ErrorCode ec;
    165 
    166     ec = TALER_MERCHANT_delete_private_account_start (das->adh,
    167                                                       &delete_account_cb,
    168                                                       das);
    169     GNUNET_assert (TALER_EC_NONE == ec);
    170   }
    171 }
    172 
    173 
    174 /**
    175  * Free the state of a "DELETE account" CMD, and possibly
    176  * cancel a pending operation thereof.
    177  *
    178  * @param cls closure.
    179  * @param cmd command being run.
    180  */
    181 static void
    182 delete_account_cleanup (void *cls,
    183                         const struct TALER_TESTING_Command *cmd)
    184 {
    185   struct DeleteAccountState *das = cls;
    186 
    187   if (NULL != das->adh)
    188   {
    189     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
    190                 "DELETE /accounts/$ID operation did not complete\n");
    191     TALER_MERCHANT_delete_private_account_cancel (das->adh);
    192   }
    193   GNUNET_free (das);
    194 }
    195 
    196 
    197 struct TALER_TESTING_Command
    198 TALER_TESTING_cmd_merchant_delete_account (const char *label,
    199                                            const char *create_account_ref,
    200                                            unsigned int http_status)
    201 {
    202   struct DeleteAccountState *das;
    203 
    204   das = GNUNET_new (struct DeleteAccountState);
    205   das->create_account_ref = create_account_ref;
    206   das->http_status = http_status;
    207   {
    208     struct TALER_TESTING_Command cmd = {
    209       .cls = das,
    210       .label = label,
    211       .run = &delete_account_run,
    212       .cleanup = &delete_account_cleanup
    213     };
    214 
    215     return cmd;
    216   }
    217 }
    218 
    219 
    220 /* end of testing_api_cmd_delete_account.c */