2016-04-03 22:21:10 +08:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2023-01-02 20:51:48 +08:00
|
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
2016-04-03 22:21:10 +08:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2020-11-04 21:02:01 +08:00
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
2016-04-03 22:21:10 +08:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: curl
|
2022-05-17 17:16:50 +08:00
|
|
|
*
|
2016-04-03 22:21:10 +08:00
|
|
|
***************************************************************************/
|
2014-02-22 23:52:58 +08:00
|
|
|
#include "curlcheck.h"
|
|
|
|
|
2022-02-04 17:44:02 +08:00
|
|
|
#include "vtls/hostcheck.h" /* from the lib dir */
|
2014-02-22 23:52:58 +08:00
|
|
|
|
|
|
|
static CURLcode unit_setup(void)
|
|
|
|
{
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2016-04-04 02:28:34 +08:00
|
|
|
static void unit_stop(void)
|
2014-02-22 23:52:58 +08:00
|
|
|
{
|
|
|
|
/* done before shutting down and exiting */
|
|
|
|
}
|
|
|
|
|
|
|
|
UNITTEST_START
|
|
|
|
|
2014-03-27 05:06:44 +08:00
|
|
|
/* only these backends define the tested functions */
|
2018-10-30 17:00:00 +08:00
|
|
|
#if defined(USE_OPENSSL) || defined(USE_GSKIT)
|
2014-03-27 05:06:44 +08:00
|
|
|
|
2014-02-22 23:52:58 +08:00
|
|
|
/* here you start doing things and checking that the results are good */
|
|
|
|
|
2022-02-10 00:27:09 +08:00
|
|
|
fail_unless(Curl_cert_hostcheck(STRCONST("www.example.com"),
|
2022-02-11 04:04:52 +08:00
|
|
|
STRCONST("www.example.com")), "good 1");
|
|
|
|
fail_unless(Curl_cert_hostcheck(STRCONST("*.example.com"),
|
|
|
|
STRCONST("www.example.com")),
|
2016-04-03 22:21:10 +08:00
|
|
|
"good 2");
|
2022-02-10 00:27:09 +08:00
|
|
|
fail_unless(Curl_cert_hostcheck(STRCONST("xxx*.example.com"),
|
2022-02-11 04:04:52 +08:00
|
|
|
STRCONST("xxxwww.example.com")), "good 3");
|
|
|
|
fail_unless(Curl_cert_hostcheck(STRCONST("f*.example.com"),
|
|
|
|
STRCONST("foo.example.com")), "good 4");
|
|
|
|
fail_unless(Curl_cert_hostcheck(STRCONST("192.168.0.0"),
|
|
|
|
STRCONST("192.168.0.0")), "good 5");
|
2016-04-03 22:21:10 +08:00
|
|
|
|
2022-02-10 00:27:09 +08:00
|
|
|
fail_if(Curl_cert_hostcheck(STRCONST("xxx.example.com"),
|
2022-02-11 04:04:52 +08:00
|
|
|
STRCONST("www.example.com")), "bad 1");
|
|
|
|
fail_if(Curl_cert_hostcheck(STRCONST("*"),
|
|
|
|
STRCONST("www.example.com")),"bad 2");
|
|
|
|
fail_if(Curl_cert_hostcheck(STRCONST("*.*.com"),
|
|
|
|
STRCONST("www.example.com")), "bad 3");
|
2022-02-10 00:27:09 +08:00
|
|
|
fail_if(Curl_cert_hostcheck(STRCONST("*.example.com"),
|
2022-02-11 04:04:52 +08:00
|
|
|
STRCONST("baa.foo.example.com")), "bad 4");
|
2022-02-10 00:27:09 +08:00
|
|
|
fail_if(Curl_cert_hostcheck(STRCONST("f*.example.com"),
|
2022-02-11 04:04:52 +08:00
|
|
|
STRCONST("baa.example.com")), "bad 5");
|
|
|
|
fail_if(Curl_cert_hostcheck(STRCONST("*.com"),
|
|
|
|
STRCONST("example.com")), "bad 6");
|
|
|
|
fail_if(Curl_cert_hostcheck(STRCONST("*fail.com"),
|
|
|
|
STRCONST("example.com")), "bad 7");
|
|
|
|
fail_if(Curl_cert_hostcheck(STRCONST("*.example."),
|
|
|
|
STRCONST("www.example.")), "bad 8");
|
|
|
|
fail_if(Curl_cert_hostcheck(STRCONST("*.example."),
|
|
|
|
STRCONST("www.example")), "bad 9");
|
|
|
|
fail_if(Curl_cert_hostcheck(STRCONST(""), STRCONST("www")), "bad 10");
|
|
|
|
fail_if(Curl_cert_hostcheck(STRCONST("*"), STRCONST("www")), "bad 11");
|
|
|
|
fail_if(Curl_cert_hostcheck(STRCONST("*.168.0.0"),
|
|
|
|
STRCONST("192.168.0.0")), "bad 12");
|
2022-02-10 00:27:09 +08:00
|
|
|
fail_if(Curl_cert_hostcheck(STRCONST("www.example.com"),
|
2022-02-11 04:04:52 +08:00
|
|
|
STRCONST("192.168.0.0")), "bad 13");
|
2014-02-22 23:52:58 +08:00
|
|
|
|
|
|
|
#ifdef ENABLE_IPV6
|
2022-02-10 00:27:09 +08:00
|
|
|
fail_if(Curl_cert_hostcheck(STRCONST("*::3285:a9ff:fe46:b619"),
|
2022-02-11 04:04:52 +08:00
|
|
|
STRCONST("fe80::3285:a9ff:fe46:b619")), "bad 14");
|
2022-02-10 00:27:09 +08:00
|
|
|
fail_unless(Curl_cert_hostcheck(STRCONST("fe80::3285:a9ff:fe46:b619"),
|
2022-02-11 04:04:52 +08:00
|
|
|
STRCONST("fe80::3285:a9ff:fe46:b619")),
|
|
|
|
"good 6");
|
2014-03-27 05:06:44 +08:00
|
|
|
#endif
|
|
|
|
|
2014-02-22 23:52:58 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* you end the test code like this: */
|
|
|
|
|
|
|
|
UNITTEST_STOP
|