1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2011, 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 http://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"
26 static char login[LOGINSIZE];
27 static char password[PASSWORDSIZE];
28 static char filename[64];
30 static CURLcode unit_setup(void)
37 static void unit_stop(void)
44 static const char* filename1 = "log/netrc1304";
45 memcpy(filename, filename1, strlen(filename1));
48 * Test a non existent host in our netrc file.
50 result = Curl_parsenetrc("test.example.com", login, password, filename);
51 fail_unless(result == 1, "Host not found should return 1");
52 fail_unless(password[0] == 0, "password should not have been changed");
53 fail_unless(login[0] == 0, "login should not have been changed");
56 * Test a non existent login in our netrc file.
58 memcpy(login, "me", 2);
59 result = Curl_parsenetrc("example.com", login, password, filename);
60 fail_unless(result == 0, "Host should be found");
61 fail_unless(password[0] == 0, "password should not have been changed");
62 fail_unless(strncmp(login, "me", 2) == 0, "login should not have been changed");
65 * Test a non existent login and host in our netrc file.
67 memcpy(login, "me", 2);
68 result = Curl_parsenetrc("test.example.com", login, password, filename);
69 fail_unless(result == 1, "Host should be found");
70 fail_unless(password[0] == 0, "password should not have been changed");
71 fail_unless(strncmp(login, "me", 2) == 0, "login should not have been changed");
74 * Test a non existent login (substring of an existing one) in our
77 memcpy(login, "admi", 4);
78 result = Curl_parsenetrc("example.com", login, password, filename);
79 fail_unless(result == 0, "Host should be found");
80 fail_unless(password[0] == 0, "password should not have been changed");
81 fail_unless(strncmp(login, "admi", 4) == 0, "login should not have been changed");
84 * Test a non existent login (superstring of an existing one)
87 memcpy(login, "adminn", 6);
88 result = Curl_parsenetrc("example.com", login, password, filename);
89 fail_unless(result == 0, "Host should be found");
90 fail_unless(password[0] == 0, "password should not have been changed");
91 fail_unless(strncmp(login, "adminn", 6) == 0, "login should not have been changed");
94 * Test for the first existing host in our netrc file
98 result = Curl_parsenetrc("example.com", login, password, filename);
99 fail_unless(result == 0, "Host should have been found");
100 fail_unless(strncmp(password, "passwd", 6) == 0,
101 "password should be 'passwd'");
102 fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'");
105 * Test for the first existing host in our netrc file
106 * with login[0] != 0.
109 result = Curl_parsenetrc("example.com", login, password, filename);
110 fail_unless(result == 0, "Host should have been found");
111 fail_unless(strncmp(password, "passwd", 6) == 0,
112 "password should be 'passwd'");
113 fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'");
116 * Test for the second existing host in our netrc file
121 result = Curl_parsenetrc("curl.example.com", login, password, filename);
122 fail_unless(result == 0, "Host should have been found");
123 fail_unless(strncmp(password, "none", 4) == 0,
124 "password should be 'none'");
125 fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
128 * Test for the second existing host in our netrc file
129 * with login[0] != 0.
132 result = Curl_parsenetrc("curl.example.com", login, password, filename);
133 fail_unless(result == 0, "Host should have been found");
134 fail_unless(strncmp(password, "none", 4) == 0,
135 "password should be 'none'");
136 fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
139 * Test over the size limit password / login!
140 * Test files with a bad format