LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_change_auth.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 0 30 0.0 %
Date: 2021-08-30 06:43:37 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   (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 testing/testing_api_cmd_change_auth.c
      21             :  * @brief command(s) to change CURL context authorization header
      22             :  * @author Christian Grothoff
      23             :  */
      24             : #include "platform.h"
      25             : #include "taler_json_lib.h"
      26             : #include <gnunet/gnunet_curl_lib.h>
      27             : #include "taler_testing_lib.h"
      28             : 
      29             : 
      30             : /**
      31             :  * State for a "authchange" CMD.
      32             :  */
      33             : struct AuthchangeState
      34             : {
      35             : 
      36             :   /**
      37             :    * What is the new authorization token to send?
      38             :    */
      39             :   const char *auth_token;
      40             : };
      41             : 
      42             : 
      43             : /**
      44             :  * No traits to offer, just provide a stub to be called when
      45             :  * some CMDs iterates through the list of all the commands.
      46             :  *
      47             :  * @param cls closure.
      48             :  * @param[out] ret result.
      49             :  * @param trait name of the trait.
      50             :  * @param index index number of the trait to return.
      51             :  * @return #GNUNET_OK on success.
      52             :  */
      53             : static int
      54           0 : authchange_traits (void *cls,
      55             :                    const void **ret,
      56             :                    const char *trait,
      57             :                    unsigned int index)
      58             : {
      59             :   (void) cls;
      60             :   (void) ret;
      61             :   (void) trait;
      62             :   (void) index;
      63           0 :   return GNUNET_NO;
      64             : }
      65             : 
      66             : 
      67             : /**
      68             :  * Run the command.
      69             :  *
      70             :  * @param cls closure.
      71             :  * @param cmd the command to execute.
      72             :  * @param is the interpreter state.
      73             :  */
      74             : static void
      75           0 : authchange_run (void *cls,
      76             :                 const struct TALER_TESTING_Command *cmd,
      77             :                 struct TALER_TESTING_Interpreter *is)
      78             : {
      79           0 :   struct AuthchangeState *ss = cls;
      80             : 
      81           0 :   if (NULL != is->ctx)
      82             :   {
      83           0 :     GNUNET_CURL_fini (is->ctx);
      84           0 :     is->ctx = NULL;
      85             :   }
      86           0 :   if (NULL != is->rc)
      87             :   {
      88           0 :     GNUNET_CURL_gnunet_rc_destroy (is->rc);
      89           0 :     is->rc = NULL;
      90             :   }
      91           0 :   is->ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
      92           0 :                               &is->rc);
      93           0 :   GNUNET_CURL_enable_async_scope_header (is->ctx,
      94             :                                          "Taler-Correlation-Id");
      95           0 :   GNUNET_assert (NULL != is->ctx);
      96           0 :   is->rc = GNUNET_CURL_gnunet_rc_create (is->ctx);
      97           0 :   if (NULL != ss->auth_token)
      98             :   {
      99             :     char *authorization;
     100             : 
     101           0 :     GNUNET_asprintf (&authorization,
     102             :                      "%s: %s",
     103             :                      MHD_HTTP_HEADER_AUTHORIZATION,
     104             :                      ss->auth_token);
     105           0 :     GNUNET_assert (GNUNET_OK ==
     106             :                    GNUNET_CURL_append_header (is->ctx,
     107             :                                               authorization));
     108           0 :     GNUNET_free (authorization);
     109             :   }
     110           0 :   TALER_TESTING_interpreter_next (is);
     111           0 : }
     112             : 
     113             : 
     114             : /**
     115             :  * Cleanup the state from a "authchange" CMD.
     116             :  *
     117             :  * @param cls closure.
     118             :  * @param cmd the command which is being cleaned up.
     119             :  */
     120             : static void
     121           0 : authchange_cleanup (void *cls,
     122             :                     const struct TALER_TESTING_Command *cmd)
     123             : {
     124           0 :   struct AuthchangeState *ss = cls;
     125             : 
     126             :   (void) cmd;
     127           0 :   GNUNET_free (ss);
     128           0 : }
     129             : 
     130             : 
     131             : struct TALER_TESTING_Command
     132           0 : TALER_TESTING_cmd_set_authorization (const char *label,
     133             :                                      const char *auth_token)
     134             : {
     135             :   struct AuthchangeState *ss;
     136             : 
     137           0 :   ss = GNUNET_new (struct AuthchangeState);
     138           0 :   ss->auth_token = auth_token;
     139             : 
     140             :   {
     141           0 :     struct TALER_TESTING_Command cmd = {
     142             :       .cls = ss,
     143             :       .label = label,
     144             :       .run = &authchange_run,
     145             :       .cleanup = &authchange_cleanup,
     146             :       .traits = &authchange_traits
     147             :     };
     148             : 
     149           0 :     return cmd;
     150             :   }
     151             : }
     152             : 
     153             : 
     154             : /* end of testing_api_cmd_change_auth.c  */

Generated by: LCOV version 1.14