unit1397.c 3.9 KB

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