2
0

minor_bugs_test.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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>
  10. #include <stdio.h>
  11. #include "zrtp.h"
  12. #include "cmockery/cmockery.h"
  13. zrtp_global_t *zrtp;
  14. void setup() {
  15. zrtp_status_t s;
  16. zrtp_config_t zrtp_config;
  17. zrtp_config_defaults(&zrtp_config);
  18. s = zrtp_init(&zrtp_config, &zrtp);
  19. assert_int_equal(s, zrtp_status_ok);
  20. }
  21. void teardown() {
  22. zrtp_down(zrtp);
  23. }
  24. static void session_init_fails_with_no_dh2k() {
  25. zrtp_profile_t profile;
  26. zrtp_status_t s;
  27. zrtp_session_t *new_session;
  28. /* Let's initialize ZRTP session with default profile first */
  29. zrtp_profile_defaults(&profile, zrtp);
  30. new_session = NULL;
  31. s = zrtp_session_init(zrtp,
  32. &profile,
  33. ZRTP_SIGNALING_ROLE_INITIATOR,
  34. &new_session);
  35. assert_int_equal(zrtp_status_ok, s);
  36. assert_non_null(new_session);
  37. /* Then disable DH2K and leave just mandatory parameters */
  38. profile.pk_schemes[0] = ZRTP_PKTYPE_DH3072;
  39. profile.pk_schemes[1] = ZRTP_PKTYPE_MULT;
  40. profile.pk_schemes[2] = 0;
  41. new_session = NULL;
  42. s = zrtp_session_init(zrtp,
  43. &profile,
  44. ZRTP_SIGNALING_ROLE_INITIATOR,
  45. &new_session);
  46. assert_int_equal(zrtp_status_ok, s);
  47. assert_non_null(new_session);
  48. /* Let's try to disable Multi key exchange, it should produce an error. */
  49. profile.pk_schemes[0] = ZRTP_PKTYPE_DH3072;
  50. profile.pk_schemes[1] = 0;
  51. new_session = NULL;
  52. s = zrtp_session_init(zrtp,
  53. &profile,
  54. ZRTP_SIGNALING_ROLE_INITIATOR,
  55. &new_session);
  56. assert_int_not_equal(zrtp_status_ok, s);
  57. assert_null(new_session);
  58. /* Profile checking with one of mandatory components missing should return error too. */
  59. s = zrtp_profile_check(&profile, zrtp);
  60. assert_int_not_equal(zrtp_status_ok, s);
  61. /* NOTE: we ignore memory leaks and don't destroy ZRTP sessions to make test sources cleaner */
  62. }
  63. int main(void) {
  64. const UnitTest tests[] = {
  65. unit_test_setup_teardown(session_init_fails_with_no_dh2k, setup, teardown),
  66. };
  67. return run_tests(tests);
  68. }