1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2013, 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, "login should not have been changed");
78 * Test a non existent login and host in our netrc file.
82 abort_unless(login != NULL, "returned NULL!");
83 result = Curl_parsenetrc("test.example.com", &login, &password, filename);
84 fail_unless(result == 1, "Host should be found");
85 abort_unless(password != NULL, "returned NULL!");
86 fail_unless(password[0] == 0, "password should not have been changed");
87 abort_unless(login != NULL, "returned NULL!");
88 fail_unless(strncmp(login, "me", 2) == 0, "login should not have been changed");
91 * Test a non existent login (substring of an existing one) in our
95 login = strdup("admi");
96 abort_unless(login != NULL, "returned NULL!");
97 result = Curl_parsenetrc("example.com", &login, &password, filename);
98 fail_unless(result == 0, "Host should be found");
99 abort_unless(password != NULL, "returned NULL!");
100 fail_unless(password[0] == 0, "password should not have been changed");
101 abort_unless(login != NULL, "returned NULL!");
102 fail_unless(strncmp(login, "admi", 4) == 0, "login should not have been changed");
105 * Test a non existent login (superstring of an existing one)
109 login = strdup("adminn");
110 abort_unless(login != NULL, "returned NULL!");
111 result = Curl_parsenetrc("example.com", &login, &password, filename);
112 fail_unless(result == 0, "Host should be found");
113 abort_unless(password != NULL, "returned NULL!");
114 fail_unless(password[0] == 0, "password should not have been changed");
115 abort_unless(login != NULL, "returned NULL!");
116 fail_unless(strncmp(login, "adminn", 6) == 0, "login should not have been changed");
119 * Test for the first existing host in our netrc file
124 abort_unless(login != NULL, "returned NULL!");
125 result = Curl_parsenetrc("example.com", &login, &password, filename);
126 fail_unless(result == 0, "Host should have been found");
127 abort_unless(password != NULL, "returned NULL!");
128 fail_unless(strncmp(password, "passwd", 6) == 0,
129 "password should be 'passwd'");
130 abort_unless(login != NULL, "returned NULL!");
131 fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'");
134 * Test for the first existing host in our netrc file
135 * with login[0] != 0.
138 password = strdup("");
139 abort_unless(password != NULL, "returned NULL!");
140 result = Curl_parsenetrc("example.com", &login, &password, filename);
141 fail_unless(result == 0, "Host should have been found");
142 abort_unless(password != NULL, "returned NULL!");
143 fail_unless(strncmp(password, "passwd", 6) == 0,
144 "password should be 'passwd'");
145 abort_unless(login != NULL, "returned NULL!");
146 fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'");
149 * Test for the second existing host in our netrc file
153 password = strdup("");
154 abort_unless(password != NULL, "returned NULL!");
157 abort_unless(login != NULL, "returned NULL!");
158 result = Curl_parsenetrc("curl.example.com", &login, &password, filename);
159 fail_unless(result == 0, "Host should have been found");
160 abort_unless(password != NULL, "returned NULL!");
161 fail_unless(strncmp(password, "none", 4) == 0,
162 "password should be 'none'");
163 abort_unless(login != NULL, "returned NULL!");
164 fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
167 * Test for the second existing host in our netrc file
168 * with login[0] != 0.
171 password = strdup("");
172 abort_unless(password != NULL, "returned NULL!");
173 result = Curl_parsenetrc("curl.example.com", &login, &password, filename);
174 fail_unless(result == 0, "Host should have been found");
175 abort_unless(password != NULL, "returned NULL!");
176 fail_unless(strncmp(password, "none", 4) == 0,
177 "password should be 'none'");
178 abort_unless(login != NULL, "returned NULL!");
179 fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
182 * Test over the size limit password / login!
183 * Test files with a bad format