LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_twister_exec_client.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 63 213 29.6 %
Date: 2021-08-30 06:43:37 Functions: 12 30 40.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   (C) 2018 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             : /**
      21             :  * @file testing_api_cmd_twister_exec_client.c
      22             :  * @brief test commands aimed to call the CLI twister client
      23             :  *        to drive its behaviour.
      24             :  * @author Christian Grothoff <christian@grothoff.org>
      25             :  * @author Marcello Stanisci
      26             :  */
      27             : 
      28             : #include "platform.h"
      29             : #include "taler_testing_lib.h"
      30             : #include "taler_twister_testing_lib.h"
      31             : 
      32             : 
      33             : /**
      34             :  * State for a "modify object" CMD.
      35             :  */
      36             : struct ModifyObjectState
      37             : {
      38             :   /**
      39             :    * Process handle for the twister CLI client.
      40             :    */
      41             :   struct GNUNET_OS_Process *proc;
      42             : 
      43             :   /**
      44             :    * Object-like notation to the object to delete.
      45             :    */
      46             :   const char *path;
      47             : 
      48             : 
      49             :   /**
      50             :    * Value to substitute to the original one.
      51             :    */
      52             :   const char *value;
      53             : 
      54             :   /**
      55             :    * Config file name to pass to the CLI client.
      56             :    */
      57             :   const char *config_filename;
      58             : };
      59             : 
      60             : 
      61             : /**
      62             :  * State for a "flip object" CMD.
      63             :  */
      64             : struct FlipObjectState
      65             : {
      66             :   /**
      67             :    * Process handle for the twister CLI client.
      68             :    */
      69             :   struct GNUNET_OS_Process *proc;
      70             : 
      71             :   /**
      72             :    * Object-like notation to the string-object to flip.
      73             :    */
      74             :   const char *path;
      75             : 
      76             :   /**
      77             :    * Config file name to pass to the CLI client.
      78             :    */
      79             :   const char *config_filename;
      80             : };
      81             : 
      82             : 
      83             : /**
      84             :  * State for a "delete object" CMD.
      85             :  */
      86             : struct DeleteObjectState
      87             : {
      88             :   /**
      89             :    * Process handle for the twister CLI client.
      90             :    */
      91             :   struct GNUNET_OS_Process *proc;
      92             : 
      93             :   /**
      94             :    * Object-like notation to the object to delete.
      95             :    */
      96             :   const char *path;
      97             : 
      98             :   /**
      99             :    * Config file name to pass to the CLI client.
     100             :    */
     101             :   const char *config_filename;
     102             : };
     103             : 
     104             : 
     105             : /**
     106             :  * State for a "malform request" CMD.
     107             :  */
     108             : struct MalformRequestState
     109             : {
     110             :   /**
     111             :    * Process handle for the twister CLI client.
     112             :    */
     113             :   struct GNUNET_OS_Process *proc;
     114             : 
     115             :   /**
     116             :    * Config file name to pass to the CLI client.
     117             :    */
     118             :   const char *config_filename;
     119             : };
     120             : 
     121             : 
     122             : /**
     123             :  * State for a "malform response" CMD.
     124             :  */
     125             : struct MalformResponseState
     126             : {
     127             :   /**
     128             :    * Process handle for the twister CLI client.
     129             :    */
     130             :   struct GNUNET_OS_Process *proc;
     131             : 
     132             :   /**
     133             :    * Config file name to pass to the CLI client.
     134             :    */
     135             :   const char *config_filename;
     136             : };
     137             : 
     138             : 
     139             : /**
     140             :  * State for a "hack response code" CMD.
     141             :  */
     142             : struct HackResponseCodeState
     143             : {
     144             :   /**
     145             :    * Process handle for the twister CLI client.
     146             :    */
     147             :   struct GNUNET_OS_Process *proc;
     148             : 
     149             :   /**
     150             :    * HTTP status code to substitute to the original one.
     151             :    */
     152             :   unsigned int http_status;
     153             : 
     154             :   /**
     155             :    * Config file name to pass to the CLI client.
     156             :    */
     157             :   const char *config_filename;
     158             : };
     159             : 
     160             : 
     161             : /**
     162             :  * Free the state from a "hack response code" CMD, and
     163             :  * possibly kill its process if it did not terminate yet.
     164             :  *
     165             :  * @param cls closure.
     166             :  * @param cmd the command being cleaned up.
     167             :  */
     168             : static void
     169           0 : hack_response_code_cleanup
     170             :   (void *cls,
     171             :   const struct TALER_TESTING_Command *cmd)
     172             : {
     173           0 :   struct HackResponseCodeState *hrcs = cls;
     174             : 
     175           0 :   if (NULL != hrcs->proc)
     176             :   {
     177           0 :     GNUNET_break (0 == GNUNET_OS_process_kill (hrcs->proc,
     178             :                                                SIGKILL));
     179           0 :     GNUNET_OS_process_wait (hrcs->proc);
     180           0 :     GNUNET_OS_process_destroy (hrcs->proc);
     181           0 :     hrcs->proc = NULL;
     182             :   }
     183           0 :   GNUNET_free (hrcs);
     184           0 : }
     185             : 
     186             : 
     187             : /**
     188             :  * Offer data internal to a "hack response code" CMD,
     189             :  * to other commands.
     190             :  *
     191             :  * @param cls closure
     192             :  * @param[out] ret result (could be anything)
     193             :  * @param trait name of the trait
     194             :  * @param index index number of the object to offer.
     195             :  * @return #GNUNET_OK on success
     196             :  */
     197             : static int
     198           0 : hack_response_code_traits (void *cls,
     199             :                            const void **ret,
     200             :                            const char *trait,
     201             :                            unsigned int index)
     202             : {
     203             : 
     204           0 :   struct HackResponseCodeState *hrcs = cls;
     205             :   struct TALER_TESTING_Trait traits[] = {
     206           0 :     TALER_TESTING_make_trait_process (0, &hrcs->proc),
     207           0 :     TALER_TESTING_trait_end ()
     208             :   };
     209             : 
     210           0 :   return TALER_TESTING_get_trait (traits,
     211             :                                   ret,
     212             :                                   trait,
     213             :                                   index);
     214             : }
     215             : 
     216             : 
     217             : /**
     218             :  * Run a "hack response code" CMD.
     219             :  *
     220             :  * @param cls closure.
     221             :  * @param cmd the command being run.
     222             :  * @param is the interpreter state.
     223             :  */
     224             : static void
     225           0 : hack_response_code_run (void *cls,
     226             :                         const struct TALER_TESTING_Command *cmd,
     227             :                         struct TALER_TESTING_Interpreter *is)
     228             : {
     229           0 :   struct HackResponseCodeState *hrcs = cls;
     230             :   char *http_status;
     231             : 
     232           0 :   GNUNET_asprintf (&http_status, "%u",
     233             :                    hrcs->http_status);
     234             : 
     235           0 :   hrcs->proc = GNUNET_OS_start_process (
     236             :     GNUNET_OS_INHERIT_STD_ALL,
     237             :     NULL, NULL, NULL,
     238             :     "taler-twister",
     239             :     "taler-twister",
     240             :     "-c", hrcs->config_filename,
     241             :     "--responsecode", http_status,
     242             :     NULL);
     243           0 :   if (NULL == hrcs->proc)
     244             :   {
     245           0 :     GNUNET_break (0);
     246           0 :     TALER_TESTING_interpreter_fail (is);
     247           0 :     return;
     248             :   }
     249           0 :   TALER_TESTING_wait_for_sigchld (is);
     250           0 :   GNUNET_free (http_status);
     251             : }
     252             : 
     253             : 
     254             : /**
     255             :  * Define a "hack response code" CMD.  This causes the next
     256             :  * response code (from the service proxied by the twister) to
     257             :  * be substituted with @a http_status.
     258             :  *
     259             :  * @param label command label
     260             :  * @param config_filename configuration filename.
     261             :  * @param http_status new response code to use
     262             :  * @return the command
     263             :  */
     264             : struct TALER_TESTING_Command
     265           0 : TALER_TESTING_cmd_hack_response_code (const char *label,
     266             :                                       const char *config_filename,
     267             :                                       unsigned int http_status)
     268             : {
     269             :   struct HackResponseCodeState *hrcs;
     270             : 
     271           0 :   hrcs = GNUNET_new (struct HackResponseCodeState);
     272           0 :   hrcs->http_status = http_status;
     273           0 :   hrcs->config_filename = config_filename;
     274             : 
     275           0 :   struct TALER_TESTING_Command cmd = {
     276             :     .label = label,
     277             :     .run = &hack_response_code_run,
     278             :     .cleanup = &hack_response_code_cleanup,
     279             :     .traits = &hack_response_code_traits,
     280             :     .cls = hrcs
     281             :   };
     282             : 
     283           0 :   return cmd;
     284             : }
     285             : 
     286             : 
     287             : /**
     288             :  * Free the state from a "delete object" CMD, and
     289             :  * possibly kill its process if it did not terminate yet.
     290             :  *
     291             :  * @param cls closure.
     292             :  * @param cmd the command being cleaned up.
     293             :  */
     294             : static void
     295           0 : delete_object_cleanup
     296             :   (void *cls,
     297             :   const struct TALER_TESTING_Command *cmd)
     298             : {
     299           0 :   struct DeleteObjectState *dos = cls;
     300             : 
     301           0 :   if (NULL != dos->proc)
     302             :   {
     303           0 :     GNUNET_break (0 == GNUNET_OS_process_kill (dos->proc,
     304             :                                                SIGKILL));
     305           0 :     GNUNET_OS_process_wait (dos->proc);
     306           0 :     GNUNET_OS_process_destroy (dos->proc);
     307           0 :     dos->proc = NULL;
     308             :   }
     309           0 :   GNUNET_free (dos);
     310           0 : }
     311             : 
     312             : 
     313             : /**
     314             :  * Offer data internal to a "delete object" CMD,
     315             :  * to other commands.
     316             :  *
     317             :  * @param cls closure
     318             :  * @param[out] ret result (could be anything)
     319             :  * @param trait name of the trait
     320             :  * @param index index number of the object to offer.
     321             :  * @return #GNUNET_OK on success
     322             :  */
     323             : static int
     324           0 : delete_object_traits (void *cls,
     325             :                       const void **ret,
     326             :                       const char *trait,
     327             :                       unsigned int index)
     328             : {
     329             : 
     330           0 :   struct DeleteObjectState *dos = cls;
     331             :   struct TALER_TESTING_Trait traits[] = {
     332           0 :     TALER_TESTING_make_trait_process (0, &dos->proc),
     333           0 :     TALER_TESTING_trait_end ()
     334             :   };
     335             : 
     336           0 :   return TALER_TESTING_get_trait (traits,
     337             :                                   ret,
     338             :                                   trait,
     339             :                                   index);
     340             : }
     341             : 
     342             : 
     343             : /**
     344             :  * Run a "delete object" CMD.
     345             :  *
     346             :  * @param cls closure.
     347             :  * @param cmd the command being run.
     348             :  * @param is the interpreter state.
     349             :  */
     350             : static void
     351           0 : delete_object_run (void *cls,
     352             :                    const struct TALER_TESTING_Command *cmd,
     353             :                    struct TALER_TESTING_Interpreter *is)
     354             : {
     355           0 :   struct DeleteObjectState *dos = cls;
     356             : 
     357           0 :   dos->proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
     358             :                                        NULL, NULL, NULL,
     359             :                                        "taler-twister",
     360             :                                        "taler-twister",
     361             :                                        "-c", dos->config_filename,
     362             :                                        "--deleteobject", dos->path,
     363             :                                        NULL);
     364           0 :   if (NULL == dos->proc)
     365             :   {
     366           0 :     GNUNET_break (0);
     367           0 :     TALER_TESTING_interpreter_fail (is);
     368           0 :     return;
     369             :   }
     370           0 :   TALER_TESTING_wait_for_sigchld (is);
     371             : }
     372             : 
     373             : 
     374             : /**
     375             :  * Free the state from a "modify object" CMD, and
     376             :  * possibly kill its process if it did not terminate yet.
     377             :  *
     378             :  * @param cls closure.
     379             :  * @param cmd the command being cleaned up.
     380             :  */
     381             : static void
     382           1 : modify_object_cleanup
     383             :   (void *cls,
     384             :   const struct TALER_TESTING_Command *cmd)
     385             : {
     386           1 :   struct ModifyObjectState *mos = cls;
     387             : 
     388           1 :   if (NULL != mos->proc)
     389             :   {
     390           0 :     GNUNET_break (0 == GNUNET_OS_process_kill (mos->proc,
     391             :                                                SIGKILL));
     392           0 :     GNUNET_OS_process_wait (mos->proc);
     393           0 :     GNUNET_OS_process_destroy (mos->proc);
     394           0 :     mos->proc = NULL;
     395             :   }
     396           1 :   GNUNET_free (mos);
     397           1 : }
     398             : 
     399             : 
     400             : /**
     401             :  * Offer data internal to a "modify object" CMD,
     402             :  * to other commands.
     403             :  *
     404             :  * @param cls closure
     405             :  * @param[out] ret result (could be anything)
     406             :  * @param trait name of the trait
     407             :  * @param index index number of the object to offer.
     408             :  * @return #GNUNET_OK on success
     409             :  */
     410             : static int
     411           1 : modify_object_traits (void *cls,
     412             :                       const void **ret,
     413             :                       const char *trait,
     414             :                       unsigned int index)
     415             : {
     416             : 
     417           1 :   struct ModifyObjectState *mos = cls;
     418             :   struct TALER_TESTING_Trait traits[] = {
     419           1 :     TALER_TESTING_make_trait_process (0, &mos->proc),
     420           1 :     TALER_TESTING_trait_end ()
     421             :   };
     422             : 
     423           1 :   return TALER_TESTING_get_trait (traits,
     424             :                                   ret,
     425             :                                   trait,
     426             :                                   index);
     427             : }
     428             : 
     429             : 
     430             : /**
     431             :  * Run a "modify object" CMD.  The "download fashion" of it.
     432             :  *
     433             :  * @param cls closure.
     434             :  * @param cmd the command being run.
     435             :  * @param is the interpreter state.
     436             :  */
     437             : static void
     438           0 : modify_object_dl_run (void *cls,
     439             :                       const struct TALER_TESTING_Command *cmd,
     440             :                       struct TALER_TESTING_Interpreter *is)
     441             : {
     442           0 :   struct ModifyObjectState *mos = cls;
     443             : 
     444           0 :   mos->proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
     445             :                                        NULL, NULL, NULL,
     446             :                                        "taler-twister",
     447             :                                        "taler-twister",
     448             :                                        "-c", mos->config_filename,
     449             :                                        "-m", mos->path,
     450             :                                        "--value", mos->value,
     451             :                                        NULL);
     452           0 :   if (NULL == mos->proc)
     453             :   {
     454           0 :     GNUNET_break (0);
     455           0 :     TALER_TESTING_interpreter_fail (is);
     456           0 :     return;
     457             :   }
     458           0 :   TALER_TESTING_wait_for_sigchld (is);
     459             : }
     460             : 
     461             : 
     462             : /**
     463             :  * Run a "modify object" CMD, the "upload fashion" of it.
     464             :  *
     465             :  * @param cls closure.
     466             :  * @param cmd the command being run.
     467             :  * @param is the interpreter state.
     468             :  */
     469             : static void
     470           0 : modify_object_ul_run (void *cls,
     471             :                       const struct TALER_TESTING_Command *cmd,
     472             :                       struct TALER_TESTING_Interpreter *is)
     473             : {
     474           0 :   struct ModifyObjectState *mos = cls;
     475             : 
     476           0 :   mos->proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
     477             :                                        NULL, NULL, NULL,
     478             :                                        "taler-twister",
     479             :                                        "taler-twister",
     480             :                                        "-c", mos->config_filename,
     481             :                                        "-X", mos->path,
     482             :                                        "--value", mos->value,
     483             :                                        NULL);
     484           0 :   if (NULL == mos->proc)
     485             :   {
     486           0 :     GNUNET_break (0);
     487           0 :     TALER_TESTING_interpreter_fail (is);
     488           0 :     return;
     489             :   }
     490           0 :   TALER_TESTING_wait_for_sigchld (is);
     491             : }
     492             : 
     493             : 
     494             : /**
     495             :  * Run a "modify header" CMD
     496             :  *
     497             :  * @param cls closure.
     498             :  * @param cmd the command being run.
     499             :  * @param is the interpreter state.
     500             :  */
     501             : static void
     502           1 : modify_header_dl_run (void *cls,
     503             :                       const struct TALER_TESTING_Command *cmd,
     504             :                       struct TALER_TESTING_Interpreter *is)
     505             : {
     506           1 :   struct ModifyObjectState *mos = cls;
     507             : 
     508           1 :   mos->proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
     509             :                                        NULL, NULL, NULL,
     510             :                                        "taler-twister",
     511             :                                        "taler-twister",
     512             :                                        "-H", mos->path,
     513             :                                        "--value", mos->value,
     514             :                                        "-c", mos->config_filename,
     515             :                                        NULL);
     516           1 :   if (NULL == mos->proc)
     517             :   {
     518           0 :     GNUNET_break (0);
     519           0 :     TALER_TESTING_interpreter_fail (is);
     520           0 :     return;
     521             :   }
     522           1 :   TALER_TESTING_wait_for_sigchld (is);
     523             : }
     524             : 
     525             : 
     526             : /**
     527             :  * Create a "delete object" CMD.  This command deletes
     528             :  * the JSON object pointed by @a path.
     529             :  *
     530             :  * @param label command label
     531             :  * @param config_filename configuration filename.
     532             :  * @param path object-like path notation to point the object
     533             :  *        to delete.
     534             :  * @return the command
     535             :  */
     536             : struct TALER_TESTING_Command
     537           0 : TALER_TESTING_cmd_delete_object (const char *label,
     538             :                                  const char *config_filename,
     539             :                                  const char *path)
     540             : {
     541             :   struct DeleteObjectState *dos;
     542             : 
     543           0 :   dos = GNUNET_new (struct DeleteObjectState);
     544           0 :   dos->path = path;
     545           0 :   dos->config_filename = config_filename;
     546             : 
     547           0 :   struct TALER_TESTING_Command cmd = {
     548             :     .label = label,
     549             :     .run = &delete_object_run,
     550             :     .cleanup = &delete_object_cleanup,
     551             :     .traits = &delete_object_traits,
     552             :     .cls = dos
     553             :   };
     554             : 
     555           0 :   return cmd;
     556             : }
     557             : 
     558             : 
     559             : /**
     560             :  * Free the state from a "flip object" CMD, and
     561             :  * possibly kill its process if it did not terminate yet.
     562             :  *
     563             :  * @param cls closure.
     564             :  * @param cmd the command being cleaned up.
     565             :  */
     566             : static void
     567           2 : flip_object_cleanup
     568             :   (void *cls,
     569             :   const struct TALER_TESTING_Command *cmd)
     570             : {
     571           2 :   struct FlipObjectState *fos = cls;
     572             : 
     573           2 :   if (NULL != fos->proc)
     574             :   {
     575           0 :     GNUNET_break (0 == GNUNET_OS_process_kill (fos->proc,
     576             :                                                SIGKILL));
     577           0 :     GNUNET_OS_process_wait (fos->proc);
     578           0 :     GNUNET_OS_process_destroy (fos->proc);
     579           0 :     fos->proc = NULL;
     580             :   }
     581           2 :   GNUNET_free (fos);
     582           2 : }
     583             : 
     584             : 
     585             : /**
     586             :  * Offer data internal to a "flip object" CMD,
     587             :  * to other commands.
     588             :  *
     589             :  * @param cls closure
     590             :  * @param[out] ret result (could be anything)
     591             :  * @param trait name of the trait
     592             :  * @param index index number of the object to offer.
     593             :  * @return #GNUNET_OK on success
     594             :  */
     595             : static int
     596           2 : flip_object_traits (void *cls,
     597             :                     const void **ret,
     598             :                     const char *trait,
     599             :                     unsigned int index)
     600             : {
     601             : 
     602           2 :   struct FlipObjectState *fos = cls;
     603             :   struct TALER_TESTING_Trait traits[] = {
     604           2 :     TALER_TESTING_make_trait_process (0, &fos->proc),
     605           2 :     TALER_TESTING_trait_end ()
     606             :   };
     607             : 
     608           2 :   return TALER_TESTING_get_trait (traits,
     609             :                                   ret,
     610             :                                   trait,
     611             :                                   index);
     612             : }
     613             : 
     614             : 
     615             : /**
     616             :  * Run a "flip object" CMD, the upload fashion of it.
     617             :  *
     618             :  * @param cls closure.
     619             :  * @param cmd the command being run.
     620             :  * @param is the interpreter state.
     621             :  */
     622             : static void
     623           2 : flip_upload_run (void *cls,
     624             :                  const struct TALER_TESTING_Command *cmd,
     625             :                  struct TALER_TESTING_Interpreter *is)
     626             : {
     627           2 :   struct FlipObjectState *fos = cls;
     628             : 
     629           2 :   fos->proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
     630             :                                        NULL, NULL, NULL,
     631             :                                        "taler-twister",
     632             :                                        "taler-twister",
     633             :                                        "-c", fos->config_filename,
     634             :                                        "--flip-ul", fos->path,
     635             :                                        NULL);
     636           2 :   if (NULL == fos->proc)
     637             :   {
     638           0 :     GNUNET_break (0);
     639           0 :     TALER_TESTING_interpreter_fail (is);
     640           0 :     return;
     641             :   }
     642           2 :   TALER_TESTING_wait_for_sigchld (is);
     643             : }
     644             : 
     645             : 
     646             : /**
     647             :  * Run a "flip object" CMD, the download fashion of it.
     648             :  *
     649             :  * @param cls closure.
     650             :  * @param cmd the command being run.
     651             :  * @param is the interpreter state.
     652             :  */
     653             : static void
     654           0 : flip_download_run (void *cls,
     655             :                    const struct TALER_TESTING_Command *cmd,
     656             :                    struct TALER_TESTING_Interpreter *is)
     657             : {
     658           0 :   struct FlipObjectState *fos = cls;
     659             : 
     660           0 :   fos->proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
     661             :                                        NULL, NULL, NULL,
     662             :                                        "taler-twister",
     663             :                                        "taler-twister",
     664             :                                        "-c", fos->config_filename,
     665             :                                        "--flip-dl", fos->path,
     666             :                                        NULL);
     667           0 :   if (NULL == fos->proc)
     668             :   {
     669           0 :     GNUNET_break (0);
     670           0 :     TALER_TESTING_interpreter_fail (is);
     671           0 :     return;
     672             :   }
     673           0 :   TALER_TESTING_wait_for_sigchld (is);
     674             : }
     675             : 
     676             : 
     677             : /**
     678             :  * Define a "flip object" command, for objects to upload.
     679             :  *
     680             :  * @param label command label
     681             :  * @param config_filename configuration filename.
     682             :  * @param path object-like path notation to point the object
     683             :  *        to flip.
     684             :  * @return the command
     685             :  */
     686             : struct TALER_TESTING_Command
     687           2 : TALER_TESTING_cmd_flip_upload (const char *label,
     688             :                                const char *config_filename,
     689             :                                const char *path)
     690             : {
     691             :   struct FlipObjectState *dos;
     692             : 
     693           2 :   dos = GNUNET_new (struct FlipObjectState);
     694           2 :   dos->path = path;
     695           2 :   dos->config_filename = config_filename;
     696             : 
     697           2 :   struct TALER_TESTING_Command cmd = {
     698             :     .label = label,
     699             :     .run = &flip_upload_run,
     700             :     .cleanup = &flip_object_cleanup,
     701             :     .traits = &flip_object_traits,
     702             :     .cls = dos
     703             :   };
     704             : 
     705           2 :   return cmd;
     706             : }
     707             : 
     708             : 
     709             : /**
     710             :  * Define a "flip object" command, for objects to download.
     711             :  *
     712             :  * @param label command label
     713             :  * @param config_filename configuration filename.
     714             :  * @param path object-like path notation to point the object
     715             :  *        to flip.
     716             :  * @return the command
     717             :  */
     718             : struct TALER_TESTING_Command
     719           0 : TALER_TESTING_cmd_flip_download (const char *label,
     720             :                                  const char *config_filename,
     721             :                                  const char *path)
     722             : {
     723             :   struct FlipObjectState *dos;
     724             : 
     725           0 :   dos = GNUNET_new (struct FlipObjectState);
     726           0 :   dos->path = path;
     727           0 :   dos->config_filename = config_filename;
     728             : 
     729           0 :   struct TALER_TESTING_Command cmd = {
     730             :     .label = label,
     731             :     .run = &flip_download_run,
     732             :     .cleanup = &flip_object_cleanup,
     733             :     .traits = &flip_object_traits,
     734             :     .cls = dos
     735             :   };
     736             : 
     737           0 :   return cmd;
     738             : }
     739             : 
     740             : 
     741             : /**
     742             :  * Free the state from a "malform request" CMD, and
     743             :  * possibly kill its process if it did not terminate yet.
     744             :  *
     745             :  * @param cls closure.
     746             :  * @param cmd the command being cleaned up.
     747             :  */
     748             : static void
     749           0 : malform_request_cleanup (void *cls,
     750             :                          const struct TALER_TESTING_Command *cmd)
     751             : {
     752           0 :   struct MalformRequestState *mrs = cls;
     753             : 
     754           0 :   if (NULL != mrs->proc)
     755             :   {
     756           0 :     GNUNET_break (0 == GNUNET_OS_process_kill (mrs->proc,
     757             :                                                SIGKILL));
     758           0 :     GNUNET_OS_process_wait (mrs->proc);
     759           0 :     GNUNET_OS_process_destroy (mrs->proc);
     760           0 :     mrs->proc = NULL;
     761             :   }
     762           0 :   GNUNET_free (mrs);
     763           0 : }
     764             : 
     765             : 
     766             : /**
     767             :  * Offer data internal to a "malform request" CMD,
     768             :  * to other commands.
     769             :  *
     770             :  * @param cls closure
     771             :  * @param[out] ret result (could be anything)
     772             :  * @param trait name of the trait
     773             :  * @param index index number of the object to offer.
     774             :  * @return #GNUNET_OK on success
     775             :  */
     776             : static int
     777           0 : malform_request_traits (void *cls,
     778             :                         const void **ret,
     779             :                         const char *trait,
     780             :                         unsigned int index)
     781             : {
     782           0 :   struct MalformRequestState *mrs = cls;
     783             :   struct TALER_TESTING_Trait traits[] = {
     784           0 :     TALER_TESTING_make_trait_process (0, &mrs->proc),
     785           0 :     TALER_TESTING_trait_end ()
     786             :   };
     787             : 
     788           0 :   return TALER_TESTING_get_trait (traits,
     789             :                                   ret,
     790             :                                   trait,
     791             :                                   index);
     792             : }
     793             : 
     794             : 
     795             : /**
     796             :  * Run a "malform request" CMD.
     797             :  *
     798             :  * @param cls closure.
     799             :  * @param cmd the command being run.
     800             :  * @param is the interpreter state.
     801             :  */
     802             : static void
     803           0 : malform_request_run (void *cls,
     804             :                      const struct TALER_TESTING_Command *cmd,
     805             :                      struct TALER_TESTING_Interpreter *is)
     806             : {
     807           0 :   struct MalformRequestState *mrs = cls;
     808             : 
     809           0 :   mrs->proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
     810             :                                        NULL, NULL, NULL,
     811             :                                        "taler-twister",
     812             :                                        "taler-twister",
     813             :                                        "-c", mrs->config_filename,
     814             :                                        "--malformupload",
     815             :                                        NULL);
     816           0 :   if (NULL == mrs->proc)
     817             :   {
     818           0 :     GNUNET_break (0);
     819           0 :     TALER_TESTING_interpreter_fail (is);
     820           0 :     return;
     821             :   }
     822           0 :   TALER_TESTING_wait_for_sigchld (is);
     823             : }
     824             : 
     825             : 
     826             : /**
     827             :  * Free the state from a "malform response" CMD, and
     828             :  * possibly kill its process if it did not terminate yet.
     829             :  *
     830             :  * @param cls closure.
     831             :  * @param cmd the command being cleaned up.
     832             :  */
     833             : static void
     834           2 : malform_response_cleanup
     835             :   (void *cls,
     836             :   const struct TALER_TESTING_Command *cmd)
     837             : {
     838           2 :   struct MalformResponseState *mrs = cls;
     839             : 
     840           2 :   if (NULL != mrs->proc)
     841             :   {
     842           0 :     GNUNET_break (0 == GNUNET_OS_process_kill (mrs->proc,
     843             :                                                SIGKILL));
     844           0 :     GNUNET_OS_process_wait (mrs->proc);
     845           0 :     GNUNET_OS_process_destroy (mrs->proc);
     846           0 :     mrs->proc = NULL;
     847             :   }
     848           2 :   GNUNET_free (mrs);
     849           2 : }
     850             : 
     851             : 
     852             : /**
     853             :  * Offer data internal to a "malform response" CMD,
     854             :  * to other commands.
     855             :  *
     856             :  * @param cls closure
     857             :  * @param[out] ret result (could be anything)
     858             :  * @param trait name of the trait
     859             :  * @param index index number of the object to offer.
     860             :  * @return #GNUNET_OK on success
     861             :  */
     862             : static int
     863           2 : malform_response_traits (void *cls,
     864             :                          const void **ret,
     865             :                          const char *trait,
     866             :                          unsigned int index)
     867             : {
     868           2 :   struct MalformResponseState *mrs = cls;
     869             :   struct TALER_TESTING_Trait traits[] = {
     870           2 :     TALER_TESTING_make_trait_process (0, &mrs->proc),
     871           2 :     TALER_TESTING_trait_end ()
     872             :   };
     873             : 
     874           2 :   return TALER_TESTING_get_trait (traits,
     875             :                                   ret,
     876             :                                   trait,
     877             :                                   index);
     878             : }
     879             : 
     880             : 
     881             : /**
     882             :  * Run a "malform response" CMD.
     883             :  *
     884             :  * @param cls closure.
     885             :  * @param cmd the command being run.
     886             :  * @param is the interpreter state.
     887             :  */
     888             : static void
     889           2 : malform_response_run (void *cls,
     890             :                       const struct TALER_TESTING_Command *cmd,
     891             :                       struct TALER_TESTING_Interpreter *is)
     892             : {
     893           2 :   struct MalformResponseState *mrs = cls;
     894             : 
     895           2 :   mrs->proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
     896             :                                        NULL, NULL, NULL,
     897             :                                        "taler-twister",
     898             :                                        "taler-twister",
     899             :                                        "-c", mrs->config_filename,
     900             :                                        "--malform",
     901             :                                        NULL);
     902           2 :   if (NULL == mrs->proc)
     903             :   {
     904           0 :     GNUNET_break (0);
     905           0 :     TALER_TESTING_interpreter_fail (is);
     906           0 :     return;
     907             :   }
     908           2 :   TALER_TESTING_wait_for_sigchld (is);
     909             : }
     910             : 
     911             : 
     912             : /**
     913             :  * Create a "malform request" CMD.  This command makes the
     914             :  * next request randomly malformed (by truncating it).
     915             :  *
     916             :  * @param label command label
     917             :  * @param config_filename configuration filename.
     918             :  * @return the command
     919             :  */
     920             : struct TALER_TESTING_Command
     921           0 : TALER_TESTING_cmd_malform_request (const char *label,
     922             :                                    const char *config_filename)
     923             : {
     924             :   struct MalformRequestState *mrs;
     925             : 
     926           0 :   mrs = GNUNET_new (struct MalformRequestState);
     927           0 :   mrs->config_filename = config_filename;
     928             : 
     929           0 :   struct TALER_TESTING_Command cmd = {
     930             :     .label = label,
     931             :     .run = &malform_request_run,
     932             :     .cleanup = &malform_request_cleanup,
     933             :     .traits = &malform_request_traits,
     934             :     .cls = mrs
     935             :   };
     936             : 
     937           0 :   return cmd;
     938             : }
     939             : 
     940             : 
     941             : /**
     942             :  * Create a "malform response" CMD.  This command makes
     943             :  * the next response randomly malformed (by truncating it).
     944             :  *
     945             :  * @param label command label
     946             :  * @param config_filename configuration filename.
     947             :  *
     948             :  * @return the command
     949             :  */
     950             : struct TALER_TESTING_Command
     951           2 : TALER_TESTING_cmd_malform_response (const char *label,
     952             :                                     const char *config_filename)
     953             : {
     954             :   struct MalformResponseState *mrs;
     955             : 
     956           2 :   mrs = GNUNET_new (struct MalformResponseState);
     957           2 :   mrs->config_filename = config_filename;
     958             : 
     959           2 :   struct TALER_TESTING_Command cmd = {
     960             :     .label = label,
     961             :     .run = &malform_response_run,
     962             :     .cleanup = &malform_response_cleanup,
     963             :     .traits = &malform_response_traits,
     964             :     .cls = mrs
     965             :   };
     966             : 
     967           2 :   return cmd;
     968             : 
     969             : }
     970             : 
     971             : 
     972             : /**
     973             :  * Create a "modify object" CMD.  This command instructs
     974             :  * the twister to modify the next object that is downloaded
     975             :  * from the proxied service.
     976             :  *
     977             :  * @param label command label
     978             :  * @param config_filename configuration filename.
     979             :  * @param path object-like path notation to point the object
     980             :  *        to modify.
     981             :  * @param value value to put as the object's.
     982             :  *
     983             :  * @return the command
     984             :  */
     985             : struct TALER_TESTING_Command
     986           0 : TALER_TESTING_cmd_modify_object_dl (const char *label,
     987             :                                     const char *config_filename,
     988             :                                     const char *path,
     989             :                                     const char *value)
     990             : {
     991             :   struct ModifyObjectState *mos;
     992             : 
     993           0 :   mos = GNUNET_new (struct ModifyObjectState);
     994           0 :   mos->path = path;
     995           0 :   mos->value = value;
     996           0 :   mos->config_filename = config_filename;
     997             : 
     998           0 :   struct TALER_TESTING_Command cmd = {
     999             :     .label = label,
    1000             :     .run = &modify_object_dl_run,
    1001             :     .cleanup = &modify_object_cleanup,
    1002             :     .traits = &modify_object_traits,
    1003             :     .cls = mos
    1004             :   };
    1005             : 
    1006           0 :   return cmd;
    1007             : }
    1008             : 
    1009             : 
    1010             : /**
    1011             :  * Create a "modify object" CMD.  This command instructs
    1012             :  * the twister to modify the next object that will be uploaded
    1013             :  * to the proxied service.
    1014             :  *
    1015             :  * @param label command label
    1016             :  * @param config_filename configuration filename.
    1017             :  * @param path object-like path notation pointing the object
    1018             :  *        to modify.
    1019             :  * @param value value to put as the object's.
    1020             :  * @return the command
    1021             :  */
    1022             : struct TALER_TESTING_Command
    1023           0 : TALER_TESTING_cmd_modify_object_ul (const char *label,
    1024             :                                     const char *config_filename,
    1025             :                                     const char *path,
    1026             :                                     const char *value)
    1027             : {
    1028             :   struct ModifyObjectState *mos;
    1029             : 
    1030           0 :   mos = GNUNET_new (struct ModifyObjectState);
    1031           0 :   mos->path = path;
    1032           0 :   mos->value = value;
    1033           0 :   mos->config_filename = config_filename;
    1034             : 
    1035           0 :   struct TALER_TESTING_Command cmd = {
    1036             :     .label = label,
    1037             :     .run = &modify_object_ul_run,
    1038             :     .cleanup = &modify_object_cleanup,
    1039             :     .traits = &modify_object_traits,
    1040             :     .cls = mos
    1041             :   };
    1042             : 
    1043           0 :   return cmd;
    1044             : }
    1045             : 
    1046             : 
    1047             : /**
    1048             :  * Create a "modify header" CMD.  This command instructs
    1049             :  * the twister to modify a header in the next HTTP response.
    1050             :  *
    1051             :  * @param label command label
    1052             :  * @param config_filename configuration filename.
    1053             :  * @param path identifies the location to modify
    1054             :  * @param value value to set the header to.
    1055             :  * @return the command
    1056             :  */
    1057             : struct TALER_TESTING_Command
    1058           1 : TALER_TESTING_cmd_modify_header_dl (const char *label,
    1059             :                                     const char *config_filename,
    1060             :                                     const char *path,
    1061             :                                     const char *value)
    1062             : {
    1063             :   struct ModifyObjectState *mos;
    1064             : 
    1065           1 :   mos = GNUNET_new (struct ModifyObjectState);
    1066           1 :   mos->path = path;
    1067           1 :   mos->value = value;
    1068           1 :   mos->config_filename = config_filename;
    1069             : 
    1070           1 :   struct TALER_TESTING_Command cmd = {
    1071             :     .label = label,
    1072             :     .run = &modify_header_dl_run,
    1073             :     .cleanup = &modify_object_cleanup,
    1074             :     .traits = &modify_object_traits,
    1075             :     .cls = mos
    1076             :   };
    1077             : 
    1078           1 :   return cmd;
    1079             : }
    1080             : 
    1081             : 
    1082             : /* end of testing_api_cmd_exec_client.c */

Generated by: LCOV version 1.14