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,
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
#endif
......@@ -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;
else if (strcasecmp(transport_name,"tls")==0) return &obj->tls_channels;
else{
......@@ -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){
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);
belle_sip_message("channel [%p] removed from http provider.",obj);
belle_sip_object_unref(chan);
......@@ -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){
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_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);
......
......@@ -93,73 +93,91 @@ static int http_cleanup(void){
return 0;
}
static void one_get(const char *url,http_counters_t* counters, int *counter){
belle_http_request_listener_callbacks_t cbs={0};
belle_http_request_listener_t *l;
belle_generic_uri_t *uri;
belle_http_request_t *req;
uri=belle_generic_uri_parse(url);
req=belle_http_request_create("GET",
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);
static int url_supported(const char *url) {
if (url && strstr(url,"https://")==url && (belle_sip_list_size(*belle_http_provider_get_channels(prov,"tls"))==0)){
belle_sip_error("No TLS support, test skipped.");
return -1;
}
return 0;
}
static int one_get(const char *url,http_counters_t* counters, int *counter){
if (url_supported(url)==-1) {
return -1;
} else {
belle_http_request_listener_callbacks_t cbs={0};
belle_http_request_listener_t *l;
belle_generic_uri_t *uri;
belle_http_request_t *req;
uri=belle_generic_uri_parse(url);
req=belle_http_request_create("GET",
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){
http_counters_t counters={0};
one_get("http://smtp.linphone.org",&counters,&counters.response_count);
BC_ASSERT_TRUE(counters.response_count==1);
BC_ASSERT_TRUE(counters.io_error_count==0);
BC_ASSERT_EQUAL(counters.two_hundred,1,int,"%d");
if (one_get("http://smtp.linphone.org",&counters,&counters.response_count) == 0) {
BC_ASSERT_TRUE(counters.response_count==1);
BC_ASSERT_TRUE(counters.io_error_count==0);
BC_ASSERT_EQUAL(counters.two_hundred,1,int,"%d");
}
}
static void http_get_empty_body(void){
http_counters_t counters={0};
one_get("http://smtp.linphone.org/marie_invalid",&counters,&counters.response_count);
BC_ASSERT_TRUE(counters.response_count==1);
BC_ASSERT_TRUE(counters.io_error_count==0);
BC_ASSERT_EQUAL(counters.two_hundred,1,int,"%d");
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.io_error_count==0);
BC_ASSERT_EQUAL(counters.two_hundred,1,int,"%d");
}
}
static void http_get_io_error(void){
http_counters_t counters={0};
one_get("http://blablabla.cul",&counters,&counters.io_error_count);
BC_ASSERT_TRUE(counters.response_count==0);
BC_ASSERT_EQUAL(counters.io_error_count,1,int,"%d");
}
if (one_get("http://blablabla.fail",&counters,&counters.io_error_count) == 0) {
BC_ASSERT_EQUAL(counters.response_count,0,int,"%d");
BC_ASSERT_EQUAL(counters.io_error_count,1,int,"%d");
}
}
static void one_https_get(void){
http_counters_t counters={0};
one_get("https://smtp.linphone.org",&counters,&counters.response_count);
BC_ASSERT_TRUE(counters.response_count==1);
BC_ASSERT_TRUE(counters.io_error_count==0);
BC_ASSERT_EQUAL(counters.two_hundred,1,int,"%d");
if (one_get("https://smtp.linphone.org",&counters,&counters.response_count) == 0) {
BC_ASSERT_EQUAL(counters.response_count, 1, int, "%d");
BC_ASSERT_EQUAL(counters.io_error_count, 0, int, "%d");
BC_ASSERT_EQUAL(counters.two_hundred,1,int,"%d");
}
}
static void https_get_long_body(void){
http_counters_t counters={0};
one_get("https://smtp.linphone.org/linphone.html",&counters, &counters.response_count);
BC_ASSERT_TRUE(counters.response_count==1);
BC_ASSERT_TRUE(counters.io_error_count==0);
BC_ASSERT_EQUAL(counters.two_hundred,1,int,"%d");
if (one_get("https://smtp.linphone.org/linphone.html",&counters, &counters.response_count) == 0) {
BC_ASSERT_EQUAL(counters.response_count, 1, int, "%d");
BC_ASSERT_EQUAL(counters.io_error_count, 0, int, "%d");
BC_ASSERT_EQUAL(counters.two_hundred,1,int,"%d");
}
}
static void https_digest_get(void){
http_counters_t counters={0};
one_get("https://pauline:pouet@smtp.linphone.org/restricted",&counters,&counters.response_count);
BC_ASSERT_TRUE(counters.response_count==1);
BC_ASSERT_TRUE(counters.io_error_count==0);
BC_ASSERT_EQUAL(counters.three_hundred,1,int,"%d");
if (one_get("https://pauline:pouet@smtp.linphone.org/restricted",&counters,&counters.response_count) == 0) {
BC_ASSERT_EQUAL(counters.response_count, 1, int, "%d");
BC_ASSERT_EQUAL(counters.io_error_count, 0, int, "%d");
BC_ASSERT_EQUAL(counters.three_hundred,1,int,"%d");
}
}
#if 0
static void https_client_cert_connection(void){
......@@ -167,8 +185,9 @@ static void https_client_cert_connection(void){
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_http_provider_set_tls_verify_policy(prov,policy);
one_get("https://sip2.linphone.org:5063",&counters);
BC_ASSERT_EQUAL(counters.two_hundred,1,int,"%d");
if (one_get("https://sip2.linphone.org:5063",&counters) == 0) {
BC_ASSERT_EQUAL(counters.two_hundred,1,int,"%d");
}
belle_tls_verify_policy_set_exceptions(policy,0);
belle_sip_object_unref(policy);
}
......@@ -218,9 +237,14 @@ static void https_post_long_body(void){
belle_generic_uri_t *uri;
belle_http_request_t *req;
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";
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);
char *content_type=belle_sip_strdup_printf("multipart/form-data; boundary=%s",multipart_boudary);
if (url_supported(url)==-1) {
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);
......
......@@ -524,9 +524,13 @@ static void test_connection_too_long(const char *transport){
int orig=belle_sip_stack_get_transport_timeout(stack);
char *no_response_here_with_transport = belle_sip_strdup_printf(no_response_here, transport);
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);
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_free(no_response_here_with_transport);
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