xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 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 | |
| 26 | #include "urldata.h" |
| 27 | #include "url.h" |
| 28 | |
| 29 | #include "memdebug.h" /* LAST include file */ |
| 30 | |
| 31 | static CURLcode unit_setup(void) |
| 32 | { |
| 33 | return CURLE_OK; |
| 34 | } |
| 35 | |
| 36 | static void unit_stop(void) |
| 37 | { |
| 38 | } |
| 39 | |
| 40 | #if defined(__MINGW32__) || \ |
| 41 | (!defined(HAVE_FSETXATTR) && \ |
| 42 | (!defined(__FreeBSD_version) || (__FreeBSD_version < 500000))) |
| 43 | UNITTEST_START |
| 44 | { |
| 45 | return 0; |
| 46 | } |
| 47 | UNITTEST_STOP |
| 48 | #else |
| 49 | |
| 50 | char *stripcredentials(const char *url); |
| 51 | |
| 52 | struct checkthis { |
| 53 | const char *input; |
| 54 | const char *output; |
| 55 | }; |
| 56 | |
| 57 | static const struct checkthis tests[] = { |
| 58 | { "ninja://foo@example.com", "ninja://foo@example.com" }, |
| 59 | { "https://foo@example.com", "https://example.com/" }, |
| 60 | { "https://localhost:45", "https://localhost:45/" }, |
| 61 | { "https://foo@localhost:45", "https://localhost:45/" }, |
| 62 | { "http://daniel:password@localhost", "http://localhost/" }, |
| 63 | { "http://daniel@localhost", "http://localhost/" }, |
| 64 | { "http://localhost/", "http://localhost/" }, |
| 65 | { NULL, NULL } /* end marker */ |
| 66 | }; |
| 67 | |
| 68 | UNITTEST_START |
| 69 | { |
| 70 | int i; |
| 71 | int rc = 0; |
| 72 | |
| 73 | for(i = 0; tests[i].input; i++) { |
| 74 | const char *url = tests[i].input; |
| 75 | char *stripped = stripcredentials(url); |
| 76 | printf("Test %u got input \"%s\", output: \"%s\"\n", |
| 77 | i, tests[i].input, stripped); |
| 78 | |
| 79 | if(stripped && strcmp(tests[i].output, stripped)) { |
| 80 | fprintf(stderr, "Test %u got input \"%s\", expected output \"%s\"\n" |
| 81 | " Actual output: \"%s\"\n", i, tests[i].input, tests[i].output, |
| 82 | stripped); |
| 83 | rc++; |
| 84 | } |
| 85 | curl_free(stripped); |
| 86 | } |
| 87 | return rc; |
| 88 | } |
| 89 | UNITTEST_STOP |
| 90 | #endif |