unit1304.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  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.
  13. *
  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.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. ***************************************************************************/
  22. #include "curlcheck.h"
  23. #include "netrc.h"
  24. static char login[LOGINSIZE];
  25. static char password[PASSWORDSIZE];
  26. static char filename[64];
  27. static CURLcode unit_setup(void)
  28. {
  29. password[0] = 0;
  30. login[0] = 0;
  31. return CURLE_OK;
  32. }
  33. static void unit_stop(void)
  34. {
  35. }
  36. UNITTEST_START
  37. int result;
  38. static const char* filename1 = "log/netrc1304";
  39. memcpy(filename, filename1, strlen(filename1));
  40. /*
  41. * Test a non existent host in our netrc file.
  42. */
  43. result = Curl_parsenetrc("test.example.com", login, password, filename);
  44. fail_unless(result == 1, "Host not found should return 1");
  45. fail_unless(password[0] == 0, "password should not have been changed");
  46. fail_unless(login[0] == 0, "login should not have been changed");
  47. /*
  48. * Test a non existent login in our netrc file.
  49. */
  50. memcpy(login, "me", 2);
  51. result = Curl_parsenetrc("example.com", login, password, filename);
  52. fail_unless(result == 0, "Host should be found");
  53. fail_unless(password[0] == 0, "password should not have been changed");
  54. fail_unless(strncmp(login, "me", 2) == 0, "login should not have been changed");
  55. /*
  56. * Test a non existent login and host in our netrc file.
  57. */
  58. memcpy(login, "me", 2);
  59. result = Curl_parsenetrc("test.example.com", login, password, filename);
  60. fail_unless(result == 1, "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");
  63. /*
  64. * Test a non existent login (substring of an existing one) in our
  65. * netrc file.
  66. */
  67. memcpy(login, "admi", 4);
  68. result = Curl_parsenetrc("example.com", login, password, filename);
  69. fail_unless(result == 0, "Host should be found");
  70. fail_unless(password[0] == 0, "password should not have been changed");
  71. fail_unless(strncmp(login, "admi", 4) == 0, "login should not have been changed");
  72. /*
  73. * Test a non existent login (superstring of an existing one)
  74. * in our netrc file.
  75. */
  76. memcpy(login, "adminn", 6);
  77. result = Curl_parsenetrc("example.com", login, password, filename);
  78. fail_unless(result == 0, "Host should be found");
  79. fail_unless(password[0] == 0, "password should not have been changed");
  80. fail_unless(strncmp(login, "adminn", 6) == 0, "login should not have been changed");
  81. /*
  82. * Test for the first existing host in our netrc file
  83. * with login[0] = 0.
  84. */
  85. login[0] = 0;
  86. result = Curl_parsenetrc("example.com", login, password, filename);
  87. fail_unless(result == 0, "Host should have been found");
  88. fail_unless(strncmp(password, "passwd", 6) == 0,
  89. "password should be 'passwd'");
  90. fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'");
  91. /*
  92. * Test for the first existing host in our netrc file
  93. * with login[0] != 0.
  94. */
  95. password[0] = 0;
  96. result = Curl_parsenetrc("example.com", login, password, filename);
  97. fail_unless(result == 0, "Host should have been found");
  98. fail_unless(strncmp(password, "passwd", 6) == 0,
  99. "password should be 'passwd'");
  100. fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'");
  101. /*
  102. * Test for the second existing host in our netrc file
  103. * with login[0] = 0.
  104. */
  105. password[0] = 0;
  106. login[0] = 0;
  107. result = Curl_parsenetrc("curl.example.com", login, password, filename);
  108. fail_unless(result == 0, "Host should have been found");
  109. fail_unless(strncmp(password, "none", 4) == 0,
  110. "password should be 'none'");
  111. fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
  112. /*
  113. * Test for the second existing host in our netrc file
  114. * with login[0] != 0.
  115. */
  116. password[0] = 0;
  117. result = Curl_parsenetrc("curl.example.com", login, password, filename);
  118. fail_unless(result == 0, "Host should have been found");
  119. fail_unless(strncmp(password, "none", 4) == 0,
  120. "password should be 'none'");
  121. fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
  122. /* TODO:
  123. * Test over the size limit password / login!
  124. * Test files with a bad format
  125. */
  126. UNITTEST_STOP