mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-23 11:36:09 +00:00
Refactor test cases
Modified-by: Travis Cross <tc@traviscross.com> Signed-off-by: Travis Cross <tc@traviscross.com>
This commit is contained in:
parent
521e673b5f
commit
02b3b8060a
69
libs/libzrtp/test/engine_helpers.c
Normal file
69
libs/libzrtp/test/engine_helpers.c
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||||
|
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||||
|
* Contact: http://philzimmermann.com
|
||||||
|
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||||
|
*
|
||||||
|
* Viktor Krykun <v.krikun at zfoneproject.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <setjmp.h> /*chmockery dependency*/
|
||||||
|
#include <stdio.h> /*chmockery dependency*/
|
||||||
|
#include <unistd.h> /*for usleep*/
|
||||||
|
|
||||||
|
#include "cmockery/cmockery.h"
|
||||||
|
#include "test_engine.h"
|
||||||
|
|
||||||
|
static zrtp_test_id_t g_alice, g_bob;
|
||||||
|
static zrtp_test_id_t g_alice_sid, g_bob_sid;
|
||||||
|
static zrtp_test_id_t g_secure_audio_channel;
|
||||||
|
|
||||||
|
|
||||||
|
static void prepare_alice_bob() {
|
||||||
|
zrtp_status_t s;
|
||||||
|
|
||||||
|
zrtp_test_session_cfg_t session_config;
|
||||||
|
zrtp_test_session_config_defaults(&session_config);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create two test sessions, one for Alice and one for Bob and link them
|
||||||
|
* into test secure channel
|
||||||
|
*/
|
||||||
|
s = zrtp_test_session_create(g_alice, &session_config, &g_alice_sid);
|
||||||
|
assert_int_equal(zrtp_status_ok, s);
|
||||||
|
assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_alice_sid);
|
||||||
|
|
||||||
|
s = zrtp_test_session_create(g_bob, &session_config, &g_bob_sid);
|
||||||
|
assert_int_equal(zrtp_status_ok, s);
|
||||||
|
assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_bob_sid);
|
||||||
|
|
||||||
|
s = zrtp_test_channel_create2(g_alice_sid, g_bob_sid, 0, &g_secure_audio_channel);
|
||||||
|
assert_int_equal(zrtp_status_ok, s);
|
||||||
|
assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_secure_audio_channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void release_alice_bob() {
|
||||||
|
zrtp_test_session_destroy(g_alice_sid);
|
||||||
|
zrtp_test_session_destroy(g_bob_sid);
|
||||||
|
|
||||||
|
zrtp_test_channel_destroy(g_secure_audio_channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void start_alice_bob_and_wait4secure() {
|
||||||
|
zrtp_status_t s;
|
||||||
|
zrtp_test_channel_info_t channel_info;
|
||||||
|
|
||||||
|
/* Everything is ready. Let's start the stream and give it few seconds to switch secure. */
|
||||||
|
s = zrtp_test_channel_start(g_secure_audio_channel);
|
||||||
|
assert_int_equal(zrtp_status_ok, s);
|
||||||
|
|
||||||
|
unsigned i = 30;
|
||||||
|
for (; i>0; i--) {
|
||||||
|
usleep(100*1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
s = zrtp_test_channel_get(g_secure_audio_channel, &channel_info);
|
||||||
|
assert_int_equal(zrtp_status_ok, s);
|
||||||
|
|
||||||
|
assert_true(channel_info.is_secure);
|
||||||
|
}
|
@ -7,16 +7,7 @@
|
|||||||
* Viktor Krykun <v.krikun at zfoneproject.com>
|
* Viktor Krykun <v.krikun at zfoneproject.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <setjmp.h> /*chmockery dependency*/
|
#include "engine_helpers.c"
|
||||||
#include <stdio.h> /*chmockery dependency*/
|
|
||||||
#include <unistd.h> /*for usleep*/
|
|
||||||
|
|
||||||
#include "cmockery/cmockery.h"
|
|
||||||
#include "test_engine.h"
|
|
||||||
|
|
||||||
static zrtp_test_id_t g_alice, g_bob;
|
|
||||||
static zrtp_test_id_t g_alice_sid, g_bob_sid;
|
|
||||||
static zrtp_test_id_t g_secure_audio_channel;
|
|
||||||
|
|
||||||
static void setup() {
|
static void setup() {
|
||||||
zrtp_status_t s;
|
zrtp_status_t s;
|
||||||
@ -38,56 +29,6 @@ static void teardown() {
|
|||||||
zrtp_test_endpoint_destroy(g_bob);
|
zrtp_test_endpoint_destroy(g_bob);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prepare_alice_bob() {
|
|
||||||
zrtp_status_t s;
|
|
||||||
|
|
||||||
//zrtp_test_channel_info_t channel_info;
|
|
||||||
zrtp_test_session_cfg_t session_config;
|
|
||||||
zrtp_test_session_config_defaults(&session_config);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Create two test sessions, one for Alice and one for Bob and link them
|
|
||||||
* into test secure channel
|
|
||||||
*/
|
|
||||||
s = zrtp_test_session_create(g_alice, &session_config, &g_alice_sid);
|
|
||||||
assert_int_equal(zrtp_status_ok, s);
|
|
||||||
assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_alice_sid);
|
|
||||||
|
|
||||||
s = zrtp_test_session_create(g_bob, &session_config, &g_bob_sid);
|
|
||||||
assert_int_equal(zrtp_status_ok, s);
|
|
||||||
assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_bob_sid);
|
|
||||||
|
|
||||||
s = zrtp_test_channel_create2(g_alice_sid, g_bob_sid, 0, &g_secure_audio_channel);
|
|
||||||
assert_int_equal(zrtp_status_ok, s);
|
|
||||||
assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_secure_audio_channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void release_alice_bob() {
|
|
||||||
zrtp_test_session_destroy(g_alice_sid);
|
|
||||||
zrtp_test_session_destroy(g_bob_sid);
|
|
||||||
|
|
||||||
zrtp_test_channel_destroy(g_secure_audio_channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void start_alice_bob_and_wait4secure() {
|
|
||||||
zrtp_status_t s;
|
|
||||||
zrtp_test_channel_info_t channel_info;
|
|
||||||
|
|
||||||
/* Everything is ready. Let's start the stream and give it few seconds to switch secure. */
|
|
||||||
s = zrtp_test_channel_start(g_secure_audio_channel);
|
|
||||||
assert_int_equal(zrtp_status_ok, s);
|
|
||||||
|
|
||||||
unsigned i = 30;
|
|
||||||
for (; i>0; i--) {
|
|
||||||
usleep(100*1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
s = zrtp_test_channel_get(g_secure_audio_channel, &channel_info);
|
|
||||||
assert_int_equal(zrtp_status_ok, s);
|
|
||||||
|
|
||||||
assert_true(channel_info.is_secure);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void go_secure_test() {
|
static void go_secure_test() {
|
||||||
/*
|
/*
|
||||||
|
113
libs/libzrtp/test/zrtphash_test.c
Normal file
113
libs/libzrtp/test/zrtphash_test.c
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||||
|
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||||
|
* Contact: http://philzimmermann.com
|
||||||
|
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||||
|
*
|
||||||
|
* Viktor Krykun <v.krikun at zfoneproject.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "engine_helpers.c"
|
||||||
|
|
||||||
|
static void setup() {
|
||||||
|
zrtp_status_t s;
|
||||||
|
|
||||||
|
zrtp_test_endpoint_cfg_t endpoint_cfg;
|
||||||
|
zrtp_test_endpoint_config_defaults(&endpoint_cfg);
|
||||||
|
|
||||||
|
s = zrtp_test_endpoint_create(&endpoint_cfg, "Alice", &g_alice);
|
||||||
|
assert_int_equal(zrtp_status_ok, s);
|
||||||
|
assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_alice);
|
||||||
|
|
||||||
|
s = zrtp_test_endpoint_create(&endpoint_cfg, "Bob", &g_bob);
|
||||||
|
assert_int_equal(zrtp_status_ok, s);
|
||||||
|
assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_bob);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void teardown() {
|
||||||
|
zrtp_test_endpoint_destroy(g_alice);
|
||||||
|
zrtp_test_endpoint_destroy(g_bob);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void zrtp_hash_export_import_sunny_test() {
|
||||||
|
zrtp_status_t s;
|
||||||
|
char alice_zrtp_hash[ZRTP_SIGN_ZRTP_HASH_LENGTH];
|
||||||
|
char bob_zrtp_hash[ZRTP_SIGN_ZRTP_HASH_LENGTH];
|
||||||
|
zrtp_stream_t *alice_zrtp_stream, *bob_zrtp_stream;
|
||||||
|
|
||||||
|
/* Create two test sessions, one for Alice and one for Bob and link them into test secure channel */
|
||||||
|
prepare_alice_bob();
|
||||||
|
|
||||||
|
alice_zrtp_stream = zrtp_stream_for_test_stream(zrtp_test_session_get_stream_by_idx(g_alice_sid, 0));
|
||||||
|
bob_zrtp_stream = zrtp_stream_for_test_stream(zrtp_test_session_get_stream_by_idx(g_bob_sid, 0));
|
||||||
|
assert_non_null(alice_zrtp_stream); assert_non_null(bob_zrtp_stream);
|
||||||
|
|
||||||
|
/* Take Alice's hash and give it to Bob */
|
||||||
|
s = zrtp_signaling_hash_get(alice_zrtp_stream, alice_zrtp_hash, sizeof(alice_zrtp_hash));
|
||||||
|
assert_int_equal(zrtp_status_ok, s);
|
||||||
|
|
||||||
|
s = zrtp_signaling_hash_set(bob_zrtp_stream, alice_zrtp_hash, ZRTP_SIGN_ZRTP_HASH_LENGTH);
|
||||||
|
assert_int_equal(zrtp_status_ok, s);
|
||||||
|
|
||||||
|
/* Take Bob's hash and give it to Alice */
|
||||||
|
s = zrtp_signaling_hash_get(bob_zrtp_stream, bob_zrtp_hash, sizeof(bob_zrtp_hash));
|
||||||
|
assert_int_equal(zrtp_status_ok, s);
|
||||||
|
|
||||||
|
s = zrtp_signaling_hash_set(alice_zrtp_stream, bob_zrtp_hash, ZRTP_SIGN_ZRTP_HASH_LENGTH);
|
||||||
|
assert_int_equal(zrtp_status_ok, s);
|
||||||
|
|
||||||
|
/* Start and wait for Secure */
|
||||||
|
start_alice_bob_and_wait4secure();
|
||||||
|
|
||||||
|
/* Check if ZRTP_EVENT_WRONG_SIGNALING_HASH was not triggered for any of test endpoints */
|
||||||
|
assert_false(zrtp_stream_did_event_receive(zrtp_test_session_get_stream_by_idx(g_alice_sid, 0),
|
||||||
|
ZRTP_EVENT_WRONG_SIGNALING_HASH));
|
||||||
|
|
||||||
|
assert_false(zrtp_stream_did_event_receive(zrtp_test_session_get_stream_by_idx(g_bob_sid, 0),
|
||||||
|
ZRTP_EVENT_WRONG_SIGNALING_HASH));
|
||||||
|
|
||||||
|
/* Release test setup */
|
||||||
|
release_alice_bob();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void zrtp_hash_import_wrong_test() {
|
||||||
|
zrtp_status_t s;
|
||||||
|
char wrong_alice_zrtp_hash[ZRTP_SIGN_ZRTP_HASH_LENGTH];
|
||||||
|
zrtp_stream_t *bob_zrtp_stream;
|
||||||
|
|
||||||
|
/* Create two test sessions, one for Alice and one for Bob and link them into test secure channel */
|
||||||
|
prepare_alice_bob();
|
||||||
|
|
||||||
|
bob_zrtp_stream = zrtp_stream_for_test_stream(zrtp_test_session_get_stream_by_idx(g_bob_sid, 0));
|
||||||
|
assert_non_null(bob_zrtp_stream);
|
||||||
|
|
||||||
|
/* Let's provide wrong hash to bob */
|
||||||
|
zrtp_memset(wrong_alice_zrtp_hash, 6, ZRTP_SIGN_ZRTP_HASH_LENGTH);
|
||||||
|
|
||||||
|
s = zrtp_signaling_hash_set(bob_zrtp_stream, wrong_alice_zrtp_hash, ZRTP_SIGN_ZRTP_HASH_LENGTH);
|
||||||
|
assert_int_equal(zrtp_status_ok, s);
|
||||||
|
|
||||||
|
/* Start and wait for Secure */
|
||||||
|
start_alice_bob_and_wait4secure();
|
||||||
|
|
||||||
|
/* Check if Alice don't receive ZRTP_EVENT_WRONG_SIGNALING_HASH, but Bob should get one */
|
||||||
|
assert_false(zrtp_stream_did_event_receive(zrtp_test_session_get_stream_by_idx(g_alice_sid, 0),
|
||||||
|
ZRTP_EVENT_WRONG_SIGNALING_HASH));
|
||||||
|
|
||||||
|
assert_true(zrtp_stream_did_event_receive(zrtp_test_session_get_stream_by_idx(g_bob_sid, 0),
|
||||||
|
ZRTP_EVENT_WRONG_SIGNALING_HASH));
|
||||||
|
|
||||||
|
/* Release test setup */
|
||||||
|
release_alice_bob();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
const UnitTest tests[] = {
|
||||||
|
unit_test_setup_teardown(zrtp_hash_export_import_sunny_test, setup, teardown),
|
||||||
|
unit_test_setup_teardown(zrtp_hash_import_wrong_test, setup, teardown),
|
||||||
|
};
|
||||||
|
|
||||||
|
return run_tests(tests);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user