unit1304.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 #include "curlcheck.h"
00023 #include "netrc.h"
00024 #include "memdebug.h" /* LAST include file */
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    * Test a non existent host in our netrc file.
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    * Test a non existent login in our netrc file.
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    * Test a non existent login and host in our netrc file.
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    * Test a non existent login (substring of an existing one) in our
00094    * netrc file.
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    * Test a non existent login (superstring of an existing one)
00109    * in our netrc file.
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    * Test for the first existing host in our netrc file
00124    * with login[0] = 0.
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    * Test for the first existing host in our netrc file
00139    * with login[0] != 0.
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    * Test for the second existing host in our netrc file
00154    * with login[0] = 0.
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    * Test for the second existing host in our netrc file
00172    * with login[0] != 0.
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   /* TODO:
00186    * Test over the size limit password / login!
00187    * Test files with a bad format
00188    */
00189 UNITTEST_STOP


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:07