tester: do not try TLS tests when library is not available

parent 5e35f0cd
...@@ -31,6 +31,8 @@ BELLESIP_EXPORT int belle_http_provider_send_request(belle_http_provider_t *obj, ...@@ -31,6 +31,8 @@ BELLESIP_EXPORT int belle_http_provider_send_request(belle_http_provider_t *obj,
BELLESIP_EXPORT void belle_http_provider_cancel_request(belle_http_provider_t *obj, belle_http_request_t *req); BELLESIP_EXPORT void belle_http_provider_cancel_request(belle_http_provider_t *obj, belle_http_request_t *req);
BELLESIP_EXPORT belle_sip_list_t** belle_http_provider_get_channels(belle_http_provider_t *obj, const char *transport_name);
BELLE_SIP_END_DECLS BELLE_SIP_END_DECLS
#endif #endif
...@@ -357,7 +357,7 @@ static void fix_request(belle_http_request_t *req){ ...@@ -357,7 +357,7 @@ static void fix_request(belle_http_request_t *req){
} }
} }
static belle_sip_list_t **provider_get_channels(belle_http_provider_t *obj, const char *transport_name){ belle_sip_list_t **belle_http_provider_get_channels(belle_http_provider_t *obj, const char *transport_name){
if (strcasecmp(transport_name,"tcp")==0) return &obj->tcp_channels; if (strcasecmp(transport_name,"tcp")==0) return &obj->tcp_channels;
else if (strcasecmp(transport_name,"tls")==0) return &obj->tls_channels; else if (strcasecmp(transport_name,"tls")==0) return &obj->tls_channels;
else{ else{
...@@ -367,7 +367,7 @@ static belle_sip_list_t **provider_get_channels(belle_http_provider_t *obj, cons ...@@ -367,7 +367,7 @@ static belle_sip_list_t **provider_get_channels(belle_http_provider_t *obj, cons
} }
static void provider_remove_channel(belle_http_provider_t *obj, belle_sip_channel_t *chan){ static void provider_remove_channel(belle_http_provider_t *obj, belle_sip_channel_t *chan){
belle_sip_list_t **channels=provider_get_channels(obj,belle_sip_channel_get_transport_name(chan)); belle_sip_list_t **channels=belle_http_provider_get_channels(obj,belle_sip_channel_get_transport_name(chan));
*channels=belle_sip_list_remove(*channels,chan); *channels=belle_sip_list_remove(*channels,chan);
belle_sip_message("channel [%p] removed from http provider.",obj); belle_sip_message("channel [%p] removed from http provider.",obj);
belle_sip_object_unref(chan); belle_sip_object_unref(chan);
...@@ -385,7 +385,7 @@ static void belle_http_end_background_task(void* data) { ...@@ -385,7 +385,7 @@ static void belle_http_end_background_task(void* data) {
int belle_http_provider_send_request(belle_http_provider_t *obj, belle_http_request_t *req, belle_http_request_listener_t *listener){ int belle_http_provider_send_request(belle_http_provider_t *obj, belle_http_request_t *req, belle_http_request_listener_t *listener){
belle_sip_channel_t *chan; belle_sip_channel_t *chan;
belle_sip_hop_t *hop=belle_sip_hop_new_from_generic_uri(req->orig_uri ? req->orig_uri : req->req_uri); belle_sip_hop_t *hop=belle_sip_hop_new_from_generic_uri(req->orig_uri ? req->orig_uri : req->req_uri);
belle_sip_list_t **channels=provider_get_channels(obj,hop->transport); belle_sip_list_t **channels=belle_http_provider_get_channels(obj,hop->transport);
if (listener) belle_http_request_set_listener(req,listener); if (listener) belle_http_request_set_listener(req,listener);
......
...@@ -93,73 +93,91 @@ static int http_cleanup(void){ ...@@ -93,73 +93,91 @@ static int http_cleanup(void){
return 0; return 0;
} }
static void one_get(const char *url,http_counters_t* counters, int *counter){ static int url_supported(const char *url) {
belle_http_request_listener_callbacks_t cbs={0}; if (url && strstr(url,"https://")==url && (belle_sip_list_size(*belle_http_provider_get_channels(prov,"tls"))==0)){
belle_http_request_listener_t *l; belle_sip_error("No TLS support, test skipped.");
belle_generic_uri_t *uri; return -1;
belle_http_request_t *req; }
return 0;
uri=belle_generic_uri_parse(url); }
static int one_get(const char *url,http_counters_t* counters, int *counter){
req=belle_http_request_create("GET", if (url_supported(url)==-1) {
uri, return -1;
belle_sip_header_create("User-Agent","belle-sip/"PACKAGE_VERSION), } else {
NULL); belle_http_request_listener_callbacks_t cbs={0};
cbs.process_response=process_response; belle_http_request_listener_t *l;
cbs.process_io_error=process_io_error; belle_generic_uri_t *uri;
cbs.process_auth_requested=process_auth_requested; belle_http_request_t *req;
l=belle_http_request_listener_create_from_callbacks(&cbs,counters);
belle_http_provider_send_request(prov,req,l); uri=belle_generic_uri_parse(url);
wait_for(stack,counter,1,10000);
req=belle_http_request_create("GET",
belle_sip_object_unref(l); uri,
belle_sip_header_create("User-Agent","belle-sip/"PACKAGE_VERSION),
NULL);
cbs.process_response=process_response;
cbs.process_io_error=process_io_error;
cbs.process_auth_requested=process_auth_requested;
l=belle_http_request_listener_create_from_callbacks(&cbs,counters);
belle_http_provider_send_request(prov,req,l);
wait_for(stack,counter,1,10000);
belle_sip_object_unref(l);
return 0;
}
} }
static void one_http_get(void){ static void one_http_get(void){
http_counters_t counters={0}; http_counters_t counters={0};
one_get("http://smtp.linphone.org",&counters,&counters.response_count); if (one_get("http://smtp.linphone.org",&counters,&counters.response_count) == 0) {
BC_ASSERT_TRUE(counters.response_count==1); BC_ASSERT_TRUE(counters.response_count==1);
BC_ASSERT_TRUE(counters.io_error_count==0); BC_ASSERT_TRUE(counters.io_error_count==0);
BC_ASSERT_EQUAL(counters.two_hundred,1,int,"%d"); BC_ASSERT_EQUAL(counters.two_hundred,1,int,"%d");
}
} }
static void http_get_empty_body(void){ static void http_get_empty_body(void){
http_counters_t counters={0}; http_counters_t counters={0};
one_get("http://smtp.linphone.org/marie_invalid",&counters,&counters.response_count); if (one_get("http://smtp.linphone.org/marie_invalid",&counters,&counters.response_count) == 0) {
BC_ASSERT_TRUE(counters.response_count==1); BC_ASSERT_TRUE(counters.response_count==1);
BC_ASSERT_TRUE(counters.io_error_count==0); BC_ASSERT_TRUE(counters.io_error_count==0);
BC_ASSERT_EQUAL(counters.two_hundred,1,int,"%d"); BC_ASSERT_EQUAL(counters.two_hundred,1,int,"%d");
}
} }
static void http_get_io_error(void){ static void http_get_io_error(void){
http_counters_t counters={0}; http_counters_t counters={0};
one_get("http://blablabla.cul",&counters,&counters.io_error_count); if (one_get("http://blablabla.fail",&counters,&counters.io_error_count) == 0) {
BC_ASSERT_TRUE(counters.response_count==0); BC_ASSERT_EQUAL(counters.response_count,0,int,"%d");
BC_ASSERT_EQUAL(counters.io_error_count,1,int,"%d"); BC_ASSERT_EQUAL(counters.io_error_count,1,int,"%d");
} }
}
static void one_https_get(void){ static void one_https_get(void){
http_counters_t counters={0}; http_counters_t counters={0};
one_get("https://smtp.linphone.org",&counters,&counters.response_count); if (one_get("https://smtp.linphone.org",&counters,&counters.response_count) == 0) {
BC_ASSERT_TRUE(counters.response_count==1); BC_ASSERT_EQUAL(counters.response_count, 1, int, "%d");
BC_ASSERT_TRUE(counters.io_error_count==0); BC_ASSERT_EQUAL(counters.io_error_count, 0, int, "%d");
BC_ASSERT_EQUAL(counters.two_hundred,1,int,"%d"); BC_ASSERT_EQUAL(counters.two_hundred,1,int,"%d");
}
} }
static void https_get_long_body(void){ static void https_get_long_body(void){
http_counters_t counters={0}; http_counters_t counters={0};
one_get("https://smtp.linphone.org/linphone.html",&counters, &counters.response_count); if (one_get("https://smtp.linphone.org/linphone.html",&counters, &counters.response_count) == 0) {
BC_ASSERT_TRUE(counters.response_count==1); BC_ASSERT_EQUAL(counters.response_count, 1, int, "%d");
BC_ASSERT_TRUE(counters.io_error_count==0); BC_ASSERT_EQUAL(counters.io_error_count, 0, int, "%d");
BC_ASSERT_EQUAL(counters.two_hundred,1,int,"%d"); BC_ASSERT_EQUAL(counters.two_hundred,1,int,"%d");
}
} }
static void https_digest_get(void){ static void https_digest_get(void){
http_counters_t counters={0}; http_counters_t counters={0};
one_get("https://pauline:pouet@smtp.linphone.org/restricted",&counters,&counters.response_count); if (one_get("https://pauline:pouet@smtp.linphone.org/restricted",&counters,&counters.response_count) == 0) {
BC_ASSERT_TRUE(counters.response_count==1); BC_ASSERT_EQUAL(counters.response_count, 1, int, "%d");
BC_ASSERT_TRUE(counters.io_error_count==0); BC_ASSERT_EQUAL(counters.io_error_count, 0, int, "%d");
BC_ASSERT_EQUAL(counters.three_hundred,1,int,"%d"); BC_ASSERT_EQUAL(counters.three_hundred,1,int,"%d");
}
} }
#if 0 #if 0
static void https_client_cert_connection(void){ static void https_client_cert_connection(void){
...@@ -167,8 +185,9 @@ static void https_client_cert_connection(void){ ...@@ -167,8 +185,9 @@ static void https_client_cert_connection(void){
http_counters_t counters={0}; http_counters_t counters={0};
belle_tls_verify_policy_set_exceptions(policy,BELLE_TLS_VERIFY_ANY_REASON);/*ignore the server verification because we don't have a true certificate*/ belle_tls_verify_policy_set_exceptions(policy,BELLE_TLS_VERIFY_ANY_REASON);/*ignore the server verification because we don't have a true certificate*/
belle_http_provider_set_tls_verify_policy(prov,policy); belle_http_provider_set_tls_verify_policy(prov,policy);
one_get("https://sip2.linphone.org:5063",&counters); if (one_get("https://sip2.linphone.org:5063",&counters) == 0) {
BC_ASSERT_EQUAL(counters.two_hundred,1,int,"%d"); BC_ASSERT_EQUAL(counters.two_hundred,1,int,"%d");
}
belle_tls_verify_policy_set_exceptions(policy,0); belle_tls_verify_policy_set_exceptions(policy,0);
belle_sip_object_unref(policy); belle_sip_object_unref(policy);
} }
...@@ -218,9 +237,14 @@ static void https_post_long_body(void){ ...@@ -218,9 +237,14 @@ static void https_post_long_body(void){
belle_generic_uri_t *uri; belle_generic_uri_t *uri;
belle_http_request_t *req; belle_http_request_t *req;
http_counters_t counters={0}; http_counters_t counters={0};
belle_sip_user_body_handler_t *bh;
char *content_type;
const char *url="https://www.linphone.org:444/upload.php"; const char *url="https://www.linphone.org:444/upload.php";
belle_sip_user_body_handler_t *bh=belle_sip_user_body_handler_new(image_size+sizeof(MULTIPART_BEGIN)+sizeof(MULTIPART_END), on_progress, NULL, on_send_body, NULL); if (url_supported(url)==-1) {
char *content_type=belle_sip_strdup_printf("multipart/form-data; boundary=%s",multipart_boudary); return;
}
bh=belle_sip_user_body_handler_new(image_size+sizeof(MULTIPART_BEGIN)+sizeof(MULTIPART_END), on_progress, NULL, on_send_body, NULL);
content_type=belle_sip_strdup_printf("multipart/form-data; boundary=%s",multipart_boudary);
uri=belle_generic_uri_parse(url); uri=belle_generic_uri_parse(url);
......
...@@ -524,9 +524,13 @@ static void test_connection_too_long(const char *transport){ ...@@ -524,9 +524,13 @@ static void test_connection_too_long(const char *transport){
int orig=belle_sip_stack_get_transport_timeout(stack); int orig=belle_sip_stack_get_transport_timeout(stack);
char *no_response_here_with_transport = belle_sip_strdup_printf(no_response_here, transport); char *no_response_here_with_transport = belle_sip_strdup_printf(no_response_here, transport);
io_error_count=0; io_error_count=0;
if (transport && strcasecmp("tls",transport)==0 && belle_sip_provider_get_listening_point(prov,"tls")==NULL){
belle_sip_error("No TLS support, test skipped.");
return;
}
belle_sip_stack_set_transport_timeout(stack,2000); belle_sip_stack_set_transport_timeout(stack,2000);
req=try_register_user_at_domain(stack, prov, transport,1,"tester","sip.linphone.org",no_response_here_with_transport,0); req=try_register_user_at_domain(stack, prov, transport,1,"tester","sip.linphone.org",no_response_here_with_transport,0);
BC_ASSERT_TRUE(io_error_count>=1); BC_ASSERT_GREATER(io_error_count, 1, int, "%d");
belle_sip_stack_set_transport_timeout(stack,orig); belle_sip_stack_set_transport_timeout(stack,orig);
belle_sip_free(no_response_here_with_transport); belle_sip_free(no_response_here_with_transport);
if (req) belle_sip_object_unref(req); if (req) belle_sip_object_unref(req);
......
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