Commit 340bc89b authored by Simon Morlat's avatar Simon Morlat

Improve DoS module test, and fix unreliable call with DNS timeout test.

parent 58634ae1
......@@ -932,7 +932,6 @@ void disable_all_video_codecs_except_one(LinphoneCore *lc, const char *mime) {
static void call_with_dns_time_out(void) {
LinphoneCoreManager* marie = linphone_core_manager_new2( "empty_rc", FALSE);
LinphoneSipTransports transport = {9773,0,0,0};
int i;
linphone_core_set_sip_transports(marie->lc,&transport);
linphone_core_iterate(marie->lc);
......
......@@ -1024,32 +1024,43 @@ static void file_transfer_message_rcs_to_external_body_client(void) {
static void dos_module_trigger(void) {
LinphoneChatRoom *chat_room;
int i = 0;
int dummy = 0;
const char* passmsg = "This one should pass through";
int number_of_messge_to_send = 100;
LinphoneChatMessage * chat_msg = NULL;
LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
int message_rate = 20;
int flood_duration_ms = 8000;
uint64_t time_begin, time_current;
int message_sent_index = 0;
int message_to_send_index = 0;
reset_counters(&marie->stat);
reset_counters(&pauline->stat);
chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity);
time_begin = bctbx_get_cur_time_ms();
do {
char msg[128];
sprintf(msg, "Flood message number %i", i);
chat_msg = linphone_chat_room_create_message(chat_room, msg);
linphone_chat_message_send(chat_msg);
wait_for_until(marie->lc, pauline->lc, &dummy, 1, 10);
i++;
} while (i < number_of_messge_to_send);
time_current = bctbx_get_cur_time_ms();
message_to_send_index = ((time_current - time_begin) * message_rate) / 1000;
if (message_to_send_index > message_sent_index){
char msg[128] = { 0 };
snprintf(msg, sizeof(msg)-1, "Flood message number %i", message_sent_index);
chat_msg = linphone_chat_room_create_message(chat_room, msg);
linphone_chat_message_send(chat_msg);
message_sent_index++;
}else{
wait_for_until(marie->lc, pauline->lc, &dummy, 1, 20);
}
time_current = bctbx_get_cur_time_ms();
} while (time_current - time_begin < (uint64_t)flood_duration_ms);
// At this point we should be banned for a minute
wait_for_until(marie->lc, pauline->lc, &dummy, 1, 65000);; // Wait several seconds to ensure we are not banned anymore
BC_ASSERT_LOWER_STRICT(marie->stat.number_of_LinphoneMessageReceived, number_of_messge_to_send, int, "%d");
BC_ASSERT_GREATER(message_sent_index, message_rate, int, "%d");
BC_ASSERT_LOWER_STRICT(marie->stat.number_of_LinphoneMessageReceived, message_sent_index - message_rate, int, "%d");
wait_for_until(marie->lc, pauline->lc, &dummy, 1, 65000); // Wait several seconds to ensure we are not banned anymore
reset_counters(&marie->stat);
reset_counters(&pauline->stat);
chat_msg = linphone_chat_room_create_message(chat_room, passmsg);
......@@ -1975,8 +1986,14 @@ static void deal_with_jwe_auth_module(const char *jwe, bool_t invalid_jwe, bool_
linphone_call_params_unref(gandalf_params);
int n_expected_calls = invalid_jwe || invalid_oid ? 0 : 1;
BC_ASSERT_TRUE(wait_for_list(lcs, &gandalf->stat.number_of_LinphoneCallOutgoingRinging, n_expected_calls, 3000));
BC_ASSERT_TRUE(wait_for_list(lcs, &pauline->stat.number_of_LinphoneCallIncomingReceived, n_expected_calls, 3000));
if (n_expected_calls){
BC_ASSERT_TRUE(wait_for_list(lcs, &gandalf->stat.number_of_LinphoneCallOutgoingRinging, 1, 3000));
BC_ASSERT_TRUE(wait_for_list(lcs, &pauline->stat.number_of_LinphoneCallIncomingReceived, 1, 3000));
}else{
BC_ASSERT_TRUE(wait_for_list(lcs, &gandalf->stat.number_of_LinphoneCallError, 1, 3000));
BC_ASSERT_TRUE(wait_for_list(lcs, &gandalf->stat.number_of_LinphoneCallReleased, 1, 3000));
}
LinphoneCall *pauline_call = linphone_core_get_current_call(pauline->lc);
if (!n_expected_calls)
......@@ -1992,15 +2009,15 @@ static void deal_with_jwe_auth_module(const char *jwe, bool_t invalid_jwe, bool_
LinphoneCall *gandalf_call = linphone_core_get_current_call(gandalf->lc);
if (n_expected_calls) {
if (gandalf_call)
BC_ASSERT_PTR_NOT_NULL(gandalf_call);
if (gandalf_call){
linphone_call_terminate(gandalf_call);
BC_ASSERT_TRUE(wait_for_list(lcs, &gandalf->stat.number_of_LinphoneCallEnd, 1, 3000));
BC_ASSERT_TRUE(wait_for_list(lcs, &pauline->stat.number_of_LinphoneCallEnd, n_expected_calls, 3000));
BC_ASSERT_TRUE(wait_for_list(lcs, &gandalf->stat.number_of_LinphoneCallReleased, 1, 3000));
BC_ASSERT_TRUE(wait_for_list(lcs, &pauline->stat.number_of_LinphoneCallReleased, 1, 3000));
}
}
BC_ASSERT_TRUE(wait_for_list(lcs, &gandalf->stat.number_of_LinphoneCallEnd, 1, 3000));
BC_ASSERT_TRUE(wait_for_list(lcs, &pauline->stat.number_of_LinphoneCallEnd, 1, 3000));
BC_ASSERT_TRUE(wait_for_list(lcs, &gandalf->stat.number_of_LinphoneCallReleased, 1, 3000));
BC_ASSERT_TRUE(wait_for_list(lcs, &pauline->stat.number_of_LinphoneCallReleased, 1, 3000));
linphone_core_manager_destroy(gandalf);
linphone_core_manager_destroy(pauline);
......
......@@ -234,6 +234,8 @@ static void profile_call_base(bool_t avpf1
linphone_core_terminate_all_calls(marie->lc);
BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneCallEnd, 1));
BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &pauline->stat.number_of_LinphoneCallEnd, 1));
BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneCallReleased, 1));
BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &pauline->stat.number_of_LinphoneCallReleased, 1));
BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneCallConnected, 1, int, "%d");
BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneCallConnected, 1, int, "%d");
end:
......
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