From d938a6da6d5db9a47fd3b1cb3445150c80810513 Mon Sep 17 00:00:00 2001 From: Viktor Krykun Date: Fri, 15 Jun 2012 10:23:46 +0300 Subject: [PATCH] Add test for some minor bugs Modified-by: Travis Cross Signed-off-by: Travis Cross --- libs/libzrtp/test/minor_bugs_test.c | 92 +++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 libs/libzrtp/test/minor_bugs_test.c diff --git a/libs/libzrtp/test/minor_bugs_test.c b/libs/libzrtp/test/minor_bugs_test.c new file mode 100644 index 0000000000..2bf46b220b --- /dev/null +++ b/libs/libzrtp/test/minor_bugs_test.c @@ -0,0 +1,92 @@ +/* + * 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 + */ + +#include +#include + +#include "zrtp.h" +#include "cmockery/cmockery.h" + +zrtp_global_t *zrtp; + +void setup() { + zrtp_status_t s; + zrtp_config_t zrtp_config; + + zrtp_config_defaults(&zrtp_config); + + s = zrtp_init(&zrtp_config, &zrtp); + assert_int_equal(s, zrtp_status_ok); +} + +void teardown() { + zrtp_down(zrtp); +} + + +static void session_init_fails_with_no_dh2k() { + zrtp_profile_t profile; + zrtp_status_t s; + + zrtp_session_t *new_session; + + /* Let's initialize ZRTP session with default profile first */ + zrtp_profile_defaults(&profile, zrtp); + + new_session = NULL; + s = zrtp_session_init(zrtp, + &profile, + ZRTP_SIGNALING_ROLE_INITIATOR, + &new_session); + + assert_int_equal(zrtp_status_ok, s); + assert_non_null(new_session); + + /* Then disable DH2K and leave just mandatory parameters */ + profile.pk_schemes[0] = ZRTP_PKTYPE_DH3072; + profile.pk_schemes[1] = ZRTP_PKTYPE_MULT; + profile.pk_schemes[2] = 0; + + new_session = NULL; + s = zrtp_session_init(zrtp, + &profile, + ZRTP_SIGNALING_ROLE_INITIATOR, + &new_session); + + assert_int_equal(zrtp_status_ok, s); + assert_non_null(new_session); + + /* Let's try to disable Multi key exchange, it should produce an error. */ + profile.pk_schemes[0] = ZRTP_PKTYPE_DH3072; + profile.pk_schemes[1] = 0; + + new_session = NULL; + s = zrtp_session_init(zrtp, + &profile, + ZRTP_SIGNALING_ROLE_INITIATOR, + &new_session); + + assert_int_not_equal(zrtp_status_ok, s); + assert_null(new_session); + + /* Profile checking with one of mandatory components missing should return error too. */ + s = zrtp_profile_check(&profile, zrtp); + assert_int_not_equal(zrtp_status_ok, s); + + /* NOTE: we ignore memory leaks and don't destroy ZRTP sessions to make test sources cleaner */ +} + + +int main(void) { + const UnitTest tests[] = { + unit_test_setup_teardown(session_init_fails_with_no_dh2k, setup, teardown), + }; + + return run_tests(tests); +}