unit1621.c 2.5 KB

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