unit1397.c 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2016, 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.haxx.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. ***************************************************************************/
  22. #include "curlcheck.h"
  23. #include "hostcheck.h" /* from the lib dir */
  24. static CURLcode unit_setup(void)
  25. {
  26. return CURLE_OK;
  27. }
  28. static void unit_stop(void)
  29. {
  30. /* done before shutting down and exiting */
  31. }
  32. UNITTEST_START
  33. /* only these backends define the tested functions */
  34. #if defined(USE_OPENSSL) || defined(USE_AXTLS) || defined(USE_GSKIT)
  35. /* here you start doing things and checking that the results are good */
  36. fail_unless(Curl_cert_hostcheck("www.example.com", "www.example.com"),
  37. "good 1");
  38. fail_unless(Curl_cert_hostcheck("*.example.com", "www.example.com"),
  39. "good 2");
  40. fail_unless(Curl_cert_hostcheck("xxx*.example.com", "xxxwww.example.com"),
  41. "good 3");
  42. fail_unless(Curl_cert_hostcheck("f*.example.com", "foo.example.com"),
  43. "good 4");
  44. fail_unless(Curl_cert_hostcheck("192.168.0.0", "192.168.0.0"),
  45. "good 5");
  46. fail_if(Curl_cert_hostcheck("xxx.example.com", "www.example.com"), "bad 1");
  47. fail_if(Curl_cert_hostcheck("*", "www.example.com"), "bad 2");
  48. fail_if(Curl_cert_hostcheck("*.*.com", "www.example.com"), "bad 3");
  49. fail_if(Curl_cert_hostcheck("*.example.com", "baa.foo.example.com"), "bad 4");
  50. fail_if(Curl_cert_hostcheck("f*.example.com", "baa.example.com"), "bad 5");
  51. fail_if(Curl_cert_hostcheck("*.com", "example.com"), "bad 6");
  52. fail_if(Curl_cert_hostcheck("*fail.com", "example.com"), "bad 7");
  53. fail_if(Curl_cert_hostcheck("*.example.", "www.example."), "bad 8");
  54. fail_if(Curl_cert_hostcheck("*.example.", "www.example"), "bad 9");
  55. fail_if(Curl_cert_hostcheck("", "www"), "bad 10");
  56. fail_if(Curl_cert_hostcheck("*", "www"), "bad 11");
  57. fail_if(Curl_cert_hostcheck("*.168.0.0", "192.168.0.0"), "bad 12");
  58. fail_if(Curl_cert_hostcheck("www.example.com", "192.168.0.0"), "bad 13");
  59. #ifdef ENABLE_IPV6
  60. fail_if(Curl_cert_hostcheck("*::3285:a9ff:fe46:b619",
  61. "fe80::3285:a9ff:fe46:b619"), "bad 14");
  62. fail_unless(Curl_cert_hostcheck("fe80::3285:a9ff:fe46:b619",
  63. "fe80::3285:a9ff:fe46:b619"), "good 6");
  64. #endif
  65. #endif
  66. /* you end the test code like this: */
  67. UNITTEST_STOP