LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_delete_reserve.c (source / functions) Hit Total Coverage
Test: GNU Taler merchant coverage report Lines: 0 50 0.0 %
Date: 2022-08-25 06:17:04 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2020 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_reserve.c
      21             :  * @brief command to test DELETE /reserves/$RESERVE_PUB
      22             :  * @author Jonathan Buchanan
      23             :  */
      24             : #include "platform.h"
      25             : #include <taler/taler_exchange_service.h>
      26             : #include <taler/taler_testing_lib.h>
      27             : #include "taler_merchant_service.h"
      28             : #include "taler_merchant_testing_lib.h"
      29             : 
      30             : 
      31             : /**
      32             :  * State of a "DELETE /reserves/$RESERVE_PUB" CMD.
      33             :  */
      34             : struct DeleteReserveState
      35             : {
      36             : 
      37             :   /**
      38             :    * Handle for a "DELETE reserve" request.
      39             :    */
      40             :   struct TALER_MERCHANT_ReserveDeleteHandle *rdh;
      41             : 
      42             :   /**
      43             :    * The interpreter state.
      44             :    */
      45             :   struct TALER_TESTING_Interpreter *is;
      46             : 
      47             :   /**
      48             :    * Base URL of the merchant serving the request.
      49             :    */
      50             :   const char *merchant_url;
      51             : 
      52             :   /**
      53             :    * Reference to a command that provides a reserve.
      54             :    */
      55             :   const char *reserve_reference;
      56             : 
      57             :   /**
      58             :    * Expected HTTP response code.
      59             :    */
      60             :   unsigned int http_status;
      61             : 
      62             :   /**
      63             :    * Use purge, not delete.
      64             :    */
      65             :   bool purge;
      66             : 
      67             : };
      68             : 
      69             : 
      70             : /**
      71             :  * Callback for a DELETE /reserves/$RESERVE_PUB operation.
      72             :  *
      73             :  * @param cls closure for this function
      74             :  * @param hr response being processed
      75             :  */
      76             : static void
      77           0 : delete_reserve_cb (void *cls,
      78             :                    const struct TALER_MERCHANT_HttpResponse *hr)
      79             : {
      80           0 :   struct DeleteReserveState *drs = cls;
      81             : 
      82           0 :   drs->rdh = NULL;
      83           0 :   if (drs->http_status != hr->http_status)
      84             :   {
      85           0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
      86             :                 "Unexpected response code %u (%d) to command %s\n",
      87             :                 hr->http_status,
      88             :                 (int) hr->ec,
      89             :                 TALER_TESTING_interpreter_get_current_label (drs->is));
      90           0 :     TALER_TESTING_interpreter_fail (drs->is);
      91           0 :     return;
      92             :   }
      93           0 :   switch (hr->http_status)
      94             :   {
      95           0 :   case MHD_HTTP_NO_CONTENT:
      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 reserve.\n",
     104             :                 hr->http_status);
     105             :   }
     106           0 :   TALER_TESTING_interpreter_next (drs->is);
     107             : }
     108             : 
     109             : 
     110             : /**
     111             :  * Run the "DELETE reserve" 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_reserve_run (void *cls,
     119             :                     const struct TALER_TESTING_Command *cmd,
     120             :                     struct TALER_TESTING_Interpreter *is)
     121             : {
     122           0 :   struct DeleteReserveState *drs = cls;
     123             :   const struct TALER_TESTING_Command *reserve_cmd;
     124             :   const struct TALER_ReservePublicKeyP *reserve_pub;
     125             : 
     126           0 :   reserve_cmd = TALER_TESTING_interpreter_lookup_command (
     127             :     is,
     128             :     drs->reserve_reference);
     129           0 :   if (GNUNET_OK !=
     130           0 :       TALER_TESTING_get_trait_reserve_pub (reserve_cmd,
     131             :                                            &reserve_pub))
     132           0 :     TALER_TESTING_FAIL (is);
     133             : 
     134           0 :   drs->is = is;
     135           0 :   if (drs->purge)
     136           0 :     drs->rdh = TALER_MERCHANT_reserve_purge (is->ctx,
     137             :                                              drs->merchant_url,
     138             :                                              reserve_pub,
     139             :                                              &delete_reserve_cb,
     140             :                                              drs);
     141             :   else
     142           0 :     drs->rdh = TALER_MERCHANT_reserve_delete (is->ctx,
     143             :                                               drs->merchant_url,
     144             :                                               reserve_pub,
     145             :                                               &delete_reserve_cb,
     146             :                                               drs);
     147             : 
     148           0 :   GNUNET_assert (NULL != drs->rdh);
     149             : }
     150             : 
     151             : 
     152             : /**
     153             :  * Free the state of a "DELETE reserve" CMD, and possibly
     154             :  * cancel a pending operation thereof.
     155             :  *
     156             :  * @param cls closure.
     157             :  * @param cmd command being run.
     158             :  */
     159             : static void
     160           0 : delete_reserve_cleanup (void *cls,
     161             :                         const struct TALER_TESTING_Command *cmd)
     162             : {
     163           0 :   struct DeleteReserveState *drs = cls;
     164             : 
     165           0 :   if (NULL != drs->rdh)
     166             :   {
     167           0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     168             :                 "DELETE /reserves/$RESERVE_PUB operation did not complete\n");
     169           0 :     TALER_MERCHANT_reserve_delete_cancel (drs->rdh);
     170             :   }
     171           0 :   GNUNET_free (drs);
     172           0 : }
     173             : 
     174             : 
     175             : struct TALER_TESTING_Command
     176           0 : TALER_TESTING_cmd_merchant_delete_reserve (const char *label,
     177             :                                            const char *merchant_url,
     178             :                                            const char *reserve_reference,
     179             :                                            unsigned int http_status)
     180             : {
     181             :   struct DeleteReserveState *drs;
     182             : 
     183           0 :   drs = GNUNET_new (struct DeleteReserveState);
     184           0 :   drs->merchant_url = merchant_url;
     185           0 :   drs->reserve_reference = reserve_reference;
     186           0 :   drs->http_status = http_status;
     187             :   {
     188           0 :     struct TALER_TESTING_Command cmd = {
     189             :       .cls = drs,
     190             :       .label = label,
     191             :       .run = &delete_reserve_run,
     192             :       .cleanup = &delete_reserve_cleanup
     193             :     };
     194             : 
     195           0 :     return cmd;
     196             :   }
     197             : }
     198             : 
     199             : 
     200             : struct TALER_TESTING_Command
     201           0 : TALER_TESTING_cmd_merchant_purge_reserve (const char *label,
     202             :                                           const char *merchant_url,
     203             :                                           const char *reserve_reference,
     204             :                                           unsigned int http_status)
     205             : {
     206             :   struct DeleteReserveState *drs;
     207             : 
     208           0 :   drs = GNUNET_new (struct DeleteReserveState);
     209           0 :   drs->merchant_url = merchant_url;
     210           0 :   drs->reserve_reference = reserve_reference;
     211           0 :   drs->http_status = http_status;
     212           0 :   drs->purge = true;
     213             :   {
     214           0 :     struct TALER_TESTING_Command cmd = {
     215             :       .cls = drs,
     216             :       .label = label,
     217             :       .run = &delete_reserve_run,
     218             :       .cleanup = &delete_reserve_cleanup
     219             :     };
     220             : 
     221           0 :     return cmd;
     222             :   }
     223             : }
     224             : 
     225             : 
     226             : /* end of testing_api_cmd_delete_reserve.c */

Generated by: LCOV version 1.14