Commit cdc18899 authored by Pekka Pessi's avatar Pekka Pessi

test_nua.c, test_proxy.c: always challenge charlie@example.net.

darcs-hash:20060517095457-65a35-76124fa111b6d7cd5ea960de69bffd9a0d3ee893.gz
parent ec5a83b8
......@@ -1233,6 +1233,9 @@ int test_stack_errors(struct context *ctx)
if (print_headings)
printf("TEST NUA-1.2.2: PASSED\n");
if (!ctx->proxy_tests)
goto nua_1_2_5;
/* -Un-register without REGISTER--------------------------------------- */
if (print_headings)
......@@ -1277,8 +1280,9 @@ int test_stack_errors(struct context *ctx)
/* -terminate without notifier--------------------------------------- */
nua_1_2_5:
if (print_headings)
printf("TEST NUA-1.2.5: unpublish without publish\n");
printf("TEST NUA-1.2.5: terminate without notifier\n");
TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END()));
......@@ -1302,7 +1306,6 @@ int test_stack_errors(struct context *ctx)
free_events_in_list(ctx, a->events);
nua_handle_destroy(a_call->nh), a_call->nh = NULL;
if (print_headings)
......@@ -1882,6 +1885,21 @@ int test_connectivity(struct context *ctx)
TAG_IF(!ctx->proxy_tests, NUTAG_URL(a->contact->m_url)),
TAG_END());
if (ctx->proxy_tests) {
run_abc_until(ctx, -1, NULL, -1, NULL, -1, save_until_final_response);
/* Client events: nua_options(), nua_r_options */
TEST_1(e = c->events->head); TEST_E(e->data->e_event, nua_r_options);
TEST(e->data->e_status, 407);
TEST_1(!e->next);
free_events_in_list(ctx, c->events);
AUTHENTICATE(c, c_call, c_call->nh,
NUTAG_AUTH("Digest:\"test-proxy\":charlie:secret"),
TAG_END());
}
run_abc_until(ctx, -1, save_until_received,
-1, NULL,
-1, save_until_final_response);
......@@ -6004,7 +6022,8 @@ int main(int argc, char *argv[])
retval |= test_stack_errors(ctx); SINGLE_FAILURE_CHECK();
retval |= test_register(ctx);
if (ctx->proxy_tests)
retval |= test_register(ctx);
if (retval == 0)
retval |= test_connectivity(ctx);
......@@ -6030,7 +6049,8 @@ int main(int argc, char *argv[])
retval |= test_events(ctx); SINGLE_FAILURE_CHECK();
}
retval |= test_unregister(ctx); SINGLE_FAILURE_CHECK();
if (ctx->proxy_tests)
retval |= test_unregister(ctx); SINGLE_FAILURE_CHECK();
}
retval |= test_deinit(ctx);
......
......@@ -192,8 +192,8 @@ static int process_options(struct proxy *proxy,
static struct registration_entry *
registration_entry_find(struct proxy const *proxy, url_t const *uri);
static
auth_challenger_t registrar_challenger[1];
static auth_challenger_t registrar_challenger[1];
static auth_challenger_t proxy_challenger[1];
/* Proxy entry point */
static int
......@@ -201,12 +201,21 @@ test_proxy_init(su_root_t *root, struct proxy *proxy)
{
struct proxy_transaction *t;
auth_challenger_t _proxy_challenger[1] =
{{
SIP_407_PROXY_AUTH_REQUIRED,
sip_proxy_authenticate_class,
sip_proxy_authentication_info_class
}};
auth_challenger_t _registrar_challenger[1] =
{{
SIP_401_UNAUTHORIZED,
sip_www_authenticate_class,
sip_authentication_info_class
}};
*proxy_challenger = *_proxy_challenger;
*registrar_challenger = *_registrar_challenger;
proxy->root = root;
......@@ -394,6 +403,8 @@ static sip_contact_t *create_transport_contacts(struct proxy *p)
/* ---------------------------------------------------------------------- */
static int challenge_request(struct proxy *, nta_incoming_t *, sip_t const *);
/** Forward request */
static
int proxy_request(struct proxy *proxy,
......@@ -405,6 +416,25 @@ int proxy_request(struct proxy *proxy,
struct proxy_transaction *t = NULL;
sip_request_t *rq = NULL;
sip_max_forwards_t *mf;
sip_method_t method = sip->sip_request->rq_method;
mf = sip->sip_max_forwards;
if (mf && mf->mf_count <= 1) {
if (sip->sip_request->rq_method == sip_method_options) {
return process_options(proxy, irq, sip);
}
nta_incoming_treply(irq, SIP_483_TOO_MANY_HOPS, TAG_END());
return 483;
}
if (method != sip_method_ack && method != sip_method_cancel &&
str0casecmp(sip->sip_from->a_url->url_host, "example.net") == 0) {
/* Challenge everything but CANCEL and ACK coming from Mr. C */
int status = challenge_request(proxy, irq, sip);
if (status)
return status;
}
/* We don't do any route processing */
request_uri = sip->sip_request->rq_url;
......@@ -440,16 +470,6 @@ int proxy_request(struct proxy *proxy,
target = b->contact->m_url;
}
mf = sip->sip_max_forwards;
if (mf && mf->mf_count <= 1) {
if (sip->sip_request->rq_method == sip_method_options) {
return process_options(proxy, irq, sip);
}
nta_incoming_treply(irq, SIP_483_TOO_MANY_HOPS, TAG_END());
return 483;
}
t = proxy_transaction_new(proxy);
if (t == NULL) {
nta_incoming_treply(irq, SIP_500_INTERNAL_SERVER_ERROR, TAG_END());
......@@ -486,6 +506,50 @@ int proxy_request(struct proxy *proxy,
return 0;
}
static
int challenge_request(struct proxy *p,
nta_incoming_t *irq,
sip_t const *sip)
{
int status;
auth_status_t *as;
msg_t *msg;
as = auth_status_new(p->home);
if (!as)
return 500;
as->as_method = sip->sip_request->rq_method_name;
msg = nta_incoming_getrequest(irq);
as->as_source = msg_addrinfo(msg);
as->as_user_uri = sip->sip_from->a_url;
as->as_display = sip->sip_from->a_display;
if (sip->sip_payload)
as->as_body = sip->sip_payload->pl_data,
as->as_bodylen = sip->sip_payload->pl_len;
auth_mod_check_client(p->auth, as, sip->sip_proxy_authorization,
proxy_challenger);
if ((status = as->as_status)) {
nta_incoming_treply(irq,
as->as_status, as->as_phrase,
SIPTAG_HEADER((void *)as->as_info),
SIPTAG_HEADER((void *)as->as_response),
TAG_END());
}
else if (as->as_match) {
msg_header_remove(msg, NULL, as->as_match);
}
msg_destroy(msg);
su_home_unref(as->as_home);
return status;
}
int proxy_ack_cancel(struct proxy_transaction *t,
nta_incoming_t *irq,
sip_t const *sip)
......@@ -562,8 +626,8 @@ LIST_BODIES(static, proxy_transaction, struct proxy_transaction, next, prev);
/* ---------------------------------------------------------------------- */
static
static
int domain_request(struct proxy *proxy,
nta_leg_t *leg,
nta_incoming_t *irq,
......
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