Commit 7ce69111 authored by Pekka Pessi's avatar Pekka Pessi

test_nua.c: added test for handling an 406 response to REGISTER

The outbound should restart even after an error response to REGISTER (e.g.,
because the registrar rejected the Contact with an private IP address).

darcs-hash:20070402121110-65a35-3d64672b7c7de9d7f74cf9206d35bccaa975a392.gz
parent 7338c47e
......@@ -210,7 +210,10 @@ int test_stack_errors(struct context *ctx)
run_a_until(ctx, -1, save_until_final_response);
TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_unregister);
TEST(e->data->e_status, 401);
if (e->data->e_status == 401)
TEST(e->data->e_status, 401);
else
TEST(e->data->e_status, 406);
TEST_1(!e->next);
free_events_in_list(ctx, a->events);
......
......@@ -52,6 +52,7 @@ struct binding;
#include <sofia-sip/auth_module.h>
#include <sofia-sip/su_tagarg.h>
#include <sofia-sip/msg_addr.h>
#include <sofia-sip/hostdomain.h>
#include <stdlib.h>
#include <assert.h>
......@@ -708,8 +709,8 @@ static int binding_update(struct proxy *p,
sip_contact_t *binding_contacts(su_home_t *home, struct binding *bindings);
int process_register(struct proxy *proxy,
nta_incoming_t *irq,
sip_t const *sip)
nta_incoming_t *irq,
sip_t const *sip)
{
auth_status_t *as;
msg_t *msg;
......@@ -752,6 +753,13 @@ static int process_register2(struct proxy *p,
sip_t const *sip)
{
struct registration_entry *e = NULL;
sip_contact_t *m = sip->sip_contact;
sip_via_t *v = sip->sip_via;
if (m && v && v->v_received && m->m_url->url_host
&& strcasecmp(v->v_received, m->m_url->url_host)
&& host_is_ip_address(m->m_url->url_host))
return set_status(as, 406, "Unacceptable Contact");
auth_mod_check_client(p->auth, as, sip->sip_authorization,
registrar_challenger);
......
......@@ -141,12 +141,25 @@ int test_register_to_proxy(struct context *ctx)
run_a_until(ctx, -1, save_until_final_response);
TEST_1(e = a->events->head);
TEST_E(e->data->e_event, nua_r_register);
TEST_1(sip = sip_object(e->data->e_msg));
if (ctx->nat) {
TEST_E(e->data->e_event, nua_r_register);
TEST(e->data->e_status, 100);
TEST(sip->sip_status->st_status, 406);
/* Check that CSeq included in tags is actually used in the request */
TEST(sip->sip_cseq->cs_seq, 13);
TEST_1(!sip->sip_contact);
TEST_1(e = e->next);
TEST_1(sip = sip_object(e->data->e_msg));
TEST(sip->sip_cseq->cs_seq, 14);
}
else {
/* Check that CSeq included in tags is actually used in the request */
TEST(sip->sip_cseq->cs_seq, 13);
}
TEST_E(e->data->e_event, nua_r_register);
TEST(e->data->e_status, 401);
TEST(sip->sip_status->st_status, 401);
/* Check that CSeq included in tags is actually used in the request */
TEST(sip->sip_cseq->cs_seq, 13);
TEST_1(!sip->sip_contact);
TEST_1(!e->next);
free_events_in_list(ctx, a->events);
......@@ -166,7 +179,6 @@ int test_register_to_proxy(struct context *ctx)
TEST_S(sip->sip_contact->m_url->url_user, "a");
TEST_1(strstr(sip->sip_contact->m_url->url_params, "foo=bar"));
TEST_S(sip->sip_contact->m_q, "0.9");
TEST(sip->sip_cseq->cs_seq, 14);
if (ctx->nat) {
TEST_1(e = a->specials->head);
......@@ -217,7 +229,6 @@ int test_register_to_proxy(struct context *ctx)
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");
......
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