| xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 1 | /*************************************************************************** | 
|  | 2 | *                                  _   _ ____  _ | 
|  | 3 | *  Project                     ___| | | |  _ \| | | 
|  | 4 | *                             / __| | | | |_) | | | 
|  | 5 | *                            | (__| |_| |  _ <| |___ | 
|  | 6 | *                             \___|\___/|_| \_\_____| | 
|  | 7 | * | 
|  | 8 | * Copyright (C) 1998 - 2022, 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 "curlcheck.h" | 
|  | 25 |  | 
|  | 26 | #include "vtls/hostcheck.h" /* from the lib dir */ | 
|  | 27 |  | 
|  | 28 | static CURLcode unit_setup(void) | 
|  | 29 | { | 
|  | 30 | return CURLE_OK; | 
|  | 31 | } | 
|  | 32 |  | 
|  | 33 | static void unit_stop(void) | 
|  | 34 | { | 
|  | 35 | /* done before shutting down and exiting */ | 
|  | 36 | } | 
|  | 37 |  | 
|  | 38 | UNITTEST_START | 
|  | 39 |  | 
|  | 40 | /* only these backends define the tested functions */ | 
|  | 41 | #if defined(USE_OPENSSL) || defined(USE_GSKIT) | 
|  | 42 |  | 
|  | 43 | /* here you start doing things and checking that the results are good */ | 
|  | 44 |  | 
|  | 45 | fail_unless(Curl_cert_hostcheck(STRCONST("www.example.com"), | 
|  | 46 | STRCONST("www.example.com")), "good 1"); | 
|  | 47 | fail_unless(Curl_cert_hostcheck(STRCONST("*.example.com"), | 
|  | 48 | STRCONST("www.example.com")), | 
|  | 49 | "good 2"); | 
|  | 50 | fail_unless(Curl_cert_hostcheck(STRCONST("xxx*.example.com"), | 
|  | 51 | STRCONST("xxxwww.example.com")), "good 3"); | 
|  | 52 | fail_unless(Curl_cert_hostcheck(STRCONST("f*.example.com"), | 
|  | 53 | STRCONST("foo.example.com")), "good 4"); | 
|  | 54 | fail_unless(Curl_cert_hostcheck(STRCONST("192.168.0.0"), | 
|  | 55 | STRCONST("192.168.0.0")), "good 5"); | 
|  | 56 |  | 
|  | 57 | fail_if(Curl_cert_hostcheck(STRCONST("xxx.example.com"), | 
|  | 58 | STRCONST("www.example.com")), "bad 1"); | 
|  | 59 | fail_if(Curl_cert_hostcheck(STRCONST("*"), | 
|  | 60 | STRCONST("www.example.com")),"bad 2"); | 
|  | 61 | fail_if(Curl_cert_hostcheck(STRCONST("*.*.com"), | 
|  | 62 | STRCONST("www.example.com")), "bad 3"); | 
|  | 63 | fail_if(Curl_cert_hostcheck(STRCONST("*.example.com"), | 
|  | 64 | STRCONST("baa.foo.example.com")), "bad 4"); | 
|  | 65 | fail_if(Curl_cert_hostcheck(STRCONST("f*.example.com"), | 
|  | 66 | STRCONST("baa.example.com")), "bad 5"); | 
|  | 67 | fail_if(Curl_cert_hostcheck(STRCONST("*.com"), | 
|  | 68 | STRCONST("example.com")), "bad 6"); | 
|  | 69 | fail_if(Curl_cert_hostcheck(STRCONST("*fail.com"), | 
|  | 70 | STRCONST("example.com")), "bad 7"); | 
|  | 71 | fail_if(Curl_cert_hostcheck(STRCONST("*.example."), | 
|  | 72 | STRCONST("www.example.")), "bad 8"); | 
|  | 73 | fail_if(Curl_cert_hostcheck(STRCONST("*.example."), | 
|  | 74 | STRCONST("www.example")), "bad 9"); | 
|  | 75 | fail_if(Curl_cert_hostcheck(STRCONST(""), STRCONST("www")), "bad 10"); | 
|  | 76 | fail_if(Curl_cert_hostcheck(STRCONST("*"), STRCONST("www")), "bad 11"); | 
|  | 77 | fail_if(Curl_cert_hostcheck(STRCONST("*.168.0.0"), | 
|  | 78 | STRCONST("192.168.0.0")), "bad 12"); | 
|  | 79 | fail_if(Curl_cert_hostcheck(STRCONST("www.example.com"), | 
|  | 80 | STRCONST("192.168.0.0")), "bad 13"); | 
|  | 81 |  | 
|  | 82 | #ifdef ENABLE_IPV6 | 
|  | 83 | fail_if(Curl_cert_hostcheck(STRCONST("*::3285:a9ff:fe46:b619"), | 
|  | 84 | STRCONST("fe80::3285:a9ff:fe46:b619")), "bad 14"); | 
|  | 85 | fail_unless(Curl_cert_hostcheck(STRCONST("fe80::3285:a9ff:fe46:b619"), | 
|  | 86 | STRCONST("fe80::3285:a9ff:fe46:b619")), | 
|  | 87 | "good 6"); | 
|  | 88 | #endif | 
|  | 89 |  | 
|  | 90 | #endif | 
|  | 91 |  | 
|  | 92 | /* you end the test code like this: */ | 
|  | 93 |  | 
|  | 94 | UNITTEST_STOP |