00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "curlcheck.h"
00023 #include "netrc.h"
00024 #include "memdebug.h"
00025
00026 static char *login;
00027 static char *password;
00028 static char filename[64];
00029
00030 static CURLcode unit_setup(void)
00031 {
00032 password = strdup("");
00033 login = strdup("");
00034 if(!password || !login) {
00035 Curl_safefree(password);
00036 Curl_safefree(login);
00037 return CURLE_OUT_OF_MEMORY;
00038 }
00039 return CURLE_OK;
00040 }
00041
00042 static void unit_stop(void)
00043 {
00044 Curl_safefree(password);
00045 Curl_safefree(login);
00046 }
00047
00048 UNITTEST_START
00049 int result;
00050
00051 static const char * const filename1 = "log/netrc1304";
00052 memcpy(filename, filename1, strlen(filename1));
00053
00054
00055
00056
00057 result = Curl_parsenetrc("test.example.com", &login, &password, filename);
00058 fail_unless(result == 1, "Host not found should return 1");
00059 abort_unless(password != NULL, "returned NULL!");
00060 fail_unless(password[0] == 0, "password should not have been changed");
00061 abort_unless(login != NULL, "returned NULL!");
00062 fail_unless(login[0] == 0, "login should not have been changed");
00063
00064
00065
00066
00067 free(login);
00068 login = strdup("me");
00069 abort_unless(login != NULL, "returned NULL!");
00070 result = Curl_parsenetrc("example.com", &login, &password, filename);
00071 fail_unless(result == 0, "Host should be found");
00072 abort_unless(password != NULL, "returned NULL!");
00073 fail_unless(password[0] == 0, "password should not have been changed");
00074 abort_unless(login != NULL, "returned NULL!");
00075 fail_unless(strncmp(login, "me", 2) == 0,
00076 "login should not have been changed");
00077
00078
00079
00080
00081 free(login);
00082 login = strdup("me");
00083 abort_unless(login != NULL, "returned NULL!");
00084 result = Curl_parsenetrc("test.example.com", &login, &password, filename);
00085 fail_unless(result == 1, "Host should be found");
00086 abort_unless(password != NULL, "returned NULL!");
00087 fail_unless(password[0] == 0, "password should not have been changed");
00088 abort_unless(login != NULL, "returned NULL!");
00089 fail_unless(strncmp(login, "me", 2) == 0,
00090 "login should not have been changed");
00091
00092
00093
00094
00095
00096 free(login);
00097 login = strdup("admi");
00098 abort_unless(login != NULL, "returned NULL!");
00099 result = Curl_parsenetrc("example.com", &login, &password, filename);
00100 fail_unless(result == 0, "Host should be found");
00101 abort_unless(password != NULL, "returned NULL!");
00102 fail_unless(password[0] == 0, "password should not have been changed");
00103 abort_unless(login != NULL, "returned NULL!");
00104 fail_unless(strncmp(login, "admi", 4) == 0,
00105 "login should not have been changed");
00106
00107
00108
00109
00110
00111 free(login);
00112 login = strdup("adminn");
00113 abort_unless(login != NULL, "returned NULL!");
00114 result = Curl_parsenetrc("example.com", &login, &password, filename);
00115 fail_unless(result == 0, "Host should be found");
00116 abort_unless(password != NULL, "returned NULL!");
00117 fail_unless(password[0] == 0, "password should not have been changed");
00118 abort_unless(login != NULL, "returned NULL!");
00119 fail_unless(strncmp(login, "adminn", 6) == 0,
00120 "login should not have been changed");
00121
00122
00123
00124
00125
00126 free(login);
00127 login = strdup("");
00128 abort_unless(login != NULL, "returned NULL!");
00129 result = Curl_parsenetrc("example.com", &login, &password, filename);
00130 fail_unless(result == 0, "Host should have been found");
00131 abort_unless(password != NULL, "returned NULL!");
00132 fail_unless(strncmp(password, "passwd", 6) == 0,
00133 "password should be 'passwd'");
00134 abort_unless(login != NULL, "returned NULL!");
00135 fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'");
00136
00137
00138
00139
00140
00141 free(password);
00142 password = strdup("");
00143 abort_unless(password != NULL, "returned NULL!");
00144 result = Curl_parsenetrc("example.com", &login, &password, filename);
00145 fail_unless(result == 0, "Host should have been found");
00146 abort_unless(password != NULL, "returned NULL!");
00147 fail_unless(strncmp(password, "passwd", 6) == 0,
00148 "password should be 'passwd'");
00149 abort_unless(login != NULL, "returned NULL!");
00150 fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'");
00151
00152
00153
00154
00155
00156 free(password);
00157 password = strdup("");
00158 abort_unless(password != NULL, "returned NULL!");
00159 free(login);
00160 login = strdup("");
00161 abort_unless(login != NULL, "returned NULL!");
00162 result = Curl_parsenetrc("curl.example.com", &login, &password, filename);
00163 fail_unless(result == 0, "Host should have been found");
00164 abort_unless(password != NULL, "returned NULL!");
00165 fail_unless(strncmp(password, "none", 4) == 0,
00166 "password should be 'none'");
00167 abort_unless(login != NULL, "returned NULL!");
00168 fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
00169
00170
00171
00172
00173
00174 free(password);
00175 password = strdup("");
00176 abort_unless(password != NULL, "returned NULL!");
00177 result = Curl_parsenetrc("curl.example.com", &login, &password, filename);
00178 fail_unless(result == 0, "Host should have been found");
00179 abort_unless(password != NULL, "returned NULL!");
00180 fail_unless(strncmp(password, "none", 4) == 0,
00181 "password should be 'none'");
00182 abort_unless(login != NULL, "returned NULL!");
00183 fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
00184
00185
00186
00187
00188
00189 UNITTEST_STOP