xref: /curl/tests/unit/unit1621.c (revision a13ef31d)
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 
26 #include "urldata.h"
27 #include "url.h"
28 
29 #include "memdebug.h" /* LAST include file */
30 
unit_setup(void)31 static CURLcode unit_setup(void)
32 {
33   return CURLE_OK;
34 }
35 
unit_stop(void)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 UNITTEST_STOP
45 #else
46 
47 char *stripcredentials(const char *url);
48 
49 struct checkthis {
50   const char *input;
51   const char *output;
52 };
53 
54 static const struct checkthis tests[] = {
55   { "ninja://foo@example.com", "ninja://foo@example.com" },
56   { "https://foo@example.com", "https://example.com/" },
57   { "https://localhost:45", "https://localhost:45/" },
58   { "https://foo@localhost:45", "https://localhost:45/" },
59   { "http://daniel:password@localhost", "http://localhost/" },
60   { "http://daniel@localhost", "http://localhost/" },
61   { "http://localhost/", "http://localhost/" },
62   { NULL, NULL } /* end marker */
63 };
64 
65 UNITTEST_START
66 {
67   int i;
68 
69   for(i = 0; tests[i].input; i++) {
70     const char *url = tests[i].input;
71     char *stripped = stripcredentials(url);
72     printf("Test %u got input \"%s\", output: \"%s\"\n",
73            i, tests[i].input, stripped);
74 
75     fail_if(stripped && strcmp(tests[i].output, stripped),
76             tests[i].output);
77     curl_free(stripped);
78   }
79 }
80 UNITTEST_STOP
81 #endif
82