~ubuntu-branches/ubuntu/saucy/curl/saucy

« back to all changes in this revision

Viewing changes to tests/libtest/libauthretry.c

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2013-02-12 08:54:32 UTC
  • mfrom: (3.4.34 sid)
  • Revision ID: package-import@ubuntu.com-20130212085432-r1fyi0b37enr93pp
Tags: 7.29.0-1ubuntu1
* Resynchronise with Debian. Remaining changes:
  - Drop dependencies not in main:
    + Build-Depends: Drop stunnel4 and libssh2-1-dev.
    + Drop libssh2-1-dev from binary package Depends.
  - Add new libcurl3-udeb package.
  - Add new curl-udeb package.
* Add warning to debian/patches/series.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 */
26
26
 
27
27
#include "test.h"
28
 
 
 
28
#include "strequal.h"
29
29
#include "memdebug.h"
30
30
 
31
 
static int send_request(CURL *curl, const char *url, int seq, long auth_scheme, const char *userpwd)
 
31
static CURLcode send_request(CURL *curl, const char *url, int seq,
 
32
                             long auth_scheme, const char *userpwd)
32
33
{
33
34
  CURLcode res;
34
35
  char* full_url = malloc(strlen(url) + 4 + 1);
39
40
  }
40
41
 
41
42
  sprintf(full_url, "%s%04d", url, seq);
42
 
  fprintf(stderr, "Sending new request %d to %s with credential %s (auth %ld)\n", seq, full_url, userpwd, auth_scheme);
 
43
  fprintf(stderr, "Sending new request %d to %s with credential %s "
 
44
          "(auth %ld)\n", seq, full_url, userpwd, auth_scheme);
43
45
  test_setopt(curl, CURLOPT_URL, full_url);
44
46
  test_setopt(curl, CURLOPT_VERBOSE, 1L);
45
47
  test_setopt(curl, CURLOPT_HEADER, 1L);
50
52
  res = curl_easy_perform(curl);
51
53
 
52
54
test_cleanup:
53
 
  free(full_url); 
 
55
  free(full_url);
54
56
  return res;
55
57
}
56
58
 
57
 
static int send_wrong_password(CURL *curl, const char *url, int seq, long auth_scheme)
 
59
static CURLcode send_wrong_password(CURL *curl, const char *url, int seq,
 
60
                                    long auth_scheme)
58
61
{
59
62
    return send_request(curl, url, seq, auth_scheme, "testuser:wrongpass");
60
63
}
61
64
 
62
 
static int send_right_password(CURL *curl, const char *url, int seq, long auth_scheme)
 
65
static CURLcode send_right_password(CURL *curl, const char *url, int seq,
 
66
                                    long auth_scheme)
63
67
{
64
68
    return send_request(curl, url, seq, auth_scheme, "testuser:testpass");
65
69
}
68
72
{
69
73
  if (!arg)
70
74
    return CURLAUTH_NONE;
71
 
  if (strcasecmp(arg, "basic") == 0)
 
75
  if (strequal(arg, "basic"))
72
76
    return CURLAUTH_BASIC;
73
 
  if (strcasecmp(arg, "digest") == 0)
 
77
  if (strequal(arg, "digest"))
74
78
    return CURLAUTH_DIGEST;
75
 
  if (strcasecmp(arg, "ntlm") == 0)
 
79
  if (strequal(arg, "ntlm"))
76
80
    return CURLAUTH_NTLM;
77
81
  return CURLAUTH_NONE;
78
82
}
81
85
{
82
86
  CURLcode res;
83
87
  CURL *curl = NULL;
84
 
  bool curl_is_init = FALSE;
85
88
 
86
89
  long main_auth_scheme = parse_auth_name(libtest_arg2);
87
90
  long fallback_auth_scheme = parse_auth_name(libtest_arg3);
88
91
 
89
92
  if (main_auth_scheme == CURLAUTH_NONE ||
90
 
   fallback_auth_scheme == CURLAUTH_NONE) {
 
93
      fallback_auth_scheme == CURLAUTH_NONE) {
91
94
    fprintf(stderr, "auth schemes not found on commandline\n");
92
 
    res = TEST_ERR_MAJOR_BAD;
93
 
    goto test_cleanup;
 
95
    return TEST_ERR_MAJOR_BAD;
94
96
  }
95
97
 
96
98
  if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
97
99
    fprintf(stderr, "curl_global_init() failed\n");
98
 
    res = TEST_ERR_MAJOR_BAD;
99
 
    goto test_cleanup;
 
100
    return TEST_ERR_MAJOR_BAD;
100
101
  }
101
 
  curl_is_init = TRUE;
102
102
 
103
103
  /* Send wrong password, then right password */
104
104
 
105
105
  if ((curl = curl_easy_init()) == NULL) {
106
106
    fprintf(stderr, "curl_easy_init() failed\n");
107
 
    res = TEST_ERR_MAJOR_BAD;
108
 
    goto test_cleanup;
 
107
    curl_global_cleanup();
 
108
    return TEST_ERR_MAJOR_BAD;
109
109
  }
110
110
 
111
111
  res = send_wrong_password(curl, url, 100, main_auth_scheme);
112
112
  if (res != CURLE_OK)
113
113
      goto test_cleanup;
114
114
  curl_easy_reset(curl);
 
115
 
115
116
  res = send_right_password(curl, url, 200, fallback_auth_scheme);
116
117
  if (res != CURLE_OK)
117
118
      goto test_cleanup;
123
124
 
124
125
  if ((curl = curl_easy_init()) == NULL) {
125
126
    fprintf(stderr, "curl_easy_init() failed\n");
126
 
    res = TEST_ERR_MAJOR_BAD;
127
 
    goto test_cleanup;
 
127
    curl_global_cleanup();
 
128
    return TEST_ERR_MAJOR_BAD;
128
129
  }
129
130
 
130
131
  res = send_wrong_password(curl, url, 300, main_auth_scheme);
136
137
  if (res != CURLE_OK)
137
138
      goto test_cleanup;
138
139
  curl_easy_reset(curl);
 
140
 
139
141
  res = send_right_password(curl, url, 500, fallback_auth_scheme);
140
142
  if (res != CURLE_OK)
141
143
      goto test_cleanup;
143
145
 
144
146
test_cleanup:
145
147
 
146
 
  if (curl)
147
 
    curl_easy_cleanup(curl);
148
 
  if (curl_is_init)
149
 
    curl_global_cleanup();
 
148
  curl_easy_cleanup(curl);
 
149
  curl_global_cleanup();
150
150
 
151
151
  return (int)res;
152
152
}