LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_delete_account.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 52 0
Test Date: 2026-09-11 17:45:24 Functions: 0.0 % 4 0

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

Generated by: LCOV version 2.0-1