1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
|
/* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
#include <apr_strings.h>
#include "serf.h"
#include "test_serf.h"
static apr_status_t
authn_callback_expect_not_called(char **username,
char **password,
serf_request_t *request, void *baton,
int code, const char *authn_type,
const char *realm,
apr_pool_t *pool)
{
handler_baton_t *handler_ctx = baton;
test_baton_t *tb = handler_ctx->tb;
tb->result_flags |= TEST_RESULT_AUTHNCB_CALLED;
/* Should not have been called. */
return SERF_ERROR_ISSUE_IN_TESTSUITE;
}
/* Tests that authn fails if all authn schemes are disabled. */
static void test_authentication_disabled(CuTest *tc)
{
test_baton_t *tb;
handler_baton_t handler_ctx[2];
test_server_message_t message_list[] = {
{CHUNKED_REQUEST(1, "1")} };
test_server_action_t action_list[] = {
{SERVER_RESPOND, "HTTP/1.1 401 Unauthorized" CRLF
"Transfer-Encoding: chunked" CRLF
"WWW-Authenticate: Basic realm=""Test Suite""" CRLF
CRLF
"0" CRLF CRLF},
};
apr_status_t status;
apr_pool_t *test_pool = tc->testBaton;
/* Set up a test context with a server */
status = test_http_server_setup(&tb,
message_list, 1,
action_list, 1, 0, NULL,
test_pool);
CuAssertIntEquals(tc, APR_SUCCESS, status);
serf_config_authn_types(tb->context, SERF_AUTHN_NONE);
serf_config_credentials_callback(tb->context,
authn_callback_expect_not_called);
create_new_request(tb, &handler_ctx[0], "GET", "/", 1);
status = test_helper_run_requests_no_check(tc, tb, 1,
handler_ctx, test_pool);
CuAssertIntEquals(tc, SERF_ERROR_AUTHN_NOT_SUPPORTED, status);
CuAssertIntEquals(tc, 1, tb->sent_requests->nelts);
CuAssertIntEquals(tc, 1, tb->accepted_requests->nelts);
CuAssertIntEquals(tc, 0, tb->handled_requests->nelts);
CuAssertTrue(tc, !(tb->result_flags & TEST_RESULT_AUTHNCB_CALLED));
}
/* Tests that authn fails if encountered an unsupported scheme. */
static void test_unsupported_authentication(CuTest *tc)
{
test_baton_t *tb;
handler_baton_t handler_ctx[2];
test_server_message_t message_list[] = {
{CHUNKED_REQUEST(1, "1")} };
test_server_action_t action_list[] = {
{SERVER_RESPOND, "HTTP/1.1 401 Unauthorized" CRLF
"Transfer-Encoding: chunked" CRLF
"WWW-Authenticate: NotExistent realm=""Test Suite""" CRLF
CRLF
"0" CRLF CRLF},
};
apr_status_t status;
apr_pool_t *test_pool = tc->testBaton;
/* Set up a test context with a server */
status = test_http_server_setup(&tb,
message_list, 1,
action_list, 1, 0, NULL,
test_pool);
CuAssertIntEquals(tc, APR_SUCCESS, status);
serf_config_authn_types(tb->context, SERF_AUTHN_ALL);
serf_config_credentials_callback(tb->context,
authn_callback_expect_not_called);
create_new_request(tb, &handler_ctx[0], "GET", "/", 1);
status = test_helper_run_requests_no_check(tc, tb, 1,
handler_ctx, test_pool);
CuAssertIntEquals(tc, SERF_ERROR_AUTHN_NOT_SUPPORTED, status);
CuAssertIntEquals(tc, 1, tb->sent_requests->nelts);
CuAssertIntEquals(tc, 1, tb->accepted_requests->nelts);
CuAssertIntEquals(tc, 0, tb->handled_requests->nelts);
CuAssertTrue(tc, !(tb->result_flags & TEST_RESULT_AUTHNCB_CALLED));
}
static apr_status_t
basic_authn_callback(char **username,
char **password,
serf_request_t *request, void *baton,
int code, const char *authn_type,
const char *realm,
apr_pool_t *pool)
{
handler_baton_t *handler_ctx = baton;
test_baton_t *tb = handler_ctx->tb;
tb->result_flags |= TEST_RESULT_AUTHNCB_CALLED;
if (code != 401)
return SERF_ERROR_ISSUE_IN_TESTSUITE;
if (strcmp("Basic", authn_type) != 0)
return SERF_ERROR_ISSUE_IN_TESTSUITE;
if (strcmp("<http://localhost:12345> Test Suite", realm) != 0)
return SERF_ERROR_ISSUE_IN_TESTSUITE;
*username = "serf";
*password = "serftest";
return APR_SUCCESS;
}
/* Test template, used for KeepAlive Off and KeepAlive On test */
static void basic_authentication(CuTest *tc, const char *resp_hdrs)
{
test_baton_t *tb;
handler_baton_t handler_ctx[2];
int num_requests_sent, num_requests_recvd;
test_server_message_t message_list[3];
test_server_action_t action_list[3];
apr_status_t status;
apr_pool_t *test_pool = tc->testBaton;
/* Expected string relies on strict order of headers, which is not
guaranteed. c2VyZjpzZXJmdGVzdA== is base64 encoded serf:serftest . */
message_list[0].text = CHUNKED_REQUEST(1, "1");
message_list[1].text = apr_psprintf(test_pool,
"GET / HTTP/1.1" CRLF
"Host: localhost:12345" CRLF
"Authorization: Basic c2VyZjpzZXJmdGVzdA==" CRLF
"Transfer-Encoding: chunked" CRLF
CRLF
"1" CRLF
"1" CRLF
"0" CRLF CRLF);
message_list[2].text = apr_psprintf(test_pool,
"GET / HTTP/1.1" CRLF
"Host: localhost:12345" CRLF
"Authorization: Basic c2VyZjpzZXJmdGVzdA==" CRLF
"Transfer-Encoding: chunked" CRLF
CRLF
"1" CRLF
"2" CRLF
"0" CRLF CRLF);
action_list[0].kind = SERVER_RESPOND;
/* Use non-standard case WWW-Authenticate header and scheme name to test
for case insensitive comparisons. */
action_list[0].text = apr_psprintf(test_pool,
"HTTP/1.1 401 Unauthorized" CRLF
"Transfer-Encoding: chunked" CRLF
"www-Authenticate: bAsIc realm=""Test Suite""" CRLF
"%s"
CRLF
"0" CRLF CRLF, resp_hdrs);
action_list[1].kind = SERVER_RESPOND;
action_list[1].text = CHUNKED_EMPTY_RESPONSE;
action_list[2].kind = SERVER_RESPOND;
action_list[2].text = CHUNKED_EMPTY_RESPONSE;
/* Set up a test context with a server */
status = test_http_server_setup(&tb,
message_list, 3,
action_list, 3, 0, NULL,
test_pool);
CuAssertIntEquals(tc, APR_SUCCESS, status);
serf_config_authn_types(tb->context, SERF_AUTHN_BASIC);
serf_config_credentials_callback(tb->context, basic_authn_callback);
create_new_request(tb, &handler_ctx[0], "GET", "/", 1);
/* Test that a request is retried and authentication headers are set
correctly. */
num_requests_sent = 1;
num_requests_recvd = 2;
status = test_helper_run_requests_no_check(tc, tb, num_requests_sent,
handler_ctx, test_pool);
CuAssertIntEquals(tc, APR_SUCCESS, status);
CuAssertIntEquals(tc, num_requests_recvd, tb->sent_requests->nelts);
CuAssertIntEquals(tc, num_requests_recvd, tb->accepted_requests->nelts);
CuAssertIntEquals(tc, num_requests_sent, tb->handled_requests->nelts);
CuAssertTrue(tc, tb->result_flags & TEST_RESULT_AUTHNCB_CALLED);
/* Test that credentials were cached by asserting that the authn callback
wasn't called again. */
tb->result_flags = 0;
create_new_request(tb, &handler_ctx[0], "GET", "/", 2);
status = test_helper_run_requests_no_check(tc, tb, num_requests_sent,
handler_ctx, test_pool);
CuAssertIntEquals(tc, APR_SUCCESS, status);
CuAssertTrue(tc, !(tb->result_flags & TEST_RESULT_AUTHNCB_CALLED));
}
static void test_basic_authentication(CuTest *tc)
{
basic_authentication(tc, "");
}
static void test_basic_authentication_keepalive_off(CuTest *tc)
{
basic_authentication(tc, "Connection: close" CRLF);
}
static apr_status_t
digest_authn_callback(char **username,
char **password,
serf_request_t *request, void *baton,
int code, const char *authn_type,
const char *realm,
apr_pool_t *pool)
{
handler_baton_t *handler_ctx = baton;
test_baton_t *tb = handler_ctx->tb;
tb->result_flags |= TEST_RESULT_AUTHNCB_CALLED;
if (code != 401)
return SERF_ERROR_ISSUE_IN_TESTSUITE;
if (strcmp("Digest", authn_type) != 0)
return SERF_ERROR_ISSUE_IN_TESTSUITE;
if (strcmp("<http://localhost:12345> Test Suite", realm) != 0)
return SERF_ERROR_ISSUE_IN_TESTSUITE;
*username = "serf";
*password = "serftest";
return APR_SUCCESS;
}
/* Test template, used for KeepAlive Off and KeepAlive On test */
static void digest_authentication(CuTest *tc, const char *resp_hdrs)
{
test_baton_t *tb;
handler_baton_t handler_ctx[2];
int num_requests_sent, num_requests_recvd;
test_server_message_t message_list[2];
test_server_action_t action_list[2];
apr_pool_t *test_pool = tc->testBaton;
apr_status_t status;
/* Expected string relies on strict order of headers and attributes of
Digest, both are not guaranteed.
6ff0d4cc201513ce970d5c6b25e1043b is encoded as:
md5hex(md5hex("serf:Test Suite:serftest") & ":" &
md5hex("ABCDEF1234567890") & ":" &
md5hex("GET:/test/index.html"))
*/
message_list[0].text = CHUNKED_REQUEST_URI("/test/index.html", 1, "1");
message_list[1].text = apr_psprintf(test_pool,
"GET /test/index.html HTTP/1.1" CRLF
"Host: localhost:12345" CRLF
"Authorization: Digest realm=\"Test Suite\", username=\"serf\", "
"nonce=\"ABCDEF1234567890\", uri=\"/test/index.html\", "
"response=\"6ff0d4cc201513ce970d5c6b25e1043b\", opaque=\"myopaque\", "
"algorithm=\"MD5\"" CRLF
"Transfer-Encoding: chunked" CRLF
CRLF
"1" CRLF
"1" CRLF
"0" CRLF CRLF);
action_list[0].kind = SERVER_RESPOND;
action_list[0].text = apr_psprintf(test_pool,
"HTTP/1.1 401 Unauthorized" CRLF
"Transfer-Encoding: chunked" CRLF
"WWW-Authenticate: Digest realm=\"Test Suite\","
"nonce=\"ABCDEF1234567890\",opaque=\"myopaque\","
"algorithm=\"MD5\",qop-options=\"auth\"" CRLF
"%s"
CRLF
"0" CRLF CRLF, resp_hdrs);
/* If the resp_hdrs includes "Connection: close", serf will automatically
reset the connection from the client side, no need to use
SERVER_KILL_CONNECTION. */
action_list[1].kind = SERVER_RESPOND;
action_list[1].text = CHUNKED_EMPTY_RESPONSE;
/* Set up a test context with a server */
status = test_http_server_setup(&tb,
message_list, 2,
action_list, 2, 0, NULL,
test_pool);
CuAssertIntEquals(tc, APR_SUCCESS, status);
/* Add both Basic and Digest here, should use Digest only. */
serf_config_authn_types(tb->context, SERF_AUTHN_BASIC | SERF_AUTHN_DIGEST);
serf_config_credentials_callback(tb->context, digest_authn_callback);
create_new_request(tb, &handler_ctx[0], "GET", "/test/index.html", 1);
/* Test that a request is retried and authentication headers are set
correctly. */
num_requests_sent = 1;
num_requests_recvd = 2;
status = test_helper_run_requests_no_check(tc, tb, num_requests_sent,
handler_ctx, test_pool);
CuAssertIntEquals(tc, APR_SUCCESS, status);
CuAssertIntEquals(tc, num_requests_recvd, tb->sent_requests->nelts);
CuAssertIntEquals(tc, num_requests_recvd, tb->accepted_requests->nelts);
CuAssertIntEquals(tc, num_requests_sent, tb->handled_requests->nelts);
CuAssertTrue(tc, tb->result_flags & TEST_RESULT_AUTHNCB_CALLED);
}
static void test_digest_authentication(CuTest *tc)
{
digest_authentication(tc, "");
}
static void test_digest_authentication_keepalive_off(CuTest *tc)
{
/* Add the Connection: close header to the response with the Digest headers.
This to test that the Digest headers will be added to the retry of the
request on the new connection. */
digest_authentication(tc, "Connection: close" CRLF);
}
static apr_status_t
switched_realm_authn_callback(char **username,
char **password,
serf_request_t *request, void *baton,
int code, const char *authn_type,
const char *realm,
apr_pool_t *pool)
{
handler_baton_t *handler_ctx = baton;
test_baton_t *tb = handler_ctx->tb;
const char *exp_realm = tb->user_baton;
tb->result_flags |= TEST_RESULT_AUTHNCB_CALLED;
if (code != 401)
return SERF_ERROR_ISSUE_IN_TESTSUITE;
if (strcmp(exp_realm, realm) != 0)
return SERF_ERROR_ISSUE_IN_TESTSUITE;
if (strcmp(realm, "<http://localhost:12345> Test Suite") == 0) {
*username = "serf";
*password = "serftest";
} else {
*username = "serf_newrealm";
*password = "serftest";
}
return APR_SUCCESS;
}
/* Test template, used for both Basic and Digest switch realms test */
static void authentication_switch_realms(CuTest *tc,
const char *scheme,
const char *authn_attr,
const char *authz_attr_test_suite,
const char *authz_attr_wrong_realm,
const char *authz_attr_new_realm)
{
test_baton_t *tb;
handler_baton_t handler_ctx[2];
int num_requests_sent, num_requests_recvd;
test_server_message_t message_list[5];
test_server_action_t action_list[5];
apr_pool_t *test_pool = tc->testBaton;
apr_status_t status;
message_list[0].text = CHUNKED_REQUEST(1, "1");
message_list[1].text = apr_psprintf(test_pool,
"GET / HTTP/1.1" CRLF
"Host: localhost:12345" CRLF
"Authorization: %s %s" CRLF
"Transfer-Encoding: chunked" CRLF
CRLF
"1" CRLF
"1" CRLF
"0" CRLF CRLF, scheme, authz_attr_test_suite);
message_list[2].text = apr_psprintf(test_pool,
"GET / HTTP/1.1" CRLF
"Host: localhost:12345" CRLF
"Authorization: %s %s" CRLF
"Transfer-Encoding: chunked" CRLF
CRLF
"1" CRLF
"2" CRLF
"0" CRLF CRLF, scheme, authz_attr_test_suite);
/* The client doesn't know that /newrealm/ is in another realm, so it
reuses the credentials cached on the connection. */
message_list[3].text = apr_psprintf(test_pool,
"GET /newrealm/index.html HTTP/1.1" CRLF
"Host: localhost:12345" CRLF
"Authorization: %s %s" CRLF
"Transfer-Encoding: chunked" CRLF
CRLF
"1" CRLF
"3" CRLF
"0" CRLF CRLF, scheme, authz_attr_wrong_realm);
message_list[4].text = apr_psprintf(test_pool,
"GET /newrealm/index.html HTTP/1.1" CRLF
"Host: localhost:12345" CRLF
"Authorization: %s %s" CRLF
"Transfer-Encoding: chunked" CRLF
CRLF
"1" CRLF
"3" CRLF
"0" CRLF CRLF, scheme, authz_attr_new_realm);
action_list[0].kind = SERVER_RESPOND;
action_list[0].text = apr_psprintf(test_pool,
"HTTP/1.1 401 Unauthorized" CRLF
"Transfer-Encoding: chunked" CRLF
"WWW-Authenticate: %s realm=""Test Suite""%s" CRLF
CRLF
"0" CRLF CRLF, scheme, authn_attr);
action_list[1].kind = SERVER_RESPOND;
action_list[1].text = CHUNKED_EMPTY_RESPONSE;
action_list[2].kind = SERVER_RESPOND;
action_list[2].text = CHUNKED_EMPTY_RESPONSE;
action_list[3].kind = SERVER_RESPOND;
action_list[3].text = apr_psprintf(test_pool,
"HTTP/1.1 401 Unauthorized" CRLF
"Transfer-Encoding: chunked" CRLF
"WWW-Authenticate: %s realm=""New Realm""%s" CRLF
CRLF
"0" CRLF CRLF, scheme, authn_attr);
action_list[4].kind = SERVER_RESPOND;
action_list[4].text = CHUNKED_EMPTY_RESPONSE;
/* Set up a test context with a server */
status = test_http_server_setup(&tb,
message_list, 5,
action_list, 5, 0, NULL,
test_pool);
CuAssertIntEquals(tc, APR_SUCCESS, status);
serf_config_authn_types(tb->context, SERF_AUTHN_BASIC | SERF_AUTHN_DIGEST);
serf_config_credentials_callback(tb->context,
switched_realm_authn_callback);
create_new_request(tb, &handler_ctx[0], "GET", "/", 1);
/* Test that a request is retried and authentication headers are set
correctly. */
num_requests_sent = 1;
num_requests_recvd = 2;
tb->user_baton = "<http://localhost:12345> Test Suite";
status = test_helper_run_requests_no_check(tc, tb, num_requests_sent,
handler_ctx, test_pool);
CuAssertIntEquals(tc, APR_SUCCESS, status);
CuAssertIntEquals(tc, num_requests_recvd, tb->sent_requests->nelts);
CuAssertIntEquals(tc, num_requests_recvd, tb->accepted_requests->nelts);
CuAssertIntEquals(tc, num_requests_sent, tb->handled_requests->nelts);
CuAssertTrue(tc, tb->result_flags & TEST_RESULT_AUTHNCB_CALLED);
/* Test that credentials were cached by asserting that the authn callback
wasn't called again. */
tb->result_flags = 0;
create_new_request(tb, &handler_ctx[0], "GET", "/", 2);
status = test_helper_run_requests_no_check(tc, tb, num_requests_sent,
handler_ctx, test_pool);
CuAssertIntEquals(tc, APR_SUCCESS, status);
CuAssertTrue(tc, !(tb->result_flags & TEST_RESULT_AUTHNCB_CALLED));
/* Switch realms. Test that serf asks the application for new
credentials. */
tb->result_flags = 0;
tb->user_baton = "<http://localhost:12345> New Realm";
create_new_request(tb, &handler_ctx[0], "GET", "/newrealm/index.html", 3);
status = test_helper_run_requests_no_check(tc, tb, num_requests_sent,
handler_ctx, test_pool);
CuAssertIntEquals(tc, APR_SUCCESS, status);
CuAssertTrue(tc, tb->result_flags & TEST_RESULT_AUTHNCB_CALLED);
}
static void test_basic_switch_realms(CuTest *tc)
{
authentication_switch_realms(tc, "Basic", "", "c2VyZjpzZXJmdGVzdA==",
"c2VyZjpzZXJmdGVzdA==",
"c2VyZl9uZXdyZWFsbTpzZXJmdGVzdA==");
}
static void test_digest_switch_realms(CuTest *tc)
{
authentication_switch_realms(tc, "Digest", ",nonce=\"ABCDEF1234567890\","
"opaque=\"myopaque\", algorithm=\"MD5\",qop-options=\"auth\"",
/* response hdr attribute for Test Suite realm, uri / */
"realm=\"Test Suite\", username=\"serf\", nonce=\"ABCDEF1234567890\", "
"uri=\"/\", response=\"3511a71fec5c02ab1c9212711a8baa58\", "
"opaque=\"myopaque\", algorithm=\"MD5\"",
/* response hdr attribute for Test Suite realm, uri /newrealm/index.html */
"realm=\"Test Suite\", username=\"serf\", nonce=\"ABCDEF1234567890\", "
"uri=\"/newrealm/index.html\", response=\"c6b673cf44ad16ef379930856b607344\", "
"opaque=\"myopaque\", algorithm=\"MD5\"",
/* response hdr attribute for New Realm realm, uri /newrealm/index.html */
"realm=\"New Realm\", username=\"serf_newrealm\", nonce=\"ABCDEF1234567890\", "
"uri=\"/newrealm/index.html\", response=\"f93f07d1412e53c421f66741a89198cb\", "
"opaque=\"myopaque\", algorithm=\"MD5\"");
}
static void test_auth_on_HEAD(CuTest *tc)
{
test_baton_t *tb;
handler_baton_t handler_ctx[2];
int num_requests_sent, num_requests_recvd;
apr_status_t status;
apr_pool_t *test_pool = tc->testBaton;
test_server_message_t message_list[] = {
{
"HEAD / HTTP/1.1" CRLF
"Host: localhost:12345" CRLF
CRLF
},
{
"HEAD / HTTP/1.1" CRLF
"Host: localhost:12345" CRLF
"Authorization: Basic c2VyZjpzZXJmdGVzdA==" CRLF
CRLF
},
};
test_server_action_t action_list[] = {
{
SERVER_RESPOND,
"HTTP/1.1 401 Unauthorized" CRLF
"WWW-Authenticate: Basic Realm=""Test Suite""" CRLF
CRLF
},
{
SERVER_RESPOND,
"HTTP/1.1 200 Ok" CRLF
"Content-Type: text/html" CRLF
CRLF
},
};
/* Set up a test context with a server */
status = test_http_server_setup(&tb,
message_list, 2,
action_list, 2, 0, NULL,
test_pool);
CuAssertIntEquals(tc, APR_SUCCESS, status);
serf_config_authn_types(tb->context, SERF_AUTHN_BASIC);
serf_config_credentials_callback(tb->context, basic_authn_callback);
create_new_request(tb, &handler_ctx[0], "HEAD", "/", -1);
/* Test that a request is retried and authentication headers are set
correctly. */
num_requests_sent = 1;
num_requests_recvd = 2;
status = test_helper_run_requests_no_check(tc, tb, num_requests_sent,
handler_ctx, test_pool);
CuAssertIntEquals(tc, APR_SUCCESS, status);
CuAssertIntEquals(tc, num_requests_recvd, tb->sent_requests->nelts);
CuAssertIntEquals(tc, num_requests_recvd, tb->accepted_requests->nelts);
CuAssertIntEquals(tc, num_requests_sent, tb->handled_requests->nelts);
CuAssertTrue(tc, tb->result_flags & TEST_RESULT_AUTHNCB_CALLED);
}
/*****************************************************************************/
CuSuite *test_auth(void)
{
CuSuite *suite = CuSuiteNew();
CuSuiteSetSetupTeardownCallbacks(suite, test_setup, test_teardown);
SUITE_ADD_TEST(suite, test_authentication_disabled);
SUITE_ADD_TEST(suite, test_unsupported_authentication);
SUITE_ADD_TEST(suite, test_basic_authentication);
SUITE_ADD_TEST(suite, test_basic_authentication_keepalive_off);
SUITE_ADD_TEST(suite, test_digest_authentication);
SUITE_ADD_TEST(suite, test_digest_authentication_keepalive_off);
SUITE_ADD_TEST(suite, test_basic_switch_realms);
SUITE_ADD_TEST(suite, test_digest_switch_realms);
SUITE_ADD_TEST(suite, test_auth_on_HEAD);
return suite;
}
|