check_securechannel.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include "ua_securechannel.h"
  7. #include "ua_securitypolicy_none.h"
  8. #include "check.h"
  9. #include "ua_types_generated_handling.h"
  10. #include "ua_log_stdout.h"
  11. #define UA_BYTESTRING_STATIC(s) {sizeof(s)-1, (UA_Byte*)s}
  12. UA_SecureChannel testChannel;
  13. UA_ByteString dummyCertificate = UA_BYTESTRING_STATIC("DUMMY CERTIFICATE DUMMY CERTIFICATE DUMMY CERTIFICATE");
  14. UA_SecurityPolicy dummyPolicy;
  15. /*
  16. static void
  17. setup(void) {
  18. UA_SecureChannel_init(&testChannel, &dummyPolicy, &dummyCertificate);
  19. }
  20. static void
  21. teardown(void) {
  22. UA_SecureChannel_deleteMembersCleanup(&testChannel);
  23. }*/
  24. static void
  25. setup_dummyPolicy(void) {
  26. UA_SecurityPolicy_Dummy(&dummyPolicy);
  27. }
  28. static void
  29. teardown_dummyPolicy(void) {
  30. UA_SecurityPolicy_Dummy_deleteMembers(&dummyPolicy);
  31. }
  32. START_TEST(SecureChannel_initAndDelete)
  33. {
  34. UA_SecurityPolicy_None(&dummyPolicy, dummyCertificate, UA_Log_Stdout);
  35. UA_StatusCode retval;
  36. UA_SecureChannel channel;
  37. retval = UA_SecureChannel_init(&channel, &dummyPolicy, &dummyCertificate);
  38. ck_assert_msg(retval == UA_STATUSCODE_GOOD, "Expected StatusCode to be good");
  39. ck_assert_msg(channel.state == UA_SECURECHANNELSTATE_FRESH, "Expected state to be fresh");
  40. }
  41. END_TEST
  42. START_TEST(SecureChannel_initAndDelete_invalidParameters)
  43. {
  44. UA_StatusCode retval = UA_SecureChannel_init(NULL, NULL, NULL);
  45. ck_assert_msg(retval != UA_STATUSCODE_GOOD, "Expected init to fail");
  46. UA_SecureChannel channel;
  47. retval = UA_SecureChannel_init(&channel, &dummyPolicy, NULL);
  48. ck_assert_msg(retval != UA_STATUSCODE_GOOD, "Expected init to fail");
  49. retval = UA_SecureChannel_init(&channel, NULL, &dummyCertificate);
  50. ck_assert_msg(retval != UA_STATUSCODE_GOOD, "Expected init to fail");
  51. retval = UA_SecureChannel_init(NULL, &dummyPolicy, &dummyCertificate);
  52. ck_assert_msg(retval != UA_STATUSCODE_GOOD, "Expected init to fail");
  53. UA_SecureChannel_deleteMembersCleanup(NULL);
  54. }
  55. END_TEST
  56. /*
  57. START_TEST(SecureChannel_generateNewKeys)
  58. {
  59. }
  60. END_TEST*/
  61. static Suite *
  62. testSuite_SecureChannel(void) {
  63. Suite *s = suite_create("SecureChannel");
  64. TCase *tc_initAndDelete = tcase_create("Initialize and delete Securechannel");
  65. tcase_add_test(tc_initAndDelete, SecureChannel_initAndDelete);
  66. tcase_add_test(tc_initAndDelete, SecureChannel_initAndDelete_invalidParameters);
  67. suite_add_tcase(s, tc_initAndDelete);
  68. return s;
  69. }
  70. int
  71. main(void) {
  72. Suite *s = testSuite_SecureChannel();
  73. SRunner *sr = srunner_create(s);
  74. srunner_set_fork_status(sr, CK_NOFORK);
  75. srunner_run_all(sr, CK_NORMAL);
  76. int number_failed = srunner_ntests_failed(sr);
  77. srunner_free(sr);
  78. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  79. }