END_TEST


START_TEST(register_1_3_2_2)
{
  nua_handle_t *nh = nua_handle(nua, NULL, TAG_END());
  struct message *m;

  S2_CASE("1.3.2.2", "Register behind NAT with TCP",
	  "Detect NAT over TCP using rport. "
	  "Authenticate, detect NAT, "
	  "close TCP at server, wait for re-REGISTERs.");

  nua_set_params(nua, NTATAG_TCP_RPORT(1), TAG_END());
  fail_unless_event(nua_r_set_params, 200);

  mark_point();
  s2->registration->nh = nh;
  make_auth_natted_register(
    nh, NUTAG_PROXY(s2sip->tcp.contact->m_url),
    NUTAG_OUTBOUND("no-options-keepalive, no-validate"),
    TAG_END());
  fail_if(!tport_is_tcp(s2->registration->tport));
  tport_shutdown(s2->registration->tport, 2);

  m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
  fail_if(!m); fail_if(!m->sip->sip_authorization);
  s2_save_register(m);

  s2_sip_respond_to(m, NULL,
		SIP_200_OK,
		SIPTAG_CONTACT(s2->registration->contact),
		SIPTAG_VIA(natted_via(m, receive_natted)),
		TAG_END());
  s2_sip_free_message(m);

  /* The "NAT binding" changed when new TCP connection is established */
  /* => NUA re-REGISTERs with newly detected contact */
  fail_unless_event(nua_r_register, 100);

  m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
  fail_if(!m); fail_if(!m->sip->sip_authorization);
  fail_if(!m->sip->sip_contact || !m->sip->sip_contact->m_next);
  s2_save_register(m);

  s2_sip_respond_to(m, NULL,
		SIP_200_OK,
		SIPTAG_CONTACT(s2->registration->contact),
		SIPTAG_VIA(natted_via(m, receive_natted)),
		TAG_END());
  s2_sip_free_message(m);

  fail_unless_event(nua_r_register, 200);

  fail_unless(s2->registration->contact != NULL);
  fail_if(s2->registration->contact->m_next != NULL);

  s2_register_teardown();
}
Example #2
0
END_TEST


START_TEST(register_1_2_2_3)
{
    nua_handle_t *nh = nua_handle(nua, NULL, TAG_END());
    struct message *m;

    S2_CASE("1.2.2.3", "Register behind NAT",
            "Authenticate, outbound activated, "
            "detect NAT binding change when re-REGISTERing");

    mark_point();

    make_auth_natted_register(nh,
                              NUTAG_OUTBOUND("no-options-keepalive, no-validate"),
                              TAG_END());
    s2->registration->nh = nh;

    s2_nua_fast_forward(3600, s2base->root);
    mark_point();

    m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
    fail_if(!m);
    fail_if(!m->sip->sip_authorization);
    s2_save_register(m);

    s2_sip_respond_to(m, NULL,
                      SIP_200_OK,
                      SIPTAG_CONTACT(s2->registration->contact),
                      SIPTAG_VIA(natted_via(m, receive_natted2)),
                      TAG_END());
    s2_sip_free_message(m);

    fail_unless_event(nua_r_register, 100);

    m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
    fail_if(!m);
    fail_if(!m->sip->sip_authorization);
    fail_if(!m->sip->sip_contact || !m->sip->sip_contact->m_next);
    s2_save_register(m);

    s2_sip_respond_to(m, NULL,
                      SIP_200_OK,
                      SIPTAG_CONTACT(s2->registration->contact),
                      SIPTAG_VIA(natted_via(m, receive_natted2)),
                      TAG_END());
    s2_sip_free_message(m);

    fail_unless(s2->registration->contact != NULL);
    fail_if(s2->registration->contact->m_next != NULL);

    fail_unless_event(nua_r_register, 200);

    s2_register_teardown();

}
} END_TEST


START_TEST(register_1_3_2_1)
{
  nua_handle_t *nh = nua_handle(nua, NULL, TAG_END());

  S2_CASE("1.3.2.1", "Register behind NAT",
	  "Authenticate, outbound activated");

  mark_point();
  s2->registration->nh = nh;
  make_auth_natted_register(nh, NUTAG_PROXY(s2sip->tcp.contact->m_url), TAG_END());
  fail_if(!tport_is_tcp(s2->registration->tport));
  s2_register_teardown();
}
END_TEST

START_TEST(register_1_2_2_2)
{
  nua_handle_t *nh = nua_handle(nua, NULL, TAG_END());
  struct message *m;

  S2_CASE("1.2.2.2", "Register behind NAT",
	  "Authenticate, outbound activated, "
	  "authenticate OPTIONS probe, "
	  "NAT binding change");

  mark_point();
  make_auth_natted_register(nh, TAG_END());
  s2->registration->nh = nh;

  mark_point();

  m = s2_sip_wait_for_request(SIP_METHOD_OPTIONS);
  fail_if(!m);
  s2_sip_respond_to(m, NULL,
		SIP_407_PROXY_AUTH_REQUIRED,
		SIPTAG_VIA(natted_via(m, receive_natted)),
		SIPTAG_PROXY_AUTHENTICATE_STR(s2_auth_digest_str),
		TAG_END());
  s2_sip_free_message(m);
  mark_point();

  m = s2_sip_wait_for_request(SIP_METHOD_OPTIONS);
  fail_if(!m); fail_if(!m->sip->sip_proxy_authorization);
  s2_sip_respond_to(m, NULL,
		SIP_200_OK,
		SIPTAG_VIA(natted_via(m, receive_natted)),
		TAG_END());
  s2_sip_free_message(m);

  su_root_step(s2base->root, 20); su_root_step(s2base->root, 20);
  s2_nua_fast_forward(120, s2base->root);	  /* Default keepalive interval */
  mark_point();

  m = s2_sip_wait_for_request(SIP_METHOD_OPTIONS);
  s2_sip_respond_to(m, NULL,
		SIP_200_OK,
		SIPTAG_VIA(natted_via(m, receive_natted)),
		TAG_END());
  s2_sip_free_message(m);

  su_root_step(s2base->root, 20); su_root_step(s2base->root, 20);
  s2_nua_fast_forward(120, s2base->root);	  /* Default keepalive interval */
  mark_point();

  m = s2_sip_wait_for_request(SIP_METHOD_OPTIONS);
  s2_sip_respond_to(m, NULL,
		SIP_200_OK,
		SIPTAG_VIA(natted_via(m, receive_natted2)),
		TAG_END());
  s2_sip_free_message(m);

  fail_unless_event(nua_i_outbound, 0);

  m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
  fail_if(!m); fail_if(!m->sip->sip_authorization);
  fail_if(!m->sip->sip_contact || !m->sip->sip_contact->m_next);
  s2_save_register(m);

  s2_sip_respond_to(m, NULL,
		SIP_200_OK,
		SIPTAG_CONTACT(s2->registration->contact),
		SIPTAG_VIA(natted_via(m, receive_natted2)),
		TAG_END());
  s2_sip_free_message(m);

  fail_unless_event(nua_r_register, 200);

  fail_unless(s2->registration->contact != NULL);
  fail_if(s2->registration->contact->m_next != NULL);

  s2_register_teardown();

} END_TEST
Example #5
0
END_TEST

#include <sys/time.h>

START_TEST(register_1_2_4)
{
    nua_handle_t *nh = nua_handle(nua, NULL, TAG_END());
    struct message *m;
    struct event *e;
    unsigned t1, n;

    S2_CASE("1.2.4", "Register behind NAT",
            "Authenticate, outbound activated, "
            "drop OPTIONS, check that OPTIONS is not retried");

    mark_point();
    make_auth_natted_register(nh,
                              NUTAG_OUTBOUND("validate, no-options-keepalive"),  /* test with a round of unanswered plain keepalives as well? */
                              TAG_END());

    s2->registration->nh = nh;
    mark_point();

    t1 = 500;

    for (t1 = 500, n = 0; n < 20; n++) {
        e = NULL, m = NULL;

        s2_next_thing(&e, &m);

        if (e)
            break;

        fail_if(!m);
        fail_if(!m->sip->sip_request);
        fail_if(m->sip->sip_request->rq_method != sip_method_options);
        s2_sip_free_message(m);

        mark_point();

        s2_nua_fast_forward((t1 + 500) / 1000, s2base->root);
        t1 *= 2;
        if (t1 > 4000)
            t1 = 4000;
    }

    fail_unless(e != NULL);
    fail_unless(e->data->e_event == nua_i_outbound);
    fail_unless(e->data->e_status == 408);
    s2_free_event(e);

    s2_sip_flush_messages();

    s2_nua_fast_forward(3600, s2base->root);

    m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
    fail_if(!m);
    fail_if(!m->sip->sip_authorization);
    fail_if(!m->sip->sip_contact);

    s2_default_registration_duration = 120;
    s2_save_register(m);

    s2_sip_respond_to(m, NULL,
                      SIP_200_OK,
                      SIPTAG_CONTACT(s2->registration->contact),
                      TAG_END());
    s2_sip_free_message(m);

    fail_unless_event(nua_r_register, 200);

    fail_unless(s2->registration->contact != NULL);
    fail_if(s2->registration->contact->m_next != NULL);

    s2_sip_flush_messages();

    while (s2sip->received == NULL) {
        s2_nua_fast_forward(10, s2base->root);
    }

    m = s2_sip_remove_message(s2sip->received);
    fail_if(!m);
    fail_unless(m->sip->sip_request->rq_method == sip_method_register);
    fail_if(!m->sip->sip_authorization);
    fail_if(!m->sip->sip_contact);
    s2_save_register(m);

    s2_sip_respond_to(m, NULL,
                      SIP_200_OK,
                      SIPTAG_CONTACT(s2->registration->contact),
                      TAG_END());
    s2_sip_free_message(m);

    fail_unless_event(nua_r_register, 200);

    s2_register_teardown();

}