LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_get_otp_device.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 46 0
Test Date: 2025-11-13 17:46:01 Functions: 0.0 % 4 0

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   Copyright (C) 2022 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_get_otp_device.c
      21              :  * @brief command to test GET /otp-devices/$ID
      22              :  * @author Christian Grothoff
      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 "GET OTP device" CMD.
      33              :  */
      34              : struct GetOtpDeviceState
      35              : {
      36              : 
      37              :   /**
      38              :    * Handle for a "GET /otp-device/$ID" request.
      39              :    */
      40              :   struct TALER_MERCHANT_OtpDeviceGetHandle *igh;
      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              :    * ID of the otp_device to run GET for.
      54              :    */
      55              :   const char *otp_device_id;
      56              : 
      57              :   /**
      58              :    * Reference for a POST or PATCH /otp-devices CMD (optional).
      59              :    */
      60              :   const char *otp_device_reference;
      61              : 
      62              :   /**
      63              :    * Expected HTTP response code.
      64              :    */
      65              :   unsigned int http_status;
      66              : 
      67              : };
      68              : 
      69              : 
      70              : /**
      71              :  * Callback for a GET /otp-devices/$ID operation.
      72              :  *
      73              :  * @param cls closure for this function
      74              :  * @param tgr HTTP response details
      75              :  */
      76              : static void
      77            0 : get_otp_device_cb (void *cls,
      78              :                    const struct TALER_MERCHANT_OtpDeviceGetResponse *tgr)
      79              : {
      80            0 :   struct GetOtpDeviceState *gis = cls;
      81              :   const struct TALER_TESTING_Command *otp_device_cmd;
      82              : 
      83            0 :   gis->igh = NULL;
      84            0 :   if (gis->http_status != tgr->hr.http_status)
      85              :   {
      86            0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
      87              :                 "Unexpected response code %u (%d) to command %s\n",
      88              :                 tgr->hr.http_status,
      89              :                 (int) tgr->hr.ec,
      90              :                 TALER_TESTING_interpreter_get_current_label (gis->is));
      91            0 :     TALER_TESTING_interpreter_fail (gis->is);
      92            0 :     return;
      93              :   }
      94            0 :   switch (tgr->hr.http_status)
      95              :   {
      96            0 :   case MHD_HTTP_OK:
      97              :     {
      98              :       const char *expected_description;
      99              : 
     100            0 :       otp_device_cmd = TALER_TESTING_interpreter_lookup_command (
     101              :         gis->is,
     102              :         gis->otp_device_reference);
     103            0 :       if (GNUNET_OK !=
     104            0 :           TALER_TESTING_get_trait_otp_device_description (otp_device_cmd,
     105              :                                                           &expected_description))
     106            0 :         TALER_TESTING_interpreter_fail (gis->is);
     107            0 :       if (0 != strcmp (tgr->details.ok.otp_device_description,
     108              :                        expected_description))
     109              :       {
     110            0 :         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     111              :                     "OtpDevice description does not match\n");
     112            0 :         TALER_TESTING_interpreter_fail (gis->is);
     113            0 :         return;
     114              :       }
     115              :     }
     116            0 :     break;
     117            0 :   case MHD_HTTP_UNAUTHORIZED:
     118            0 :     break;
     119            0 :   case MHD_HTTP_NOT_FOUND:
     120            0 :     break;
     121            0 :   default:
     122            0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     123              :                 "Unhandled HTTP status.\n");
     124              :   }
     125            0 :   TALER_TESTING_interpreter_next (gis->is);
     126              : }
     127              : 
     128              : 
     129              : /**
     130              :  * Run the "GET /otp-device/$ID" CMD.
     131              :  *
     132              :  *
     133              :  * @param cls closure.
     134              :  * @param cmd command being run now.
     135              :  * @param is interpreter state.
     136              :  */
     137              : static void
     138            0 : get_otp_device_run (void *cls,
     139              :                     const struct TALER_TESTING_Command *cmd,
     140              :                     struct TALER_TESTING_Interpreter *is)
     141              : {
     142            0 :   struct GetOtpDeviceState *gis = cls;
     143              : 
     144            0 :   gis->is = is;
     145            0 :   gis->igh = TALER_MERCHANT_otp_device_get (
     146              :     TALER_TESTING_interpreter_get_context (is),
     147              :     gis->merchant_url,
     148              :     gis->otp_device_id,
     149              :     &get_otp_device_cb,
     150              :     gis);
     151            0 :   GNUNET_assert (NULL != gis->igh);
     152            0 : }
     153              : 
     154              : 
     155              : /**
     156              :  * Free the state of a "GET /otp-device/$ID" CMD, and possibly
     157              :  * cancel a pending operation thereof.
     158              :  *
     159              :  * @param cls closure.
     160              :  * @param cmd command being run.
     161              :  */
     162              : static void
     163            0 : get_otp_device_cleanup (void *cls,
     164              :                         const struct TALER_TESTING_Command *cmd)
     165              : {
     166            0 :   struct GetOtpDeviceState *gis = cls;
     167              : 
     168            0 :   if (NULL != gis->igh)
     169              :   {
     170            0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     171              :                 "GET /otp-devices/$ID operation did not complete\n");
     172            0 :     TALER_MERCHANT_otp_device_get_cancel (gis->igh);
     173              :   }
     174            0 :   GNUNET_free (gis);
     175            0 : }
     176              : 
     177              : 
     178              : struct TALER_TESTING_Command
     179            0 : TALER_TESTING_cmd_merchant_get_otp_device (
     180              :   const char *label,
     181              :   const char *merchant_url,
     182              :   const char *otp_device_id,
     183              :   unsigned int http_status,
     184              :   const char *otp_device_reference)
     185              : {
     186              :   struct GetOtpDeviceState *gis;
     187              : 
     188            0 :   gis = GNUNET_new (struct GetOtpDeviceState);
     189            0 :   gis->merchant_url = merchant_url;
     190            0 :   gis->otp_device_id = otp_device_id;
     191            0 :   gis->http_status = http_status;
     192            0 :   gis->otp_device_reference = otp_device_reference;
     193              :   {
     194            0 :     struct TALER_TESTING_Command cmd = {
     195              :       .cls = gis,
     196              :       .label = label,
     197              :       .run = &get_otp_device_run,
     198              :       .cleanup = &get_otp_device_cleanup
     199              :     };
     200              : 
     201            0 :     return cmd;
     202              :   }
     203              : }
     204              : 
     205              : 
     206              : /* end of testing_api_cmd_get_otp_device.c */
        

Generated by: LCOV version 2.0-1