unit1621.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 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 "urldata.h"
  26. #include "url.h"
  27. #include "memdebug.h" /* LAST include file */
  28. static CURLcode unit_setup(void)
  29. {
  30. return CURLE_OK;
  31. }
  32. static void unit_stop(void)
  33. {
  34. }
  35. #if defined(__MINGW32__) || \
  36. (!defined(HAVE_FSETXATTR) && \
  37. (!defined(__FreeBSD_version) || (__FreeBSD_version < 500000)))
  38. UNITTEST_START
  39. UNITTEST_STOP
  40. #else
  41. char *stripcredentials(const char *url);
  42. struct checkthis {
  43. const char *input;
  44. const char *output;
  45. };
  46. static const struct checkthis tests[] = {
  47. { "ninja://foo@example.com", "ninja://foo@example.com" },
  48. { "https://foo@example.com", "https://example.com/" },
  49. { "https://localhost:45", "https://localhost:45/" },
  50. { "https://foo@localhost:45", "https://localhost:45/" },
  51. { "http://daniel:password@localhost", "http://localhost/" },
  52. { "http://daniel@localhost", "http://localhost/" },
  53. { "http://localhost/", "http://localhost/" },
  54. { NULL, NULL } /* end marker */
  55. };
  56. UNITTEST_START
  57. {
  58. int i;
  59. for(i = 0; tests[i].input; i++) {
  60. const char *url = tests[i].input;
  61. char *stripped = stripcredentials(url);
  62. printf("Test %u got input \"%s\", output: \"%s\"\n",
  63. i, tests[i].input, stripped);
  64. fail_if(stripped && strcmp(tests[i].output, stripped),
  65. tests[i].output);
  66. curl_free(stripped);
  67. }
  68. }
  69. UNITTEST_STOP
  70. #endif