LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_delete_transfer.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 56.6 % 53 30
Test Date: 2026-09-11 17:45:24 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   Copyright (C) 2021 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_transfer.c
      21              :  * @brief command to test DELETE /transfers/$TRANSFER_ID
      22              :  * @author Jonathan Buchanan
      23              :  */
      24              : #include "platform.h"
      25              : struct DeleteTransferState;
      26              : #define TALER_MERCHANT_DELETE_PRIVATE_TRANSFER_RESULT_CLOSURE struct DeleteTransferState
      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-transfers-TID.h>
      32              : 
      33              : 
      34              : /**
      35              :  * State of a "DELETE /transfer/$TRANSFER_ID" CMD.
      36              :  */
      37              : struct DeleteTransferState
      38              : {
      39              : 
      40              :   /**
      41              :    * Handle for a "DELETE transfer" request.
      42              :    */
      43              :   struct TALER_MERCHANT_DeletePrivateTransferHandle *tdh;
      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              :    * Ref to cmd with ID of the transfer to run DELETE for.
      57              :    */
      58              :   const char *transfer_ref;
      59              : 
      60              :   /**
      61              :    * Expected HTTP response code.
      62              :    */
      63              :   unsigned int http_status;
      64              : 
      65              : };
      66              : 
      67              : 
      68              : /**
      69              :  * Callback for a DELETE /transfers/$ID operation.
      70              :  *
      71              :  * @param cls closure for this function
      72              :  * @param dtr response being processed
      73              :  */
      74              : static void
      75            2 : delete_transfer_cb (struct DeleteTransferState *dts,
      76              :                     const struct TALER_MERCHANT_DeletePrivateTransferResponse *
      77              :                     dtr)
      78              : {
      79              : 
      80            2 :   dts->tdh = NULL;
      81            2 :   if (dts->http_status != dtr->hr.http_status)
      82              :   {
      83            0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
      84              :                 "Unexpected response code %u (%d) to command %s\n",
      85              :                 dtr->hr.http_status,
      86              :                 (int) dtr->hr.ec,
      87              :                 TALER_TESTING_interpreter_get_current_label (dts->is));
      88            0 :     TALER_TESTING_interpreter_fail (dts->is);
      89            0 :     return;
      90              :   }
      91            2 :   switch (dtr->hr.http_status)
      92              :   {
      93            2 :   case MHD_HTTP_NO_CONTENT:
      94            2 :     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_break (0);
     103            0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     104              :                 "Unhandled HTTP status %u for DELETE transfer.\n",
     105              :                 dtr->hr.http_status);
     106              :   }
     107            2 :   TALER_TESTING_interpreter_next (dts->is);
     108              : }
     109              : 
     110              : 
     111              : /**
     112              :  * Run the "DELETE transfer" CMD.
     113              :  *
     114              :  *
     115              :  * @param cls closure.
     116              :  * @param cmd command being run now.
     117              :  * @param is interpreter state.
     118              :  */
     119              : static void
     120            2 : delete_transfer_run (void *cls,
     121              :                      const struct TALER_TESTING_Command *cmd,
     122              :                      struct TALER_TESTING_Interpreter *is)
     123              : {
     124            2 :   struct DeleteTransferState *dts = cls;
     125              :   const struct TALER_TESTING_Command *ref;
     126              :   const uint64_t *tid;
     127              : 
     128            2 :   dts->is = is;
     129            2 :   ref = TALER_TESTING_interpreter_lookup_command (is,
     130              :                                                   dts->transfer_ref);
     131            2 :   if (NULL == ref)
     132              :   {
     133            0 :     GNUNET_break (0);
     134            0 :     TALER_TESTING_interpreter_fail (dts->is);
     135            0 :     return;
     136              :   }
     137            2 :   if (GNUNET_OK !=
     138            2 :       TALER_TESTING_get_trait_bank_row (ref,
     139              :                                         &tid))
     140              :   {
     141            0 :     GNUNET_break (0);
     142            0 :     TALER_TESTING_interpreter_fail (dts->is);
     143            0 :     return;
     144              :   }
     145            2 :   if (0 == tid)
     146              :   {
     147            0 :     GNUNET_break (0);
     148            0 :     TALER_TESTING_interpreter_fail (dts->is);
     149            0 :     return;
     150              :   }
     151            2 :   dts->tdh = TALER_MERCHANT_delete_private_transfer_create (
     152              :     TALER_TESTING_interpreter_get_context (is),
     153              :     dts->merchant_url,
     154              :     *tid);
     155              :   {
     156              :     enum TALER_ErrorCode ec;
     157              : 
     158            2 :     ec = TALER_MERCHANT_delete_private_transfer_start (dts->tdh,
     159              :                                                        &delete_transfer_cb,
     160              :                                                        dts);
     161            2 :     GNUNET_assert (TALER_EC_NONE == ec);
     162              :   }
     163              : }
     164              : 
     165              : 
     166              : /**
     167              :  * Free the state of a "DELETE transfer" CMD, and possibly
     168              :  * cancel a pending operation thereof.
     169              :  *
     170              :  * @param cls closure.
     171              :  * @param cmd command being run.
     172              :  */
     173              : static void
     174            2 : delete_transfer_cleanup (void *cls,
     175              :                          const struct TALER_TESTING_Command *cmd)
     176              : {
     177            2 :   struct DeleteTransferState *dts = cls;
     178              : 
     179            2 :   if (NULL != dts->tdh)
     180              :   {
     181            0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     182              :                 "DELETE /transfers/$TRANSFER_ID operation did not complete\n");
     183            0 :     TALER_MERCHANT_delete_private_transfer_cancel (dts->tdh);
     184              :   }
     185            2 :   GNUNET_free (dts);
     186            2 : }
     187              : 
     188              : 
     189              : struct TALER_TESTING_Command
     190            2 : TALER_TESTING_cmd_merchant_delete_transfer (const char *label,
     191              :                                             const char *merchant_url,
     192              :                                             const char *transfer_ref,
     193              :                                             unsigned int http_status)
     194              : {
     195              :   struct DeleteTransferState *dts;
     196              : 
     197            2 :   dts = GNUNET_new (struct DeleteTransferState);
     198            2 :   dts->merchant_url = merchant_url;
     199            2 :   dts->transfer_ref = transfer_ref;
     200            2 :   dts->http_status = http_status;
     201              :   {
     202            2 :     struct TALER_TESTING_Command cmd = {
     203              :       .cls = dts,
     204              :       .label = label,
     205              :       .run = &delete_transfer_run,
     206              :       .cleanup = &delete_transfer_cleanup
     207              :     };
     208              : 
     209            2 :     return cmd;
     210              :   }
     211              : }
        

Generated by: LCOV version 2.0-1