quickjs-tart

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

unit1654.c (5687B)


      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 
     26 #include "urldata.h"
     27 #include "altsvc.h"
     28 
     29 static CURLcode test_unit1654(char *arg)
     30 {
     31   UNITTEST_BEGIN_SIMPLE
     32 
     33 #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_ALTSVC)
     34   char outname[256];
     35   CURL *curl;
     36   CURLcode result;
     37   struct altsvcinfo *asi = Curl_altsvc_init();
     38   abort_if(!asi, "Curl_altsvc_i");
     39   result = Curl_altsvc_load(asi, arg);
     40   if(result) {
     41     fail_if(result, "Curl_altsvc_load");
     42     goto fail;
     43   }
     44   curl_global_init(CURL_GLOBAL_ALL);
     45   curl = curl_easy_init();
     46   if(!curl) {
     47     fail_if(!curl, "curl_easy_init");
     48     goto fail;
     49   }
     50   fail_unless(Curl_llist_count(&asi->list) == 4, "wrong number of entries");
     51   curl_msnprintf(outname, sizeof(outname), "%s-out", arg);
     52 
     53   result = Curl_altsvc_parse(curl, asi, "h2=\"example.com:8080\"\r\n",
     54                              ALPN_h1, "example.org", 8080);
     55   fail_if(result, "Curl_altsvc_parse() failed!");
     56   fail_unless(Curl_llist_count(&asi->list) == 5, "wrong number of entries");
     57 
     58   result = Curl_altsvc_parse(curl, asi, "h3=\":8080\"\r\n",
     59                              ALPN_h1, "2.example.org", 8080);
     60   fail_if(result, "Curl_altsvc_parse(2) failed!");
     61   fail_unless(Curl_llist_count(&asi->list) == 6, "wrong number of entries");
     62 
     63   result = Curl_altsvc_parse(curl, asi,
     64                              "h2=\"example.com:8080\", "
     65                              "h3=\"yesyes.com:8080\"\r\n",
     66                              ALPN_h1, "3.example.org", 8080);
     67   fail_if(result, "Curl_altsvc_parse(3) failed!");
     68   /* that one should make two entries */
     69   fail_unless(Curl_llist_count(&asi->list) == 8, "wrong number of entries");
     70 
     71   result = Curl_altsvc_parse(curl, asi,
     72                              "h2=\"example.com:443\"; ma = 120;\r\n",
     73                              ALPN_h2, "example.org", 80);
     74   fail_if(result, "Curl_altsvc_parse(4) failed!");
     75   fail_unless(Curl_llist_count(&asi->list) == 9, "wrong number of entries");
     76 
     77   /* quoted 'ma' value */
     78   result = Curl_altsvc_parse(curl, asi,
     79                              "h2=\"example.net:443\"; ma=\"180\";\r\n",
     80                              ALPN_h2, "example.net", 80);
     81   fail_if(result, "Curl_altsvc_parse(5) failed!");
     82   fail_unless(Curl_llist_count(&asi->list) == 10, "wrong number of entries");
     83 
     84   result =
     85     Curl_altsvc_parse(curl, asi,
     86                       "h2=\":443\", h3=\":443\"; "
     87                       "persist = \"1\"; ma = 120;\r\n",
     88                       ALPN_h1, "curl.se", 80);
     89   fail_if(result, "Curl_altsvc_parse(6) failed!");
     90   fail_unless(Curl_llist_count(&asi->list) == 12, "wrong number of entries");
     91 
     92   /* clear that one again and decrease the counter */
     93   result = Curl_altsvc_parse(curl, asi, "clear;\r\n",
     94                              ALPN_h1, "curl.se", 80);
     95   fail_if(result, "Curl_altsvc_parse(7) failed!");
     96   fail_unless(Curl_llist_count(&asi->list) == 10, "wrong number of entries");
     97 
     98   result =
     99     Curl_altsvc_parse(curl, asi,
    100                       "h2=\":443\", h3=\":443\"; "
    101                       "persist = \"1\"; ma = 120;\r\n",
    102                       ALPN_h1, "curl.se", 80);
    103   fail_if(result, "Curl_altsvc_parse(6) failed!");
    104   fail_unless(Curl_llist_count(&asi->list) == 12, "wrong number of entries");
    105 
    106   /* clear - without semicolon */
    107   result = Curl_altsvc_parse(curl, asi, "clear\r\n",
    108                              ALPN_h1, "curl.se", 80);
    109   fail_if(result, "Curl_altsvc_parse(7) failed!");
    110   fail_unless(Curl_llist_count(&asi->list) == 10, "wrong number of entries");
    111 
    112   /* only a non-existing alpn */
    113   result = Curl_altsvc_parse(curl, asi,
    114                              "h6=\"example.net:443\"; ma=\"180\";\r\n",
    115                              ALPN_h2, "5.example.net", 80);
    116   fail_if(result, "Curl_altsvc_parse(8) failed!");
    117 
    118   /* missing quote in alpn host */
    119   result = Curl_altsvc_parse(curl, asi,
    120                              "h2=\"example.net:443,; ma=\"180\";\r\n",
    121                              ALPN_h2, "6.example.net", 80);
    122   fail_if(result, "Curl_altsvc_parse(9) failed!");
    123 
    124   /* missing port in host name */
    125   result = Curl_altsvc_parse(curl, asi,
    126                              "h2=\"example.net\"; ma=\"180\";\r\n",
    127                              ALPN_h2, "7.example.net", 80);
    128   fail_if(result, "Curl_altsvc_parse(10) failed!");
    129 
    130   /* illegal port in host name */
    131   result = Curl_altsvc_parse(curl, asi,
    132                              "h2=\"example.net:70000\"; ma=\"180\";\r\n",
    133                              ALPN_h2, "8.example.net", 80);
    134   fail_if(result, "Curl_altsvc_parse(11) failed!");
    135 
    136   Curl_altsvc_save(curl, asi, outname);
    137 
    138   curl_easy_cleanup(curl);
    139 fail:
    140   Curl_altsvc_cleanup(&asi);
    141 #endif
    142 
    143   UNITTEST_END(curl_global_cleanup())
    144 }