Commit c0a9e10b authored by Pekka Pessi's avatar Pekka Pessi

test_nua: added test for bad username/password (bug #1685245)

Also testing NUTAG_AUTH_CACHE(nua_auth_cache_challenged) - sending
credentials only when challenged.

darcs-hash:20070326161147-55b16-41108163452698ba1cc8f71b7bd85bc4bb33e7d4.gz
parent d7c39e88
......@@ -404,17 +404,21 @@ int test_prack_auth(struct context *ctx)
TEST_1(is_answer_recv(e->data->e_tags));
TEST_1(!is_offer_sent(e->data->e_tags));
if (md5 && !md5sess) {
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_prack);
TEST(e->data->e_status, 407);
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_prack);
if (e->data->e_status != 200 && md5 && !md5sess) {
if (e->data->e_status != 100) {
TEST(e->data->e_status, 407);
}
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_proceeding);
TEST_1(!is_answer_recv(e->data->e_tags));
TEST_1(!is_offer_sent(e->data->e_tags));
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_prack);
}
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_prack);
TEST(e->data->e_status, 200);
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_invite);
......
......@@ -724,7 +724,7 @@ int test_reject_401_aka(struct context *ctx)
sip_t const *sip;
if (print_headings)
printf("TEST NUA-4.6: invalid challenge \n");
printf("TEST NUA-4.6.1: invalid challenge \n");
a_call->sdp = "m=audio 5008 RTP/AVP 8";
b_call->sdp = "m=audio 5010 RTP/AVP 0 8";
......@@ -773,7 +773,160 @@ int test_reject_401_aka(struct context *ctx)
nua_handle_destroy(b_call->nh), b_call->nh = NULL;
if (print_headings)
printf("TEST NUA-4.6: PASSED\n");
printf("TEST NUA-4.6.1: PASSED\n");
END();
}
/* ------------------------------------------------------------------------ */
/* Reject call with 401, twice */
/*
A reject-401-bad B
| |
|-------INVITE------>|
|<----100 Trying-----|
|<--------401--------|
|---------ACK------->|
| |
|-------INVITE------>|
|<----100 Trying-----|
|<--------401--------|
|---------ACK------->|
*/
int reject_401_bad(CONDITION_PARAMS)
{
if (!(check_handle(ep, call, nh, SIP_500_INTERNAL_SERVER_ERROR)))
return 0;
save_event_in_list(ctx, event, ep, call);
switch (callstate(tags)) {
case nua_callstate_received:
RESPOND(ep, call, nh, SIP_401_UNAUTHORIZED,
/* Send a challenge that we do not grok */
SIPTAG_WWW_AUTHENTICATE_STR("Digest realm=\"No hope\", "
"nonce=\"goO541ftNrw327aWpu2\", "
"algorithm=MD5, "
"qop=\"auth\""),
TAG_END());
return 0;
case nua_callstate_terminated:
if (call)
nua_handle_destroy(call->nh), call->nh = NULL;
if (ep->flags.bit0) /* Terminate 2 calls */
return 1;
ep->flags.bit0 = 1;
return 0;
default:
return 0;
}
}
int authenticate_once(CONDITION_PARAMS)
{
if (!(check_handle(ep, call, nh, SIP_500_INTERNAL_SERVER_ERROR)))
return 0;
save_event_in_list(ctx, event, ep, call);
if (event == nua_r_invite && status == 401) {
if (ep->flags.bit0) {
nua_handle_destroy(nh); if (call) call->nh = NULL;
return 1;
}
ep->flags.bit0 = 1;
AUTHENTICATE(ep, call, nh, NUTAG_AUTH("Digest:\"No hope\":jaska:secret"),
SIPTAG_SUBJECT_STR("Got 401"),
TAG_END());
return 0;
}
switch (callstate(tags)) {
case nua_callstate_terminated:
if (call)
nua_handle_destroy(call->nh), call->nh = NULL;
return 1;
default:
return 0;
}
}
int test_reject_401_bad(struct context *ctx)
{
BEGIN();
struct endpoint *a = &ctx->a, *b = &ctx->b;
struct call *a_call = a->call, *b_call = b->call;
struct event const *e;
sip_t const *sip;
if (print_headings)
printf("TEST NUA-4.6.2: bad username/password\n");
a_call->sdp = "m=audio 5008 RTP/AVP 8";
TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END()));
INVITE(a, a_call, a_call->nh,
TAG_IF(!ctx->proxy_tests, NUTAG_URL(b->contact->m_url)),
SIPTAG_SUBJECT_STR("reject-401-bad"),
SOATAG_USER_SDP_STR(a_call->sdp),
TAG_END());
run_ab_until(ctx, -1, authenticate_once, -1, reject_401_bad);
/*
Client transitions
INIT -(C1)-> CALLING -(C6a)-> TERMINATED/INIT
*/
TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_calling); /* CALLING */
TEST_1(is_offer_sent(e->data->e_tags));
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_invite);
TEST(sip_object(e->data->e_msg)->sip_status->st_status, 401);
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_calling); /* CALLING */
TEST_1(is_offer_sent(e->data->e_tags));
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_invite);
TEST(sip_object(e->data->e_msg)->sip_status->st_status, 401);
TEST_1(!e->next);
free_events_in_list(ctx, a->events);
/*
Server transitions:
INIT -(S1)-> RECEIVED -(S6a)-> TERMINATED
*/
TEST_1(e = b->events->head); TEST_E(e->data->e_event, nua_i_invite);
TEST_1(sip = sip_object(e->data->e_msg));
TEST(e->data->e_status, 100);
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_received); /* RECEIVED */
TEST_1(is_offer_recv(e->data->e_tags));
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_terminated); /* TERMINATED */
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_invite);
TEST_1(sip = sip_object(e->data->e_msg));
TEST(e->data->e_status, 100);
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_received); /* RECEIVED */
TEST_1(is_offer_recv(e->data->e_tags));
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_terminated); /* TERMINATED */
TEST_1(!e->next);
free_events_in_list(ctx, b->events);
nua_handle_destroy(a_call->nh), a_call->nh = NULL;
nua_handle_destroy(b_call->nh), b_call->nh = NULL;
if (print_headings)
printf("TEST NUA-4.6.2: PASSED\n");
END();
}
......@@ -1262,3 +1415,19 @@ int call_with_bad_ack(CONDITION_PARAMS)
return event == nua_i_state && callstate(tags) == nua_callstate_terminated;
}
/* ---------------------------------------------------------------------- */
int test_rejects(struct context *ctx)
{
return
test_reject_401_bad(ctx) ||
test_reject_a(ctx) ||
test_reject_b(ctx) ||
test_reject_302(ctx) ||
test_reject_401(ctx) ||
test_mime_negotiation(ctx) ||
test_call_timeouts(ctx) ||
test_reject_401_aka(ctx) ||
0;
}
......@@ -110,7 +110,8 @@ int test_nua_init(struct context *ctx,
AUTHTAG_OPAQUE("kuik"),
AUTHTAG_DB(passwd_name),
AUTHTAG_QOP("auth-int"),
AUTHTAG_ALGORITHM("md5-sess"),
AUTHTAG_ALGORITHM("md5"),
AUTHTAG_NEXT_EXPIRES(60),
TAG_IF(ctx->proxy_logging, TPTAG_LOG(1)),
TAG_END());
......
......@@ -307,13 +307,7 @@ int main(int argc, char *argv[])
while (retval == 0) {
retval |= test_basic_call(ctx); SINGLE_FAILURE_CHECK();
retval |= test_reject_a(ctx); SINGLE_FAILURE_CHECK();
retval |= test_reject_b(ctx); SINGLE_FAILURE_CHECK();
retval |= test_reject_302(ctx); SINGLE_FAILURE_CHECK();
retval |= test_reject_401(ctx); SINGLE_FAILURE_CHECK();
retval |= test_mime_negotiation(ctx); SINGLE_FAILURE_CHECK();
retval |= test_call_timeouts(ctx); SINGLE_FAILURE_CHECK();
retval |= test_reject_401_aka(ctx); SINGLE_FAILURE_CHECK();
retval |= test_rejects(ctx); SINGLE_FAILURE_CHECK();
retval |= test_call_cancel(ctx); SINGLE_FAILURE_CHECK();
retval |= test_call_destroy(ctx); SINGLE_FAILURE_CHECK();
retval |= test_offer_answer(ctx); SINGLE_FAILURE_CHECK();
......
......@@ -330,10 +330,7 @@ int test_unregister(struct context *ctx);
int test_basic_call(struct context *ctx);
int test_offer_answer(struct context *ctx);
int test_reject_a(struct context *ctx);
int test_reject_b(struct context *ctx);
int test_reject_302(struct context *ctx);
int test_reject_401(struct context *ctx);
int test_rejects(struct context *ctx);
int test_mime_negotiation(struct context *ctx);
int test_call_timeouts(struct context *ctx);
int test_reject_401_aka(struct context *ctx);
......
......@@ -55,6 +55,7 @@ int test_register_to_proxy(struct context *ctx)
struct event *e;
sip_t const *sip;
sip_cseq_t cseq[1];
int seen_401;
if (ctx->p)
test_proxy_set_expiration(ctx->p, 5, 5, 10);
......@@ -189,6 +190,8 @@ int test_register_to_proxy(struct context *ctx)
REGISTER(b, b_reg, b_reg->nh, SIPTAG_TO(b->to),
SIPTAG_CONTACT(m),
/* Do not include credentials unless challenged */
NUTAG_AUTH_CACHE(nua_auth_cache_challenged),
TAG_END());
}
run_ab_until(ctx, -1, save_events, -1, save_until_final_response);
......@@ -213,7 +216,8 @@ int test_register_to_proxy(struct context *ctx)
TEST_1(sip->sip_contact);
TEST_S(sip->sip_contact->m_display, "B");
TEST_S(sip->sip_contact->m_url->url_user, "b");
free_events_in_list(ctx, b->events);
if (print_headings)
printf("TEST NUA-2.3.2: PASSED\n");
......@@ -318,11 +322,21 @@ int test_register_to_proxy(struct context *ctx)
TEST_1(!e->next);
free_events_in_list(ctx, a->events);
seen_401 = 0;
for (e = b->events->head; e; e = e->next) {
TEST_E(e->data->e_event, nua_r_register);
TEST(e->data->e_status, 200);
TEST_1(sip = sip_object(e->data->e_msg));
TEST_1(sip->sip_contact);
if (e->data->e_status == 200) {
TEST(e->data->e_status, 200);
TEST_1(seen_401);
TEST_1(sip->sip_contact);
}
else if (sip->sip_status && sip->sip_status->st_status == 401) {
seen_401 = 1;
}
if (!e->next)
break;
}
......@@ -680,6 +694,10 @@ int test_unregister(struct context *ctx)
run_b_until(ctx, -1, save_until_final_response);
TEST_1(e = b->events->head);
TEST_E(e->data->e_event, nua_r_unregister);
if (e->data->e_status == 100) {
TEST_1(e = e->next);
TEST_E(e->data->e_event, nua_r_unregister);
}
TEST(e->data->e_status, 200);
TEST_1(sip = sip_object(e->data->e_msg));
TEST_1(!sip->sip_contact);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment