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(); }
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_1) { nua_handle_t *nh; struct message *m; S2_CASE("1.3.1", "Register over TCP via NAT", "REGISTER via TCP, detect NTA, re-REGISTER"); nh = nua_handle(nua, NULL, TAG_END()); nua_register(nh, NUTAG_PROXY(s2sip->tcp.contact->m_url), TAG_END()); m = s2_sip_wait_for_request(SIP_METHOD_REGISTER); fail_if(!m); fail_if(!m->sip->sip_contact || m->sip->sip_contact->m_next); fail_if(!tport_is_tcp(m->tport)); 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); assert(s2->registration->contact != NULL); fail_unless_event(nua_r_register, 100); m = s2_sip_wait_for_request(SIP_METHOD_REGISTER); fail_if(!m); 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(s2->registration->contact != NULL); fail_if(s2->registration->contact->m_next != NULL); fail_unless( url_has_param(s2->registration->contact->m_url, "transport=tcp")); fail_unless_event(nua_r_register, 200); s2->registration->nh = nh; s2_register_teardown(); }
END_TEST static nua_handle_t *make_auth_natted_register( nua_handle_t *nh, tag_type_t tag, tag_value_t value, ...) { struct message *m; ta_list ta; ta_start(ta, tag, value); nua_register(nh, ta_tags(ta)); ta_end(ta); m = s2_sip_wait_for_request(SIP_METHOD_REGISTER); fail_if(!m); s2_sip_respond_to(m, NULL, SIP_401_UNAUTHORIZED, SIPTAG_WWW_AUTHENTICATE_STR(s2_auth_digest_str), SIPTAG_VIA(natted_via(m, receive_natted)), TAG_END()); s2_sip_free_message(m); fail_unless_event(nua_r_register, 401); /* NAT detected event */ fail_unless_event(nua_i_outbound, 101); nua_authenticate(nh, NUTAG_AUTH(s2_auth_credentials), TAG_END()); m = s2_sip_wait_for_request(SIP_METHOD_REGISTER); fail_if(!m); fail_if(!m->sip->sip_authorization); /* should not unregister the previous contact * as it has not been successfully registered */ fail_if(!m->sip->sip_contact); fail_if(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); assert(s2->registration->contact != NULL); fail_unless_event(nua_r_register, 200); return nh; }
} END_TEST START_TEST(register_1_2_3) { nua_handle_t *nh; struct message *m; S2_CASE("1.2.3", "Register behind NAT", "Outbound activated by error response"); nh = nua_handle(nua, NULL, TAG_END()); nua_register(nh, TAG_END()); mark_point(); m = s2_sip_wait_for_request(SIP_METHOD_REGISTER); fail_if(!m); fail_if(!m->sip->sip_contact || m->sip->sip_contact->m_next); s2_sip_respond_to(m, NULL, 400, "Bad Contact", SIPTAG_VIA(natted_via(m, receive_natted)), 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); 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(s2->registration->contact != NULL); fail_if(s2->registration->contact->m_next != NULL); fail_unless_event(nua_r_register, 200); s2->registration->nh = nh; s2_register_teardown(); } END_TEST
END_TEST START_TEST(subscribe_6_1_5) { nua_handle_t *nh; struct event *notify; sip_via_t *vorig = s2_sip_tport_via(s2sip->udp.tport); sip_via_t via[2]; char *v0_params[8] = {}, *v1_params[8] = {}; char branch0[32], branch1[32]; S2_CASE("6.1.5", "Via handling in response to NOTIFY", "NUA sends SUBSCRIBE, waits for NOTIFY, sends un-SUBSCRIBE"); nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END()); nua_subscribe(nh, SIPTAG_EVENT_STR(event_type), TAG_END()); s2_sip_msg_flags = MSG_FLG_COMMA_LISTS|MSG_FLG_COMPACT; fail_if(vorig == NULL); via[0] = *vorig; via[0].v_host = "example.org"; via[0].v_params = (void *)v0_params; snprintf(v0_params[0] = branch0, sizeof branch0, "branch=z9hG4bK%lx", ++s2sip->tid); fail_if(vorig == NULL); via[1] = *vorig; via[1].v_params = (void *)v1_params; snprintf(v1_params[0] = branch1, sizeof branch1, "branch=z9hG4bK%lx", ++s2sip->tid); notify = subscription_by_nua(nh, nua_substate_embryonic, SIPTAG_VIA(via + 1), SIPTAG_VIA(via + 0), TAG_END()); s2_sip_msg_flags = 0; s2_free_event(notify); unsubscribe_by_nua(nh, TAG_END()); nua_handle_destroy(nh); }
END_TEST #endif START_TEST(register_1_3_3_2) { nua_handle_t *nh = nua_handle(nua, NULL, TAG_END()); struct message *m; tport_t *tcp; int i; S2_CASE("1.3.3.2", "Register behind NAT with TCP", "Register w/ TCP using rport, pingpong. "); nua_set_params(nua, NTATAG_TCP_RPORT(1), TAG_END()); fail_unless_event(nua_r_set_params, 200); mark_point(); s2->registration->nh = nh; nua_register(nh, NUTAG_PROXY(s2sip->tcp.contact->m_url), NUTAG_OUTBOUND("no-options-keepalive, no-validate"), TAG_END()); m = s2_sip_wait_for_request(SIP_METHOD_REGISTER); fail_if(!m); fail_unless(tport_is_tcp(m->tport)); tcp = tport_ref(m->tport); /* Respond to request over TCP */ s2_sip_respond_to(m, NULL, SIP_401_UNAUTHORIZED, SIPTAG_WWW_AUTHENTICATE_STR(s2_auth_digest_str), SIPTAG_VIA(natted_via(m, receive_natted)), TAG_END()); s2_sip_free_message(m); fail_unless_event(nua_r_register, 401); nua_authenticate(nh, NUTAG_AUTH(s2_auth_credentials), TAG_END()); 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_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); /* Turn off pong */ tport_set_params(tcp, TPTAG_PONG2PING(0), TAG_END()); /* Wait until ping-pong failure closes the TCP connection */ for (i = 0; i < 100; i++) { s2_nua_fast_forward(5, s2base->root); if (tport_is_closed(tcp)) break; } m = s2_sip_wait_for_request(SIP_METHOD_REGISTER); fail_unless(tport_is_tcp(m->tport)); fail_unless(tcp != m->tport); fail_if(!m); 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), SIPTAG_VIA(natted_via(m, receive_natted)), TAG_END()); s2_sip_free_message(m); tport_unref(tcp); /* Contact changed */ 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); fail_if(!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); s2_register_teardown(); }
END_TEST #if nomore START_TEST(register_1_3_3_1) { nua_handle_t *nh = nua_handle(nua, NULL, TAG_END()); struct message *m; tport_t *tcp; S2_CASE("1.3.3.1", "Register behind NAT with UDP and TCP", "Register with UDP, UDP time-outing, then w/ TCP using rport. "); nua_set_params(nua, NTATAG_TCP_RPORT(1), TAG_END()); fail_unless_event(nua_r_set_params, 200); mark_point(); s2->registration->nh = nh; nua_register(nh, NUTAG_OUTBOUND("no-options-keepalive, no-validate"), TAG_END()); /* NTA tries with UDP, we drop them */ for (;;) { m = s2_sip_wait_for_request(SIP_METHOD_REGISTER); fail_if(!m); if (!tport_is_udp(m->tport)) /* Drop UDP */ break; s2_sip_free_message(m); s2_nua_fast_forward(4, s2base->root); } tcp = tport_ref(m->tport); /* Respond to request over TCP */ s2_sip_respond_to(m, NULL, SIP_401_UNAUTHORIZED, SIPTAG_WWW_AUTHENTICATE_STR(s2_auth_digest_str), SIPTAG_VIA(natted_via(m, receive_natted)), TAG_END()); s2_sip_free_message(m); fail_unless_event(nua_r_register, 401); nua_authenticate(nh, NUTAG_AUTH(s2_auth_credentials), TAG_END()); /* Turn off pong */ tport_set_params(tcp, TPTAG_PONG2PING(0), TAG_END()); /* Now request over UDP ... registering TCP contact! */ m = s2_sip_wait_for_request(SIP_METHOD_REGISTER); fail_if(!m); fail_if(!m->sip->sip_authorization); s2_save_register(m); fail_unless( url_has_param(s2->registration->contact->m_url, "transport=tcp")); 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); /* NUA detects oops... re-registers UDP */ 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); /* Wait until ping-pong failure closes the TCP connection */ { int i; for (i = 0; i < 5; i++) { su_root_step(s2base->root, 5); su_root_step(s2base->root, 5); su_root_step(s2base->root, 5); s2_nua_fast_forward(5, s2base->root); } } 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