quickjs-tart

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

unit1397.c (4142B)


      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 "vtls/hostcheck.h"
     27 
     28 static CURLcode test_unit1397(char *arg)
     29 {
     30   UNITTEST_BEGIN_SIMPLE
     31 
     32 /* only these backends define the tested functions */
     33 #if defined(USE_OPENSSL) || defined(USE_SCHANNEL)
     34 
     35   struct testcase {
     36     const char *host;
     37     const char *pattern;
     38     bool match;
     39   };
     40 
     41   static const struct testcase tests[] = {
     42     {"", "", FALSE},
     43     {"a", "", FALSE},
     44     {"", "b", FALSE},
     45     {"a", "b", FALSE},
     46     {"aa", "bb", FALSE},
     47     {"\xff", "\xff", TRUE},
     48     {"aa.aa.aa", "aa.aa.bb", FALSE},
     49     {"aa.aa.aa", "aa.aa.aa", TRUE},
     50     {"aa.aa.aa", "*.aa.bb", FALSE},
     51     {"aa.aa.aa", "*.aa.aa", TRUE},
     52     {"192.168.0.1", "192.168.0.1", TRUE},
     53     {"192.168.0.1", "*.168.0.1", FALSE},
     54     {"192.168.0.1", "*.0.1", FALSE},
     55     {"h.ello", "*.ello", FALSE},
     56     {"h.ello.", "*.ello", FALSE},
     57     {"h.ello", "*.ello.", FALSE},
     58     {"h.e.llo", "*.e.llo", TRUE},
     59     {"h.e.llo", " *.e.llo", FALSE},
     60     {" h.e.llo", "*.e.llo", TRUE},
     61     {"h.e.llo.", "*.e.llo", TRUE},
     62     {"*.e.llo.", "*.e.llo", TRUE},
     63     {"************.e.llo.", "*.e.llo", TRUE},
     64     {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
     65      "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
     66      "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
     67      "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
     68      "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
     69      ".e.llo.", "*.e.llo", TRUE},
     70     {"\xfe\xfe.e.llo.", "*.e.llo", TRUE},
     71     {"h.e.llo.", "*.e.llo.", TRUE},
     72     {"h.e.llo", "*.e.llo.", TRUE},
     73     {".h.e.llo", "*.e.llo.", FALSE},
     74     {"h.e.llo", "*.*.llo.", FALSE},
     75     {"h.e.llo", "h.*.llo", FALSE},
     76     {"h.e.llo", "h.e.*", FALSE},
     77     {"hello", "*.ello", FALSE},
     78     {"hello", "**llo", FALSE},
     79     {"bar.foo.example.com", "*.example.com", FALSE},
     80     {"foo.example.com", "*.example.com", TRUE},
     81     {"baz.example.net", "b*z.example.net", FALSE},
     82     {"foobaz.example.net", "*baz.example.net", FALSE},
     83     {"xn--l8j.example.local", "x*.example.local", FALSE},
     84     {"xn--l8j.example.net", "*.example.net", TRUE},
     85     {"xn--l8j.example.net", "*j.example.net", FALSE},
     86     {"xn--l8j.example.net", "xn--l8j.example.net", TRUE},
     87     {"xn--l8j.example.net", "xn--l8j.*.net", FALSE},
     88     {"xl8j.example.net", "*.example.net", TRUE},
     89     {"fe80::3285:a9ff:fe46:b619", "*::3285:a9ff:fe46:b619", FALSE},
     90     {"fe80::3285:a9ff:fe46:b619", "fe80::3285:a9ff:fe46:b619", TRUE},
     91     {NULL, NULL, FALSE}
     92   };
     93 
     94   int i;
     95   for(i = 0; tests[i].host; i++) {
     96     if(tests[i].match != Curl_cert_hostcheck(tests[i].pattern,
     97                                              strlen(tests[i].pattern),
     98                                              tests[i].host,
     99                                              strlen(tests[i].host))) {
    100       curl_mfprintf(stderr,
    101                     "HOST: %s\n"
    102                     "PTRN: %s\n"
    103                     "did %sMATCH\n",
    104                     tests[i].host,
    105                     tests[i].pattern,
    106                     tests[i].match ? "NOT ": "");
    107       unitfail++;
    108     }
    109   }
    110 #endif
    111 
    112   UNITTEST_END_SIMPLE
    113 }