tool1621.c (3103B)
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 "unitcheck.h" 25 26 #include "tool_xattr.h" 27 28 #include "memdebug.h" /* LAST include file */ 29 30 static CURLcode test_tool1621(char *arg) 31 { 32 UNITTEST_BEGIN_SIMPLE 33 34 #ifdef USE_XATTR /* Required for stripcredentials() */ 35 36 struct checkthis { 37 const char *input; 38 const char *output; 39 }; 40 41 static const struct checkthis tests[] = { 42 { "ninja://foo@example.com", "(null)" }, /* unsupported scheme */ 43 #if defined(USE_SSL) && !defined(CURL_DISABLE_POP3) 44 { "pop3s://foo@example.com", "pop3s://example.com/" }, 45 #endif 46 #ifndef CURL_DISABLE_LDAP 47 { "ldap://foo@example.com", "ldap://example.com/" }, 48 #endif 49 #if defined(USE_SSL) && !defined(CURL_DISABLE_HTTP) 50 { "https://foo@example.com", "https://example.com/" }, 51 { "https://localhost:45", "https://localhost:45/" }, 52 { "https://foo@localhost:45", "https://localhost:45/" }, 53 { "https://user:pass@localhost:45", "https://localhost:45/" }, 54 #endif 55 #ifndef CURL_DISABLE_HTTP 56 { "http://daniel:password@localhost", "http://localhost/" }, 57 { "http://daniel@localhost", "http://localhost/" }, 58 { "http://localhost/", "http://localhost/" }, 59 { "http://odd%40host/", "(null)" }, /* bad host */ 60 { "http://user@odd%40host/", "(null)" }, /* bad host */ 61 { "http://host/@path/", "http://host/@path/" }, 62 { "http://emptypw:@host/", "http://host/" }, 63 { "http://:emptyuser@host/", "http://host/" }, 64 { "http://odd%40user@host/", "http://host/" }, 65 { "http://only%40one%40host/", "(null)" }, /* bad host */ 66 { "http://odder%3auser@host/", "http://host/" }, 67 #endif 68 { NULL, NULL } /* end marker */ 69 }; 70 71 int i; 72 73 for(i = 0; tests[i].input; i++) { 74 const char *url = tests[i].input; 75 char *stripped = stripcredentials(url); 76 const char *strippedstr = stripped ? stripped : "(null)"; 77 printf("Test %u got input \"%s\", output: \"%s\", expected: \"%s\"\n", 78 i, tests[i].input, strippedstr, tests[i].output); 79 80 fail_if(strcmp(tests[i].output, strippedstr), tests[i].output); 81 curl_free(stripped); 82 } 83 #endif 84 85 UNITTEST_END_SIMPLE 86 }