诸暨麻将添加redis
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

154 lines
4.4 KiB

  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2012, 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. /* argv1 = URL
  23. * argv2 = main auth type
  24. * argv3 = second auth type
  25. */
  26. #include "test.h"
  27. #include "strequal.h"
  28. #include "memdebug.h"
  29. static CURLcode send_request(CURL *curl, const char *url, int seq,
  30. long auth_scheme, const char *userpwd)
  31. {
  32. CURLcode res;
  33. char* full_url = malloc(strlen(url) + 4 + 1);
  34. if (!full_url) {
  35. fprintf(stderr, "Not enough memory for full url\n");
  36. res = CURLE_OUT_OF_MEMORY;
  37. goto test_cleanup;
  38. }
  39. sprintf(full_url, "%s%04d", url, seq);
  40. fprintf(stderr, "Sending new request %d to %s with credential %s "
  41. "(auth %ld)\n", seq, full_url, userpwd, auth_scheme);
  42. test_setopt(curl, CURLOPT_URL, full_url);
  43. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  44. test_setopt(curl, CURLOPT_HEADER, 1L);
  45. test_setopt(curl, CURLOPT_HTTPGET, 1L);
  46. test_setopt(curl, CURLOPT_USERPWD, userpwd);
  47. test_setopt(curl, CURLOPT_HTTPAUTH, auth_scheme);
  48. res = curl_easy_perform(curl);
  49. test_cleanup:
  50. free(full_url);
  51. return res;
  52. }
  53. static CURLcode send_wrong_password(CURL *curl, const char *url, int seq,
  54. long auth_scheme)
  55. {
  56. return send_request(curl, url, seq, auth_scheme, "testuser:wrongpass");
  57. }
  58. static CURLcode send_right_password(CURL *curl, const char *url, int seq,
  59. long auth_scheme)
  60. {
  61. return send_request(curl, url, seq, auth_scheme, "testuser:testpass");
  62. }
  63. static long parse_auth_name(const char *arg)
  64. {
  65. if (!arg)
  66. return CURLAUTH_NONE;
  67. if (strequal(arg, "basic"))
  68. return CURLAUTH_BASIC;
  69. if (strequal(arg, "digest"))
  70. return CURLAUTH_DIGEST;
  71. if (strequal(arg, "ntlm"))
  72. return CURLAUTH_NTLM;
  73. return CURLAUTH_NONE;
  74. }
  75. int test(char *url)
  76. {
  77. CURLcode res;
  78. CURL *curl = NULL;
  79. long main_auth_scheme = parse_auth_name(libtest_arg2);
  80. long fallback_auth_scheme = parse_auth_name(libtest_arg3);
  81. if (main_auth_scheme == CURLAUTH_NONE ||
  82. fallback_auth_scheme == CURLAUTH_NONE) {
  83. fprintf(stderr, "auth schemes not found on commandline\n");
  84. return TEST_ERR_MAJOR_BAD;
  85. }
  86. if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
  87. fprintf(stderr, "curl_global_init() failed\n");
  88. return TEST_ERR_MAJOR_BAD;
  89. }
  90. /* Send wrong password, then right password */
  91. if ((curl = curl_easy_init()) == NULL) {
  92. fprintf(stderr, "curl_easy_init() failed\n");
  93. curl_global_cleanup();
  94. return TEST_ERR_MAJOR_BAD;
  95. }
  96. res = send_wrong_password(curl, url, 100, main_auth_scheme);
  97. if (res != CURLE_OK)
  98. goto test_cleanup;
  99. curl_easy_reset(curl);
  100. res = send_right_password(curl, url, 200, fallback_auth_scheme);
  101. if (res != CURLE_OK)
  102. goto test_cleanup;
  103. curl_easy_reset(curl);
  104. curl_easy_cleanup(curl);
  105. /* Send wrong password twice, then right password */
  106. if ((curl = curl_easy_init()) == NULL) {
  107. fprintf(stderr, "curl_easy_init() failed\n");
  108. curl_global_cleanup();
  109. return TEST_ERR_MAJOR_BAD;
  110. }
  111. res = send_wrong_password(curl, url, 300, main_auth_scheme);
  112. if (res != CURLE_OK)
  113. goto test_cleanup;
  114. curl_easy_reset(curl);
  115. res = send_wrong_password(curl, url, 400, fallback_auth_scheme);
  116. if (res != CURLE_OK)
  117. goto test_cleanup;
  118. curl_easy_reset(curl);
  119. res = send_right_password(curl, url, 500, fallback_auth_scheme);
  120. if (res != CURLE_OK)
  121. goto test_cleanup;
  122. curl_easy_reset(curl);
  123. test_cleanup:
  124. curl_easy_cleanup(curl);
  125. curl_global_cleanup();
  126. return (int)res;
  127. }