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 "test.h" |
| 25 | #include "memdebug.h" |
| 26 | |
| 27 | int test(char *URL) |
| 28 | { |
| 29 | CURLcode res; |
| 30 | CURL *curl = NULL; |
| 31 | char *newURL = NULL; |
| 32 | struct curl_slist *slist = NULL; |
| 33 | |
| 34 | if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { |
| 35 | fprintf(stderr, "curl_global_init() failed\n"); |
| 36 | return TEST_ERR_MAJOR_BAD; |
| 37 | } |
| 38 | |
| 39 | curl = curl_easy_init(); |
| 40 | if(!curl) { |
| 41 | fprintf(stderr, "curl_easy_init() failed\n"); |
| 42 | res = TEST_ERR_MAJOR_BAD; |
| 43 | goto test_cleanup; |
| 44 | } |
| 45 | |
| 46 | /* test: CURLFTPMETHOD_SINGLECWD with absolute path should |
| 47 | skip CWD to entry path */ |
| 48 | newURL = aprintf("%s/folderA/661", URL); |
| 49 | test_setopt(curl, CURLOPT_URL, newURL); |
| 50 | test_setopt(curl, CURLOPT_VERBOSE, 1L); |
| 51 | test_setopt(curl, CURLOPT_IGNORE_CONTENT_LENGTH, 1L); |
| 52 | test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD); |
| 53 | res = curl_easy_perform(curl); |
| 54 | |
| 55 | free(newURL); |
| 56 | newURL = aprintf("%s/folderB/661", URL); |
| 57 | test_setopt(curl, CURLOPT_URL, newURL); |
| 58 | res = curl_easy_perform(curl); |
| 59 | |
| 60 | /* test: CURLFTPMETHOD_NOCWD with absolute path should |
| 61 | never emit CWD (for both new and reused easy handle) */ |
| 62 | curl_easy_cleanup(curl); |
| 63 | curl = curl_easy_init(); |
| 64 | if(!curl) { |
| 65 | fprintf(stderr, "curl_easy_init() failed\n"); |
| 66 | res = TEST_ERR_MAJOR_BAD; |
| 67 | goto test_cleanup; |
| 68 | } |
| 69 | |
| 70 | free(newURL); |
| 71 | newURL = aprintf("%s/folderA/661", URL); |
| 72 | test_setopt(curl, CURLOPT_URL, newURL); |
| 73 | test_setopt(curl, CURLOPT_VERBOSE, 1L); |
| 74 | test_setopt(curl, CURLOPT_IGNORE_CONTENT_LENGTH, 1L); |
| 75 | test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD); |
| 76 | res = curl_easy_perform(curl); |
| 77 | |
| 78 | /* curve ball: CWD /folderB before reusing connection with _NOCWD */ |
| 79 | free(newURL); |
| 80 | newURL = aprintf("%s/folderB/661", URL); |
| 81 | test_setopt(curl, CURLOPT_URL, newURL); |
| 82 | test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD); |
| 83 | res = curl_easy_perform(curl); |
| 84 | |
| 85 | free(newURL); |
| 86 | newURL = aprintf("%s/folderA/661", URL); |
| 87 | test_setopt(curl, CURLOPT_URL, newURL); |
| 88 | test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD); |
| 89 | res = curl_easy_perform(curl); |
| 90 | |
| 91 | /* test: CURLFTPMETHOD_NOCWD with home-relative path should |
| 92 | not emit CWD for first FTP access after login */ |
| 93 | curl_easy_cleanup(curl); |
| 94 | curl = curl_easy_init(); |
| 95 | if(!curl) { |
| 96 | fprintf(stderr, "curl_easy_init() failed\n"); |
| 97 | res = TEST_ERR_MAJOR_BAD; |
| 98 | goto test_cleanup; |
| 99 | } |
| 100 | |
| 101 | slist = curl_slist_append(NULL, "SYST"); |
| 102 | if(!slist) { |
| 103 | fprintf(stderr, "curl_slist_append() failed\n"); |
| 104 | res = TEST_ERR_MAJOR_BAD; |
| 105 | goto test_cleanup; |
| 106 | } |
| 107 | |
| 108 | test_setopt(curl, CURLOPT_URL, URL); |
| 109 | test_setopt(curl, CURLOPT_VERBOSE, 1L); |
| 110 | test_setopt(curl, CURLOPT_NOBODY, 1L); |
| 111 | test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD); |
| 112 | test_setopt(curl, CURLOPT_QUOTE, slist); |
| 113 | res = curl_easy_perform(curl); |
| 114 | |
| 115 | /* test: CURLFTPMETHOD_SINGLECWD with home-relative path should |
| 116 | not emit CWD for first FTP access after login */ |
| 117 | curl_easy_cleanup(curl); |
| 118 | curl = curl_easy_init(); |
| 119 | if(!curl) { |
| 120 | fprintf(stderr, "curl_easy_init() failed\n"); |
| 121 | res = TEST_ERR_MAJOR_BAD; |
| 122 | goto test_cleanup; |
| 123 | } |
| 124 | |
| 125 | test_setopt(curl, CURLOPT_URL, URL); |
| 126 | test_setopt(curl, CURLOPT_VERBOSE, 1L); |
| 127 | test_setopt(curl, CURLOPT_NOBODY, 1L); |
| 128 | test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD); |
| 129 | test_setopt(curl, CURLOPT_QUOTE, slist); |
| 130 | res = curl_easy_perform(curl); |
| 131 | |
| 132 | /* test: CURLFTPMETHOD_NOCWD with home-relative path should |
| 133 | not emit CWD for second FTP access when not needed + |
| 134 | bonus: see if path buffering survives curl_easy_reset() */ |
| 135 | curl_easy_reset(curl); |
| 136 | test_setopt(curl, CURLOPT_URL, URL); |
| 137 | test_setopt(curl, CURLOPT_VERBOSE, 1L); |
| 138 | test_setopt(curl, CURLOPT_NOBODY, 1L); |
| 139 | test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD); |
| 140 | test_setopt(curl, CURLOPT_QUOTE, slist); |
| 141 | res = curl_easy_perform(curl); |
| 142 | |
| 143 | |
| 144 | test_cleanup: |
| 145 | |
| 146 | curl_slist_free_all(slist); |
| 147 | free(newURL); |
| 148 | curl_easy_cleanup(curl); |
| 149 | curl_global_cleanup(); |
| 150 | |
| 151 | return (int)res; |
| 152 | } |