quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

unit1304.c (6160B)


      1 /***************************************************************************
      2  *                                  _   _ ____  _
      3  *  Project                     ___| | | |  _ \| |
      4  *                             / __| | | | |_) | |
      5  *                            | (__| |_| |  _ <| |___
      6  *                             \___|\___/|_| \_\_____|
      7  *
      8  * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
      9  *
     10  * This software is licensed as described in the file COPYING, which
     11  * you should have received as part of this distribution. The terms
     12  * are also available at https://curl.se/docs/copyright.html.
     13  *
     14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
     15  * copies of the Software, and permit persons to whom the Software is
     16  * furnished to do so, under the terms of the COPYING file.
     17  *
     18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
     19  * KIND, either express or implied.
     20  *
     21  * SPDX-License-Identifier: curl
     22  *
     23  ***************************************************************************/
     24 #include "unitcheck.h"
     25 #include "netrc.h"
     26 #include "memdebug.h" /* LAST include file */
     27 
     28 #ifndef CURL_DISABLE_NETRC
     29 
     30 static void t1304_stop(char **password, char **login)
     31 {
     32   Curl_safefree(*password);
     33   Curl_safefree(*login);
     34 }
     35 
     36 static CURLcode test_unit1304(char *arg)
     37 {
     38   char *login = NULL;
     39   char *password = NULL;
     40 
     41   UNITTEST_BEGIN_SIMPLE
     42 
     43   int result;
     44   struct store_netrc store;
     45 
     46   /*
     47    * Test a non existent host in our netrc file.
     48    */
     49   Curl_netrc_init(&store);
     50   result = Curl_parsenetrc(&store,
     51                            "test.example.com", &login, &password, arg);
     52   fail_unless(result == 1, "Host not found should return 1");
     53   abort_unless(password == NULL, "password did not return NULL!");
     54   abort_unless(login == NULL, "user did not return NULL!");
     55   Curl_netrc_cleanup(&store);
     56 
     57   /*
     58    * Test a non existent login in our netrc file.
     59    */
     60   login = (char *)CURL_UNCONST("me");
     61   Curl_netrc_init(&store);
     62   result = Curl_parsenetrc(&store,
     63                            "example.com", &login, &password, arg);
     64   fail_unless(result == 0, "Host should have been found");
     65   abort_unless(password == NULL, "password is not NULL!");
     66   Curl_netrc_cleanup(&store);
     67 
     68   /*
     69    * Test a non existent login and host in our netrc file.
     70    */
     71   login = (char *)CURL_UNCONST("me");
     72   Curl_netrc_init(&store);
     73   result = Curl_parsenetrc(&store,
     74                            "test.example.com", &login, &password, arg);
     75   fail_unless(result == 1, "Host not found should return 1");
     76   abort_unless(password == NULL, "password is not NULL!");
     77   Curl_netrc_cleanup(&store);
     78 
     79   /*
     80    * Test a non existent login (substring of an existing one) in our
     81    * netrc file.
     82    */
     83   login = (char *)CURL_UNCONST("admi");
     84   Curl_netrc_init(&store);
     85   result = Curl_parsenetrc(&store,
     86                            "example.com", &login, &password, arg);
     87   fail_unless(result == 0, "Host should have been found");
     88   abort_unless(password == NULL, "password is not NULL!");
     89   Curl_netrc_cleanup(&store);
     90 
     91   /*
     92    * Test a non existent login (superstring of an existing one)
     93    * in our netrc file.
     94    */
     95   login = (char *)CURL_UNCONST("adminn");
     96   Curl_netrc_init(&store);
     97   result = Curl_parsenetrc(&store,
     98                            "example.com", &login, &password, arg);
     99   fail_unless(result == 0, "Host should have been found");
    100   abort_unless(password == NULL, "password is not NULL!");
    101   Curl_netrc_cleanup(&store);
    102 
    103   /*
    104    * Test for the first existing host in our netrc file
    105    * with login[0] = 0.
    106    */
    107   login = NULL;
    108   Curl_netrc_init(&store);
    109   result = Curl_parsenetrc(&store,
    110                            "example.com", &login, &password, arg);
    111   fail_unless(result == 0, "Host should have been found");
    112   abort_unless(password != NULL, "returned NULL!");
    113   fail_unless(strncmp(password, "passwd", 6) == 0,
    114               "password should be 'passwd'");
    115   abort_unless(login != NULL, "returned NULL!");
    116   fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'");
    117   Curl_netrc_cleanup(&store);
    118 
    119   /*
    120    * Test for the first existing host in our netrc file
    121    * with login[0] != 0.
    122    */
    123   free(password);
    124   free(login);
    125   password = NULL;
    126   login = NULL;
    127   Curl_netrc_init(&store);
    128   result = Curl_parsenetrc(&store,
    129                            "example.com", &login, &password, arg);
    130   fail_unless(result == 0, "Host should have been found");
    131   abort_unless(password != NULL, "returned NULL!");
    132   fail_unless(strncmp(password, "passwd", 6) == 0,
    133               "password should be 'passwd'");
    134   abort_unless(login != NULL, "returned NULL!");
    135   fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'");
    136   Curl_netrc_cleanup(&store);
    137 
    138   /*
    139    * Test for the second existing host in our netrc file
    140    * with login[0] = 0.
    141    */
    142   free(password);
    143   password = NULL;
    144   free(login);
    145   login = NULL;
    146   Curl_netrc_init(&store);
    147   result = Curl_parsenetrc(&store,
    148                            "curl.example.com", &login, &password, arg);
    149   fail_unless(result == 0, "Host should have been found");
    150   abort_unless(password != NULL, "returned NULL!");
    151   fail_unless(strncmp(password, "none", 4) == 0,
    152               "password should be 'none'");
    153   abort_unless(login != NULL, "returned NULL!");
    154   fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
    155   Curl_netrc_cleanup(&store);
    156 
    157   /*
    158    * Test for the second existing host in our netrc file
    159    * with login[0] != 0.
    160    */
    161   free(password);
    162   free(login);
    163   password = NULL;
    164   login = NULL;
    165   Curl_netrc_init(&store);
    166   result = Curl_parsenetrc(&store,
    167                            "curl.example.com", &login, &password, arg);
    168   fail_unless(result == 0, "Host should have been found");
    169   abort_unless(password != NULL, "returned NULL!");
    170   fail_unless(strncmp(password, "none", 4) == 0,
    171               "password should be 'none'");
    172   abort_unless(login != NULL, "returned NULL!");
    173   fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
    174   Curl_netrc_cleanup(&store);
    175 
    176   UNITTEST_END(t1304_stop(&password, &login))
    177 }
    178 
    179 #else
    180 
    181 static CURLcode test_unit1304(char *arg)
    182 {
    183   UNITTEST_BEGIN_SIMPLE
    184   UNITTEST_END_SIMPLE
    185 }
    186 
    187 #endif