2 * libZRTP SDK library, implements the ZRTP secure VoIP protocol.
3 * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
4 * Contact: http://philzimmermann.com
5 * For licensing and other legal details, see the file zrtp_legal.c.
7 * Viktor Krykun <v.krikun at zfoneproject.com>
10 #include <setjmp.h> /*chmockery dependency*/
11 #include <stdio.h> /*chmockery dependency*/
12 #include <unistd.h> /*for usleep*/
14 #include "cmockery/cmockery.h"
15 #include "test_engine.h"
17 #include "enroll_test_helpers.c"
19 static void enrollment_test() {
22 zrtp_test_channel_info_t a2pbx_channel_info
;
23 zrtp_test_session_cfg_t session_config
, session_config_enroll
;
24 zrtp_test_session_config_defaults(&session_config
);
25 zrtp_test_session_config_defaults(&session_config_enroll
);
27 session_config_enroll
.is_enrollment
= 1;
29 /**************************************************************************
30 * Enroll Alice to PBX and check triggered events.
32 prepare_alice_pbx_bob_setup(&session_config
, NULL
, &session_config_enroll
, NULL
);
34 /* Everything is ready. Let's start the stream and give it few seconds to switch secure. */
35 s
= zrtp_test_channel_start(g_alice2pbx_channel
);
36 assert_int_equal(zrtp_status_ok
, s
);
43 s
= zrtp_test_channel_get(g_alice2pbx_channel
, &a2pbx_channel_info
);
44 assert_int_equal(zrtp_status_ok
, s
);
46 /* Both, Alice and PBX should switch secure */
47 assert_true(a2pbx_channel_info
.is_secure
);
49 /* Alice should receive Enrollment notification */
50 zrtp_test_id_t alice2pbx_stream
= zrtp_test_session_get_stream_by_idx(g_alice_sid
, 0);
51 assert_true(zrtp_stream_did_event_receive(alice2pbx_stream
, ZRTP_EVENT_IS_CLIENT_ENROLLMENT
));
53 /* PBX streams should receive incoming enrollment notification */
54 zrtp_test_id_t pbx2alice_stream
= zrtp_test_session_get_stream_by_idx(g_pbxa_sid
, 0);
55 assert_true(zrtp_stream_did_event_receive(pbx2alice_stream
, ZRTP_EVENT_NEW_USER_ENROLLED
));
57 /* Confirm enrollment at the PBX side */
58 s
= zrtp_register_with_trusted_mitm(zrtp_stream_for_test_stream(alice2pbx_stream
));
59 assert_int_equal(zrtp_status_ok
, s
);
62 cleanup_alice_pbx_bob_setup();
64 /**************************************************************************
65 * Try to make one more enrollment call. This time it should say "Already enrolled"
67 prepare_alice_pbx_bob_setup(&session_config
, NULL
, &session_config_enroll
, NULL
);
69 /* Everything is ready. Let's start the stream and give it few seconds to switch secure. */
70 s
= zrtp_test_channel_start(g_alice2pbx_channel
);
71 assert_int_equal(zrtp_status_ok
, s
);
78 s
= zrtp_test_channel_get(g_alice2pbx_channel
, &a2pbx_channel_info
);
79 assert_int_equal(zrtp_status_ok
, s
);
81 assert_true(a2pbx_channel_info
.is_secure
);
83 /* Alice should receive Enrollment notification */
84 alice2pbx_stream
= zrtp_test_session_get_stream_by_idx(g_alice_sid
, 0);
85 assert_true(zrtp_stream_did_event_receive(alice2pbx_stream
, ZRTP_EVENT_IS_CLIENT_ENROLLMENT
));
87 /* PBX streams should receive incoming enrollment notification */
88 pbx2alice_stream
= zrtp_test_session_get_stream_by_idx(g_pbxa_sid
, 0);
89 assert_true(zrtp_stream_did_event_receive(pbx2alice_stream
, ZRTP_EVENT_USER_ALREADY_ENROLLED
));
91 // TODO: check if we have PBX secret cached
92 // TODO: test zrtp_is_user_enrolled()
96 const UnitTest tests
[] = {
97 unit_test_setup_teardown(enrollment_test
, pbx_setup
, pbx_teardown
),
100 return run_tests(tests
);