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