blob: 90ec31c68195e688f34313e5279f6cdbf9e9356f [file] [log] [blame]
xf.li6c8fc1e2023-08-12 00:11:09 -07001/***************************************************************************
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
28static CURLcode unit_setup(void)
29{
30 return CURLE_OK;
31}
32
33static void unit_stop(void)
34{
35 /* done before shutting down and exiting */
36}
37
38UNITTEST_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
45fail_unless(Curl_cert_hostcheck(STRCONST("www.example.com"),
46 STRCONST("www.example.com")), "good 1");
47fail_unless(Curl_cert_hostcheck(STRCONST("*.example.com"),
48 STRCONST("www.example.com")),
49 "good 2");
50fail_unless(Curl_cert_hostcheck(STRCONST("xxx*.example.com"),
51 STRCONST("xxxwww.example.com")), "good 3");
52fail_unless(Curl_cert_hostcheck(STRCONST("f*.example.com"),
53 STRCONST("foo.example.com")), "good 4");
54fail_unless(Curl_cert_hostcheck(STRCONST("192.168.0.0"),
55 STRCONST("192.168.0.0")), "good 5");
56
57fail_if(Curl_cert_hostcheck(STRCONST("xxx.example.com"),
58 STRCONST("www.example.com")), "bad 1");
59fail_if(Curl_cert_hostcheck(STRCONST("*"),
60 STRCONST("www.example.com")),"bad 2");
61fail_if(Curl_cert_hostcheck(STRCONST("*.*.com"),
62 STRCONST("www.example.com")), "bad 3");
63fail_if(Curl_cert_hostcheck(STRCONST("*.example.com"),
64 STRCONST("baa.foo.example.com")), "bad 4");
65fail_if(Curl_cert_hostcheck(STRCONST("f*.example.com"),
66 STRCONST("baa.example.com")), "bad 5");
67fail_if(Curl_cert_hostcheck(STRCONST("*.com"),
68 STRCONST("example.com")), "bad 6");
69fail_if(Curl_cert_hostcheck(STRCONST("*fail.com"),
70 STRCONST("example.com")), "bad 7");
71fail_if(Curl_cert_hostcheck(STRCONST("*.example."),
72 STRCONST("www.example.")), "bad 8");
73fail_if(Curl_cert_hostcheck(STRCONST("*.example."),
74 STRCONST("www.example")), "bad 9");
75fail_if(Curl_cert_hostcheck(STRCONST(""), STRCONST("www")), "bad 10");
76fail_if(Curl_cert_hostcheck(STRCONST("*"), STRCONST("www")), "bad 11");
77fail_if(Curl_cert_hostcheck(STRCONST("*.168.0.0"),
78 STRCONST("192.168.0.0")), "bad 12");
79fail_if(Curl_cert_hostcheck(STRCONST("www.example.com"),
80 STRCONST("192.168.0.0")), "bad 13");
81
82#ifdef ENABLE_IPV6
83fail_if(Curl_cert_hostcheck(STRCONST("*::3285:a9ff:fe46:b619"),
84 STRCONST("fe80::3285:a9ff:fe46:b619")), "bad 14");
85fail_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
94UNITTEST_STOP