unit1621.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 "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. {
  40. return 0;
  41. }
  42. UNITTEST_STOP
  43. #else
  44. char *stripcredentials(const char *url);
  45. struct checkthis {
  46. const char *input;
  47. const char *output;
  48. };
  49. static const struct checkthis tests[] = {
  50. { "ninja://foo@example.com", "ninja://foo@example.com" },
  51. { "https://foo@example.com", "https://example.com/" },
  52. { "https://localhost:45", "https://localhost:45/" },
  53. { "https://foo@localhost:45", "https://localhost:45/" },
  54. { "http://daniel:password@localhost", "http://localhost/" },
  55. { "http://daniel@localhost", "http://localhost/" },
  56. { "http://localhost/", "http://localhost/" },
  57. { NULL, NULL } /* end marker */
  58. };
  59. UNITTEST_START
  60. {
  61. int i;
  62. int rc = 0;
  63. for(i = 0; tests[i].input; i++) {
  64. const char *url = tests[i].input;
  65. char *stripped = stripcredentials(url);
  66. printf("Test %u got input \"%s\", output: \"%s\"\n",
  67. i, tests[i].input, stripped);
  68. if(stripped && strcmp(tests[i].output, stripped)) {
  69. fprintf(stderr, "Test %u got input \"%s\", expected output \"%s\"\n"
  70. " Actual output: \"%s\"\n", i, tests[i].input, tests[i].output,
  71. stripped);
  72. rc++;
  73. }
  74. curl_free(stripped);
  75. }
  76. return rc;
  77. }
  78. UNITTEST_STOP
  79. #endif