2
0

enrollment_test.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  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.
  6. *
  7. * Viktor Krykun <v.krikun at zfoneproject.com>
  8. */
  9. #include <setjmp.h> /*chmockery dependency*/
  10. #include <stdio.h> /*chmockery dependency*/
  11. #include <unistd.h> /*for usleep*/
  12. #include "cmockery/cmockery.h"
  13. #include "test_engine.h"
  14. #include "enroll_test_helpers.c"
  15. static void enrollment_test() {
  16. zrtp_status_t s;
  17. zrtp_test_channel_info_t a2pbx_channel_info;
  18. zrtp_test_session_cfg_t session_config, session_config_enroll;
  19. zrtp_test_session_config_defaults(&session_config);
  20. zrtp_test_session_config_defaults(&session_config_enroll);
  21. session_config_enroll.is_enrollment = 1;
  22. /**************************************************************************
  23. * Enroll Alice to PBX and check triggered events.
  24. */
  25. prepare_alice_pbx_bob_setup(&session_config, NULL, &session_config_enroll, NULL);
  26. /* Everything is ready. Let's start the stream and give it few seconds to switch secure. */
  27. s = zrtp_test_channel_start(g_alice2pbx_channel);
  28. assert_int_equal(zrtp_status_ok, s);
  29. int i = 30;
  30. for (; i>0; i--) {
  31. usleep(100*1000);
  32. }
  33. s = zrtp_test_channel_get(g_alice2pbx_channel, &a2pbx_channel_info);
  34. assert_int_equal(zrtp_status_ok, s);
  35. /* Both, Alice and PBX should switch secure */
  36. assert_true(a2pbx_channel_info.is_secure);
  37. /* Alice should receive Enrollment notification */
  38. zrtp_test_id_t alice2pbx_stream = zrtp_test_session_get_stream_by_idx(g_alice_sid, 0);
  39. assert_true(zrtp_stream_did_event_receive(alice2pbx_stream, ZRTP_EVENT_IS_CLIENT_ENROLLMENT));
  40. /* PBX streams should receive incoming enrollment notification */
  41. zrtp_test_id_t pbx2alice_stream = zrtp_test_session_get_stream_by_idx(g_pbxa_sid, 0);
  42. assert_true(zrtp_stream_did_event_receive(pbx2alice_stream, ZRTP_EVENT_NEW_USER_ENROLLED));
  43. /* Confirm enrollment at the PBX side */
  44. s = zrtp_register_with_trusted_mitm(zrtp_stream_for_test_stream(alice2pbx_stream));
  45. assert_int_equal(zrtp_status_ok, s);
  46. /* Clean-up */
  47. cleanup_alice_pbx_bob_setup();
  48. /**************************************************************************
  49. * Try to make one more enrollment call. This time it should say "Already enrolled"
  50. */
  51. prepare_alice_pbx_bob_setup(&session_config, NULL, &session_config_enroll, NULL);
  52. /* Everything is ready. Let's start the stream and give it few seconds to switch secure. */
  53. s = zrtp_test_channel_start(g_alice2pbx_channel);
  54. assert_int_equal(zrtp_status_ok, s);
  55. i = 30;
  56. for (; i>0; i--) {
  57. usleep(100*1000);
  58. }
  59. s = zrtp_test_channel_get(g_alice2pbx_channel, &a2pbx_channel_info);
  60. assert_int_equal(zrtp_status_ok, s);
  61. assert_true(a2pbx_channel_info.is_secure);
  62. /* Alice should receive Enrollment notification */
  63. alice2pbx_stream = zrtp_test_session_get_stream_by_idx(g_alice_sid, 0);
  64. assert_true(zrtp_stream_did_event_receive(alice2pbx_stream, ZRTP_EVENT_IS_CLIENT_ENROLLMENT));
  65. /* PBX streams should receive incoming enrollment notification */
  66. pbx2alice_stream = zrtp_test_session_get_stream_by_idx(g_pbxa_sid, 0);
  67. assert_true(zrtp_stream_did_event_receive(pbx2alice_stream, ZRTP_EVENT_USER_ALREADY_ENROLLED));
  68. // TODO: check if we have PBX secret cached
  69. // TODO: test zrtp_is_user_enrolled()
  70. }
  71. int main(void) {
  72. const UnitTest tests[] = {
  73. unit_test_setup_teardown(enrollment_test, pbx_setup, pbx_teardown),
  74. };
  75. return run_tests(tests);
  76. }