check_client_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 <pthread.h>
  5. #include "ua_types.h"
  6. #include "ua_server.h"
  7. #include "ua_client.h"
  8. #include "ua_config_default.h"
  9. #include "ua_client_highlevel.h"
  10. #include "ua_network_tcp.h"
  11. #include "testing_clock.h"
  12. #include "check.h"
  13. UA_Server *server;
  14. UA_ServerConfig *config;
  15. UA_Boolean *running;
  16. pthread_t server_thread;
  17. static void * serverloop(void *_) {
  18. while(*running)
  19. UA_Server_run_iterate(server, true);
  20. return NULL;
  21. }
  22. static void setup(void) {
  23. running = UA_Boolean_new();
  24. *running = true;
  25. config = UA_ServerConfig_new_default();
  26. server = UA_Server_new(config);
  27. UA_Server_run_startup(server);
  28. pthread_create(&server_thread, NULL, serverloop, NULL);
  29. UA_realSleep(100);
  30. }
  31. static void teardown(void) {
  32. *running = false;
  33. pthread_join(server_thread, NULL);
  34. UA_Server_run_shutdown(server);
  35. UA_Boolean_delete(running);
  36. UA_Server_delete(server);
  37. UA_ServerConfig_delete(config);
  38. }
  39. START_TEST(SecureChannel_timeout_max) {
  40. UA_Client *client = UA_Client_new(UA_ClientConfig_default);
  41. UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840");
  42. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  43. UA_fakeSleep(UA_ClientConfig_default.secureChannelLifeTime);
  44. UA_Variant val;
  45. UA_NodeId nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_STATE);
  46. retval = UA_Client_readValueAttribute(client, nodeId, &val);
  47. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  48. UA_Variant_deleteMembers(&val);
  49. UA_Client_disconnect(client);
  50. UA_Client_delete(client);
  51. }
  52. END_TEST
  53. /*
  54. START_TEST(SecureChannel_timeout_fail) {
  55. UA_Client *client = UA_Client_new(UA_ClientConfig_default);
  56. UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840");
  57. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  58. UA_fakeSleep(UA_ClientConfig_default.secureChannelLifeTime+1);
  59. UA_Variant val;
  60. UA_Variant_init(&val);
  61. UA_NodeId nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_STATE);
  62. retval = UA_Client_readValueAttribute(client, nodeId, &val);
  63. ck_assert(retval != UA_STATUSCODE_GOOD);
  64. UA_Variant_deleteMembers(&val);
  65. UA_Client_disconnect(client);
  66. UA_Client_delete(client);
  67. }
  68. END_TEST*/
  69. int main(void) {
  70. TCase *tc_sc = tcase_create("Client SecureChannel");
  71. tcase_add_checked_fixture(tc_sc, setup, teardown);
  72. tcase_add_test(tc_sc, SecureChannel_timeout_max);
  73. // Temporarily disable test since it is failing. See #1388
  74. //tcase_add_test(tc_sc, SecureChannel_timeout_fail);
  75. Suite *s = suite_create("Client");
  76. suite_add_tcase(s, tc_sc);
  77. SRunner *sr = srunner_create(s);
  78. srunner_set_fork_status(sr, CK_NOFORK);
  79. srunner_run_all(sr,CK_NORMAL);
  80. int number_failed = srunner_ntests_failed(sr);
  81. srunner_free(sr);
  82. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  83. }