aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl/test_digestauth.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcurl/test_digestauth.c')
-rw-r--r--src/testcurl/test_digestauth.c77
1 files changed, 40 insertions, 37 deletions
diff --git a/src/testcurl/test_digestauth.c b/src/testcurl/test_digestauth.c
index 255e086a..fd579196 100644
--- a/src/testcurl/test_digestauth.c
+++ b/src/testcurl/test_digestauth.c
@@ -73,7 +73,8 @@ ahc_echo (void *cls,
73 const char *url, 73 const char *url,
74 const char *method, 74 const char *method,
75 const char *version, 75 const char *version,
76 const char *upload_data, size_t *upload_data_size, 76 const char *upload_data,
77 size_t *upload_data_size,
77 void **unused) 78 void **unused)
78{ 79{
79 struct MHD_Response *response; 80 struct MHD_Response *response;
@@ -82,44 +83,47 @@ ahc_echo (void *cls,
82 const char *realm = "test@example.com"; 83 const char *realm = "test@example.com";
83 int ret; 84 int ret;
84 85
85 username = MHD_digest_auth_get_username(connection); 86 username = MHD_digest_auth_get_username (connection);
86 if ( (username == NULL) || 87 if ( (username == NULL) ||
87 (0 != strcmp (username, "testuser")) ) 88 (0 != strcmp (username, "testuser")) )
88 { 89 {
89 response = MHD_create_response_from_buffer(strlen (DENIED), 90 response = MHD_create_response_from_buffer (strlen (DENIED),
90 DENIED, 91 DENIED,
91 MHD_RESPMEM_PERSISTENT); 92 MHD_RESPMEM_PERSISTENT);
92 ret = MHD_queue_auth_fail_response(connection, realm, 93 ret = MHD_queue_auth_fail_response(connection, realm,
93 MY_OPAQUE, 94 MY_OPAQUE,
94 response, 95 response,
95 MHD_NO); 96 MHD_NO);
96 MHD_destroy_response(response); 97 MHD_destroy_response(response);
97 return ret; 98 return ret;
98 } 99 }
99 ret = MHD_digest_auth_check(connection, realm, 100 ret = MHD_digest_auth_check(connection, realm,
100 username, 101 username,
101 password, 102 password,
102 300); 103 300);
103 free(username); 104 free(username);
104 if ( (ret == MHD_INVALID_NONCE) || 105 if ( (ret == MHD_INVALID_NONCE) ||
105 (ret == MHD_NO) ) 106 (ret == MHD_NO) )
106 { 107 {
107 response = MHD_create_response_from_buffer(strlen (DENIED), 108 response = MHD_create_response_from_buffer(strlen (DENIED),
108 DENIED, 109 DENIED,
109 MHD_RESPMEM_PERSISTENT); 110 MHD_RESPMEM_PERSISTENT);
110 if (NULL == response) 111 if (NULL == response)
111 return MHD_NO; 112 return MHD_NO;
112 ret = MHD_queue_auth_fail_response(connection, realm, 113 ret = MHD_queue_auth_fail_response(connection, realm,
113 MY_OPAQUE, 114 MY_OPAQUE,
114 response, 115 response,
115 (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO); 116 (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO);
116 MHD_destroy_response(response); 117 MHD_destroy_response(response);
117 return ret; 118 return ret;
118 } 119 }
119 response = MHD_create_response_from_buffer(strlen(PAGE), PAGE, 120 response = MHD_create_response_from_buffer (strlen(PAGE),
120 MHD_RESPMEM_PERSISTENT); 121 PAGE,
121 ret = MHD_queue_response(connection, MHD_HTTP_OK, response); 122 MHD_RESPMEM_PERSISTENT);
122 MHD_destroy_response(response); 123 ret = MHD_queue_response (connection,
124 MHD_HTTP_OK,
125 response);
126 MHD_destroy_response (response);
123 return ret; 127 return ret;
124} 128}
125 129
@@ -144,24 +148,24 @@ testDigestAuth ()
144 fd = open("/dev/urandom", O_RDONLY); 148 fd = open("/dev/urandom", O_RDONLY);
145 if (-1 == fd) 149 if (-1 == fd)
146 { 150 {
147 fprintf(stderr, "Failed to open `%s': %s\n", 151 fprintf(stderr, "Failed to open `%s': %s\n",
148 "/dev/urandom", 152 "/dev/urandom",
149 strerror(errno)); 153 strerror(errno));
150 return 1; 154 return 1;
151 } 155 }
152 while (off < 8) 156 while (off < 8)
153 { 157 {
154 len = read(fd, rnd, 8); 158 len = read(fd, rnd, 8);
155 if (len == -1) 159 if (len == -1)
156 { 160 {
157 fprintf(stderr, "Failed to read `%s': %s\n", 161 fprintf(stderr, "Failed to read `%s': %s\n",
158 "/dev/urandom", 162 "/dev/urandom",
159 strerror(errno)); 163 strerror(errno));
160 (void) close(fd); 164 (void) close(fd);
161 return 1; 165 return 1;
162 } 166 }
163 off += len; 167 off += len;
164 } 168 }
165 (void) close(fd); 169 (void) close(fd);
166#else 170#else
167 { 171 {
@@ -193,7 +197,7 @@ testDigestAuth ()
193 if (d == NULL) 197 if (d == NULL)
194 return 1; 198 return 1;
195 c = curl_easy_init (); 199 c = curl_easy_init ();
196 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:1337/"); 200 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:1337/bar%20 foo?a=bü%20");
197 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 201 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
198 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 202 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
199 curl_easy_setopt (c, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); 203 curl_easy_setopt (c, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
@@ -225,7 +229,6 @@ testDigestAuth ()
225} 229}
226 230
227 231
228
229int 232int
230main (int argc, char *const *argv) 233main (int argc, char *const *argv)
231{ 234{