1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
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.
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
22 #include "curlcheck.h"
24 #include "memdebug.h" /* LAST include file */
27 static char *password;
28 static char filename[64];
30 static CURLcode unit_setup(void)
32 password = strdup("");
34 if(!password || !login) {
35 Curl_safefree(password);
37 return CURLE_OUT_OF_MEMORY;
42 static void unit_stop(void)
44 Curl_safefree(password);
51 static const char* const filename1 = "log/netrc1304";
52 memcpy(filename, filename1, strlen(filename1));
55 * Test a non existent host in our netrc file.
57 result = Curl_parsenetrc("test.example.com", &login, &password, filename);
58 fail_unless(result == 1, "Host not found should return 1");
59 abort_unless(password != NULL, "returned NULL!");
60 fail_unless(password[0] == 0, "password should not have been changed");
61 abort_unless(login != NULL, "returned NULL!");
62 fail_unless(login[0] == 0, "login should not have been changed");
65 * Test a non existent login in our netrc file.
69 abort_unless(login != NULL, "returned NULL!");
70 result = Curl_parsenetrc("example.com", &login, &password, filename);
71 fail_unless(result == 0, "Host should be found");
72 abort_unless(password != NULL, "returned NULL!");
73 fail_unless(password[0] == 0, "password should not have been changed");
74 abort_unless(login != NULL, "returned NULL!");
75 fail_unless(strncmp(login, "me", 2) == 0,
76 "login should not have been changed");
79 * Test a non existent login and host in our netrc file.
83 abort_unless(login != NULL, "returned NULL!");
84 result = Curl_parsenetrc("test.example.com", &login, &password, filename);
85 fail_unless(result == 1, "Host should be found");
86 abort_unless(password != NULL, "returned NULL!");
87 fail_unless(password[0] == 0, "password should not have been changed");
88 abort_unless(login != NULL, "returned NULL!");
89 fail_unless(strncmp(login, "me", 2) == 0,
90 "login should not have been changed");
93 * Test a non existent login (substring of an existing one) in our
97 login = strdup("admi");
98 abort_unless(login != NULL, "returned NULL!");
99 result = Curl_parsenetrc("example.com", &login, &password, filename);
100 fail_unless(result == 0, "Host should be found");
101 abort_unless(password != NULL, "returned NULL!");
102 fail_unless(password[0] == 0, "password should not have been changed");
103 abort_unless(login != NULL, "returned NULL!");
104 fail_unless(strncmp(login, "admi", 4) == 0,
105 "login should not have been changed");
108 * Test a non existent login (superstring of an existing one)
112 login = strdup("adminn");
113 abort_unless(login != NULL, "returned NULL!");
114 result = Curl_parsenetrc("example.com", &login, &password, filename);
115 fail_unless(result == 0, "Host should be found");
116 abort_unless(password != NULL, "returned NULL!");
117 fail_unless(password[0] == 0, "password should not have been changed");
118 abort_unless(login != NULL, "returned NULL!");
119 fail_unless(strncmp(login, "adminn", 6) == 0,
120 "login should not have been changed");
123 * Test for the first existing host in our netrc file
128 abort_unless(login != NULL, "returned NULL!");
129 result = Curl_parsenetrc("example.com", &login, &password, filename);
130 fail_unless(result == 0, "Host should have been found");
131 abort_unless(password != NULL, "returned NULL!");
132 fail_unless(strncmp(password, "passwd", 6) == 0,
133 "password should be 'passwd'");
134 abort_unless(login != NULL, "returned NULL!");
135 fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'");
138 * Test for the first existing host in our netrc file
139 * with login[0] != 0.
142 password = strdup("");
143 abort_unless(password != NULL, "returned NULL!");
144 result = Curl_parsenetrc("example.com", &login, &password, filename);
145 fail_unless(result == 0, "Host should have been found");
146 abort_unless(password != NULL, "returned NULL!");
147 fail_unless(strncmp(password, "passwd", 6) == 0,
148 "password should be 'passwd'");
149 abort_unless(login != NULL, "returned NULL!");
150 fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'");
153 * Test for the second existing host in our netrc file
157 password = strdup("");
158 abort_unless(password != NULL, "returned NULL!");
161 abort_unless(login != NULL, "returned NULL!");
162 result = Curl_parsenetrc("curl.example.com", &login, &password, filename);
163 fail_unless(result == 0, "Host should have been found");
164 abort_unless(password != NULL, "returned NULL!");
165 fail_unless(strncmp(password, "none", 4) == 0,
166 "password should be 'none'");
167 abort_unless(login != NULL, "returned NULL!");
168 fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
171 * Test for the second existing host in our netrc file
172 * with login[0] != 0.
175 password = strdup("");
176 abort_unless(password != NULL, "returned NULL!");
177 result = Curl_parsenetrc("curl.example.com", &login, &password, filename);
178 fail_unless(result == 0, "Host should have been found");
179 abort_unless(password != NULL, "returned NULL!");
180 fail_unless(strncmp(password, "none", 4) == 0,
181 "password should be 'none'");
182 abort_unless(login != NULL, "returned NULL!");
183 fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
186 * Test over the size limit password / login!
187 * Test files with a bad format