unit1621.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2022, Daniel Stenberg, <[email protected]>, 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. bool stripcredentials(char **url);
  45. struct checkthis {
  46. const char *input;
  47. const char *output;
  48. };
  49. static const struct checkthis tests[] = {
  50. { "ninja://[email protected]", "ninja://[email protected]" },
  51. { "https://[email protected]", "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. bool cleanup;
  62. char *url;
  63. int i;
  64. int rc = 0;
  65. for(i = 0; tests[i].input; i++) {
  66. url = (char *)tests[i].input;
  67. cleanup = stripcredentials(&url);
  68. printf("Test %u got input \"%s\", output: \"%s\"\n",
  69. i, tests[i].input, url);
  70. if(strcmp(tests[i].output, url)) {
  71. fprintf(stderr, "Test %u got input \"%s\", expected output \"%s\"\n"
  72. " Actual output: \"%s\"\n", i, tests[i].input, tests[i].output,
  73. url);
  74. rc++;
  75. }
  76. if(cleanup)
  77. curl_free(url);
  78. }
  79. return rc;
  80. }
  81. UNITTEST_STOP
  82. #endif