check_stack.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. /****************************************************************************
  2. Name : check_stack.c
  3. Author : uleon @ open62541
  4. Version : 0.1
  5. Copyright : Your copyright notice
  6. Description : test cases to check different aspects of the
  7. stack indication-response behavior w/o any network aspects
  8. ```
  9. Client Server
  10. request o--__
  11. --> indication +
  12. | <---
  13. __--o response +
  14. confirm. <--
  15. ```
  16. *****************************************************************************/
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include "opcua.h"
  20. #include "ua_transport.h"
  21. #include "ua_transport_binary.h"
  22. #include "ua_transport_binary_secure.h"
  23. #include "check.h"
  24. #define MAXMSG 512
  25. #define BUFFER_SIZE 8192
  26. /** @brief this structure holds all the information for the stack test fixture */
  27. typedef struct stackTestFixture {
  28. /** @brief the actual buffer to receive the response msg */
  29. UA_Byte respMsgBuffer[BUFFER_SIZE];
  30. /** @brief the management structure (initialized to point to respMsgBuffer in create */
  31. UA_ByteString respMsg;
  32. /** @brief the management data structure for the fake connection */
  33. TL_Connection connection;
  34. } stackTestFixture;
  35. /** @brief the maximum number of parallel fixtures.
  36. * ( MAX_FIXTURES needs to match the number of bytes of fixturesMap )*/
  37. #define MAX_FIXTURES 32
  38. /** @brief this map marks the slots in fixtures as free (bit=0) or in use (bit=1) */
  39. UA_Int32 fixturesMap = 0;
  40. /** @brief the array of pointers to the fixtures */
  41. stackTestFixture* fixtures[MAX_FIXTURES];
  42. /** @brief search first free handle, set and return */
  43. UA_Int32 stackTestFixture_getAndMarkFreeHandle() {
  44. UA_Int32 freeFixtureHandle = 0;
  45. for (freeFixtureHandle=0;freeFixtureHandle < MAX_FIXTURES;++freeFixtureHandle) {
  46. if (!(fixturesMap & (1 << freeFixtureHandle))) { // when free
  47. fixturesMap |= (1 << freeFixtureHandle); // then set
  48. return freeFixtureHandle;
  49. }
  50. }
  51. return UA_ERR_NO_MEMORY;
  52. }
  53. /** @brief clear bit in fixture map */
  54. UA_Int32 stackTestFixture_markHandleAsFree(UA_Int32 fixtureHandle) {
  55. if (fixtureHandle >= 0 && fixtureHandle < MAX_FIXTURES) {
  56. fixturesMap &= ~ (1 << fixtureHandle); // clear bit
  57. return UA_SUCCESS;
  58. }
  59. return UA_ERR_INVALID_VALUE;
  60. }
  61. /** @brief get a handle to a free slot and create a new stackTestFixture */
  62. UA_Int32 stackTestFixture_create(TL_Writer writerCallback) {
  63. UA_UInt32 fixtureHandle = stackTestFixture_getAndMarkFreeHandle();
  64. if (fixtureHandle < MAX_FIXTURES) {
  65. UA_alloc((void**)&fixtures[fixtureHandle], sizeof(stackTestFixture));
  66. stackTestFixture* fixture = fixtures[fixtureHandle];
  67. fixture->respMsg.data = fixture->respMsgBuffer;
  68. fixture->respMsg.length = 0;
  69. fixture->connection.connectionState = CONNECTIONSTATE_CLOSED;
  70. fixture->connection.writerCallback = writerCallback;
  71. fixture->connection.localConf.maxChunkCount = 1;
  72. fixture->connection.localConf.maxMessageSize = BUFFER_SIZE;
  73. fixture->connection.localConf.protocolVersion = 0;
  74. fixture->connection.localConf.recvBufferSize = BUFFER_SIZE;
  75. fixture->connection.localConf.recvBufferSize = BUFFER_SIZE;
  76. fixture->connection.connectionHandle = fixtureHandle;
  77. }
  78. return fixtureHandle;
  79. }
  80. /** @brief free the allocated memory of the stackTestFixture associated with the handle */
  81. UA_Int32 stackTestFixture_delete(UA_UInt32 fixtureHandle) {
  82. if (fixtureHandle < MAX_FIXTURES) {
  83. UA_free(fixtures[fixtureHandle]);
  84. stackTestFixture_markHandleAsFree(fixtureHandle);
  85. return UA_SUCCESS;
  86. }
  87. return UA_ERR_INVALID_VALUE;
  88. }
  89. /** @brief return the fixture associated with the handle */
  90. stackTestFixture* stackTestFixture_getFixture(UA_UInt32 fixtureHandle) {
  91. if (fixtureHandle < MAX_FIXTURES && ( fixturesMap & (1 << fixtureHandle)))
  92. return fixtures[fixtureHandle];
  93. return UA_NULL;
  94. }
  95. /** @brief write message provided in the gather buffers to the buffer of the fixture */
  96. UA_Int32 responseMsg(struct TL_Connection * c, UA_ByteString const ** gather_buf, UA_Int32 gather_len) {
  97. UA_Int32 retval = UA_SUCCESS;
  98. UA_UInt32 total_len = 0;
  99. stackTestFixture* fixture = stackTestFixture_getFixture(c->connectionHandle);
  100. for (UA_Int32 i=0; i<gather_len && retval == UA_SUCCESS; ++i) {
  101. if (total_len + gather_buf[i]->length < BUFFER_SIZE) {
  102. memcpy(&(fixture->respMsg.data[total_len]),gather_buf[i]->data,gather_buf[i]->length);
  103. total_len += gather_buf[i]->length;
  104. } else {
  105. retval = UA_ERR_NO_MEMORY;
  106. }
  107. }
  108. fixture->respMsg.length = total_len;
  109. return UA_SUCCESS;
  110. }
  111. void indicateMsg(UA_Int32 handle, UA_ByteString *slMessage) {
  112. TL_Process(&(stackTestFixture_getFixture(handle)->connection), slMessage);
  113. }
  114. UA_Byte pkt_HEL[] = {
  115. 0x48, 0x45, 0x4c, 0x46, 0x39, 0x00, /* HELF9. */
  116. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
  117. 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, /* ........ */
  118. 0x00, 0x01, 0x88, 0x13, 0x00, 0x00, 0x19, 0x00, /* ........ */
  119. 0x00, 0x00, 0x6f, 0x70, 0x63, 0x2e, 0x74, 0x63, /* ..opc.tc */
  120. 0x70, 0x3a, 0x2f, 0x2f, 0x31, 0x30, 0x2e, 0x30, /* p://10.0 */
  121. 0x2e, 0x35, 0x34, 0x2e, 0x37, 0x37, 0x3a, 0x34, /* .54.77:4 */
  122. 0x38, 0x34, 0x32 /* 842 */
  123. };
  124. UA_Byte pkt_OPN[] = {
  125. 0x4f, 0x50, 0x4e, 0x46, 0x85, 0x00, /* OPNF.. */
  126. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2f, 0x00, /* ....../. */
  127. 0x00, 0x00, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, /* ..http:/ */
  128. 0x2f, 0x6f, 0x70, 0x63, 0x66, 0x6f, 0x75, 0x6e, /* /opcfoun */
  129. 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x6f, /* dation.o */
  130. 0x72, 0x67, 0x2f, 0x55, 0x41, 0x2f, 0x53, 0x65, /* rg/UA/Se */
  131. 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x50, 0x6f, /* curityPo */
  132. 0x6c, 0x69, 0x63, 0x79, 0x23, 0x4e, 0x6f, 0x6e, /* licy#Non */
  133. 0x65, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* e....... */
  134. 0xff, 0x33, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, /* .3...... */
  135. 0x00, 0x01, 0x00, 0xbe, 0x01, 0x00, 0x00, 0x40, /* .......@ */
  136. 0xaf, 0xfc, 0xe8, 0xa1, 0x76, 0xcf, 0x01, 0x00, /* ....v... */
  137. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, /* ........ */
  138. 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
  139. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
  140. 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, /* ........ */
  141. 0x00, 0x00, 0x00, 0x80, 0xee, 0x36, 0x00 /* .....6. */
  142. };
  143. UA_Byte pkt_MSG_CreateSession[] = {
  144. 0x4d, 0x53, 0x47, 0x46, 0xb4, 0x05, 0x00, 0x00, /* MSGF.... */
  145. 0x19, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, /* QQ...... */ // assumes fixed secureChannelID=25 !
  146. 0x34, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, /* 4....... */
  147. 0x01, 0x00, 0xcd, 0x01, 0x00, 0x00, 0x50, 0xd6, /* ......P. */
  148. 0xfc, 0xe8, 0xa1, 0x76, 0xcf, 0x01, 0x01, 0x00, /* ...v.... */
  149. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, /* ........ */
  150. 0xff, 0xff, 0x10, 0x27, 0x00, 0x00, 0x00, 0x00, /* ...'.... */
  151. 0x00, 0x2d, 0x00, 0x00, 0x00, 0x75, 0x72, 0x6e, /* .-...urn */
  152. 0x3a, 0x6d, 0x72, 0x74, 0x2d, 0x56, 0x69, 0x72, /* :mrt-Vir */
  153. 0x74, 0x75, 0x61, 0x6c, 0x42, 0x6f, 0x78, 0x3a, /* tualBox: */
  154. 0x55, 0x6e, 0x69, 0x66, 0x69, 0x65, 0x64, 0x41, /* UnifiedA */
  155. 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x69, 0x6f, /* utomatio */
  156. 0x6e, 0x3a, 0x55, 0x61, 0x45, 0x78, 0x70, 0x65, /* n:UaExpe */
  157. 0x72, 0x74, 0x1e, 0x00, 0x00, 0x00, 0x75, 0x72, /* rt....ur */
  158. 0x6e, 0x3a, 0x55, 0x6e, 0x69, 0x66, 0x69, 0x65, /* n:Unifie */
  159. 0x64, 0x41, 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, /* dAutomat */
  160. 0x69, 0x6f, 0x6e, 0x3a, 0x55, 0x61, 0x45, 0x78, /* ion:UaEx */
  161. 0x70, 0x65, 0x72, 0x74, 0x02, 0x1b, 0x00, 0x00, /* pert.... */
  162. 0x00, 0x55, 0x6e, 0x69, 0x66, 0x69, 0x65, 0x64, /* .Unified */
  163. 0x20, 0x41, 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, /* Automat */
  164. 0x69, 0x6f, 0x6e, 0x20, 0x55, 0x61, 0x45, 0x78, /* ion UaEx */
  165. 0x70, 0x65, 0x72, 0x74, 0x01, 0x00, 0x00, 0x00, /* pert.... */
  166. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* ........ */
  167. 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, /* ........ */
  168. 0x19, 0x00, 0x00, 0x00, 0x6f, 0x70, 0x63, 0x2e, /* ....opc. */
  169. 0x74, 0x63, 0x70, 0x3a, 0x2f, 0x2f, 0x31, 0x30, /* tcp://10 */
  170. 0x2e, 0x30, 0x2e, 0x35, 0x34, 0x2e, 0x37, 0x37, /* .0.54.77 */
  171. 0x3a, 0x34, 0x38, 0x34, 0x32, 0x2d, 0x00, 0x00, /* :4842-.. */
  172. 0x00, 0x75, 0x72, 0x6e, 0x3a, 0x6d, 0x72, 0x74, /* .urn:mrt */
  173. 0x2d, 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, /* -Virtual */
  174. 0x42, 0x6f, 0x78, 0x3a, 0x55, 0x6e, 0x69, 0x66, /* Box:Unif */
  175. 0x69, 0x65, 0x64, 0x41, 0x75, 0x74, 0x6f, 0x6d, /* iedAutom */
  176. 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x55, 0x61, /* ation:Ua */
  177. 0x45, 0x78, 0x70, 0x65, 0x72, 0x74, 0x20, 0x00, /* Expert . */
  178. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
  179. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
  180. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
  181. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
  182. 0x00, 0x00, 0x72, 0x04, 0x00, 0x00, 0x30, 0x82, /* ..r...0. */
  183. 0x04, 0x6e, 0x30, 0x82, 0x03, 0xd7, 0xa0, 0x03, /* .n0..... */
  184. 0x02, 0x01, 0x02, 0x02, 0x04, 0x53, 0x1b, 0x10, /* .....S.. */
  185. 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, /* .0...*.H */
  186. 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, /* ........ */
  187. 0x30, 0x81, 0x93, 0x31, 0x0b, 0x30, 0x09, 0x06, /* 0..1.0.. */
  188. 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x44, 0x45, /* .U....DE */
  189. 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, /* 1.0...U. */
  190. 0x08, 0x13, 0x08, 0x41, 0x6e, 0x79, 0x77, 0x68, /* ...Anywh */
  191. 0x65, 0x72, 0x65, 0x31, 0x11, 0x30, 0x0f, 0x06, /* ere1.0.. */
  192. 0x03, 0x55, 0x04, 0x07, 0x13, 0x08, 0x41, 0x6e, /* .U....An */
  193. 0x79, 0x77, 0x68, 0x65, 0x72, 0x65, 0x31, 0x13, /* ywhere1. */
  194. 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, /* 0...U... */
  195. 0x0a, 0x54, 0x55, 0x20, 0x44, 0x72, 0x65, 0x73, /* .TU Dres */
  196. 0x64, 0x65, 0x6e, 0x31, 0x36, 0x30, 0x34, 0x06, /* den1604. */
  197. 0x03, 0x55, 0x04, 0x0b, 0x13, 0x2d, 0x43, 0x68, /* .U...-Ch */
  198. 0x61, 0x69, 0x72, 0x20, 0x66, 0x6f, 0x72, 0x20, /* air for */
  199. 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x20, /* Process */
  200. 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x20, /* Control */
  201. 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x73, 0x20, /* Systems */
  202. 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, /* Engineer */
  203. 0x69, 0x6e, 0x67, 0x31, 0x11, 0x30, 0x0f, 0x06, /* ing1.0.. */
  204. 0x03, 0x55, 0x04, 0x03, 0x13, 0x08, 0x55, 0x61, /* .U....Ua */
  205. 0x45, 0x78, 0x70, 0x65, 0x72, 0x74, 0x30, 0x1e, /* Expert0. */
  206. 0x17, 0x0d, 0x31, 0x34, 0x30, 0x33, 0x30, 0x38, /* ..140308 */
  207. 0x31, 0x32, 0x34, 0x34, 0x31, 0x35, 0x5a, 0x17, /* 124415Z. */
  208. 0x0d, 0x31, 0x34, 0x30, 0x33, 0x30, 0x38, 0x31, /* .1403081 */
  209. 0x33, 0x34, 0x34, 0x31, 0x35, 0x5a, 0x30, 0x81, /* 34415Z0. */
  210. 0x93, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, /* .1.0...U */
  211. 0x04, 0x06, 0x13, 0x02, 0x44, 0x45, 0x31, 0x11, /* ....DE1. */
  212. 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, /* 0...U... */
  213. 0x08, 0x41, 0x6e, 0x79, 0x77, 0x68, 0x65, 0x72, /* .Anywher */
  214. 0x65, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, /* e1.0...U */
  215. 0x04, 0x07, 0x13, 0x08, 0x41, 0x6e, 0x79, 0x77, /* ....Anyw */
  216. 0x68, 0x65, 0x72, 0x65, 0x31, 0x13, 0x30, 0x11, /* here1.0. */
  217. 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0a, 0x54, /* ..U....T */
  218. 0x55, 0x20, 0x44, 0x72, 0x65, 0x73, 0x64, 0x65, /* U Dresde */
  219. 0x6e, 0x31, 0x36, 0x30, 0x34, 0x06, 0x03, 0x55, /* n1604..U */
  220. 0x04, 0x0b, 0x13, 0x2d, 0x43, 0x68, 0x61, 0x69, /* ...-Chai */
  221. 0x72, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x50, 0x72, /* r for Pr */
  222. 0x6f, 0x63, 0x65, 0x73, 0x73, 0x20, 0x43, 0x6f, /* ocess Co */
  223. 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x20, 0x53, 0x79, /* ntrol Sy */
  224. 0x73, 0x74, 0x65, 0x6d, 0x73, 0x20, 0x45, 0x6e, /* stems En */
  225. 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, /* gineerin */
  226. 0x67, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, /* g1.0...U */
  227. 0x04, 0x03, 0x13, 0x08, 0x55, 0x61, 0x45, 0x78, /* ....UaEx */
  228. 0x70, 0x65, 0x72, 0x74, 0x30, 0x81, 0x9f, 0x30, /* pert0..0 */
  229. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, /* ...*.H.. */
  230. 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, /* ........ */
  231. 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, /* ..0..... */
  232. 0x00, 0xb3, 0xb3, 0xc9, 0x97, 0xb7, 0x4f, 0x6d, /* ......Om */
  233. 0x6f, 0x72, 0x48, 0xe2, 0x5f, 0x8c, 0x89, 0x0f, /* orH._... */
  234. 0xc3, 0x47, 0x17, 0x4c, 0xd2, 0x8c, 0x2a, 0x85, /* .G.L..*. */
  235. 0xf6, 0x80, 0xb1, 0x9e, 0xf4, 0x90, 0xff, 0x0f, /* ........ */
  236. 0xff, 0x42, 0x74, 0x75, 0xcd, 0xd5, 0xe0, 0x8f, /* .Btu.... */
  237. 0x7f, 0xa1, 0x41, 0x86, 0x83, 0xcf, 0x2c, 0xef, /* ..A...,. */
  238. 0xbd, 0xb7, 0xbf, 0x50, 0xa9, 0x5c, 0xfa, 0x39, /* ...P.\.9 */
  239. 0x84, 0xbb, 0x7e, 0xc9, 0x7e, 0x5b, 0xc8, 0x1b, /* ..~.~[.. */
  240. 0x19, 0xfc, 0x31, 0x05, 0xa9, 0x0c, 0x31, 0x3c, /* ..1...1< */
  241. 0x1a, 0x86, 0x50, 0x17, 0x45, 0x0a, 0xfd, 0xfe, /* ..P.E... */
  242. 0xa0, 0xc4, 0x88, 0x93, 0xff, 0x1c, 0xf3, 0x60, /* .......` */
  243. 0x06, 0xc6, 0xdf, 0x7c, 0xc6, 0xcd, 0x95, 0x7d, /* ...|...} */
  244. 0xf8, 0x3b, 0x7a, 0x53, 0x15, 0xbb, 0x2e, 0xcf, /* .;zS.... */
  245. 0xd1, 0x63, 0xae, 0x5a, 0x30, 0x48, 0x67, 0x5f, /* .c.Z0Hg_ */
  246. 0xa8, 0x30, 0x7f, 0x35, 0xe4, 0x43, 0x94, 0xa3, /* .0.5.C.. */
  247. 0xc1, 0xfe, 0x69, 0xcd, 0x5c, 0xd7, 0x88, 0xc0, /* ..i.\... */
  248. 0xa5, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, /* ........ */
  249. 0x01, 0xcb, 0x30, 0x82, 0x01, 0xc7, 0x30, 0x0c, /* ..0...0. */
  250. 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, /* ..U..... */
  251. 0x04, 0x02, 0x30, 0x00, 0x30, 0x50, 0x06, 0x09, /* ..0.0P.. */
  252. 0x60, 0x86, 0x48, 0x01, 0x86, 0xf8, 0x42, 0x01, /* `.H...B. */
  253. 0x0d, 0x04, 0x43, 0x16, 0x41, 0x22, 0x47, 0x65, /* ..C.A"Ge */
  254. 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x20, /* nerated */
  255. 0x77, 0x69, 0x74, 0x68, 0x20, 0x55, 0x6e, 0x69, /* with Uni */
  256. 0x66, 0x69, 0x65, 0x64, 0x20, 0x41, 0x75, 0x74, /* fied Aut */
  257. 0x6f, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, /* omation */
  258. 0x55, 0x41, 0x20, 0x42, 0x61, 0x73, 0x65, 0x20, /* UA Base */
  259. 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x20, /* Library */
  260. 0x75, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x4f, 0x70, /* using Op */
  261. 0x65, 0x6e, 0x53, 0x53, 0x4c, 0x22, 0x30, 0x1d, /* enSSL"0. */
  262. 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, /* ..U..... */
  263. 0x14, 0x37, 0x39, 0x34, 0x93, 0xa2, 0x65, 0xef, /* .794..e. */
  264. 0xb9, 0xd4, 0x71, 0x21, 0x4b, 0x77, 0xdb, 0x28, /* ..q!Kw.( */
  265. 0xc8, 0xfa, 0x03, 0xfe, 0x05, 0x30, 0x81, 0xc3, /* .....0.. */
  266. 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x81, 0xbb, /* ..U.#... */
  267. 0x30, 0x81, 0xb8, 0x80, 0x14, 0x37, 0x39, 0x34, /* 0....794 */
  268. 0x93, 0xa2, 0x65, 0xef, 0xb9, 0xd4, 0x71, 0x21, /* ..e...q! */
  269. 0x4b, 0x77, 0xdb, 0x28, 0xc8, 0xfa, 0x03, 0xfe, /* Kw.(.... */
  270. 0x05, 0xa1, 0x81, 0x99, 0xa4, 0x81, 0x96, 0x30, /* .......0 */
  271. 0x81, 0x93, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, /* ..1.0... */
  272. 0x55, 0x04, 0x06, 0x13, 0x02, 0x44, 0x45, 0x31, /* U....DE1 */
  273. 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x08, /* .0...U.. */
  274. 0x13, 0x08, 0x41, 0x6e, 0x79, 0x77, 0x68, 0x65, /* ..Anywhe */
  275. 0x72, 0x65, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, /* re1.0... */
  276. 0x55, 0x04, 0x07, 0x13, 0x08, 0x41, 0x6e, 0x79, /* U....Any */
  277. 0x77, 0x68, 0x65, 0x72, 0x65, 0x31, 0x13, 0x30, /* where1.0 */
  278. 0x11, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0a, /* ...U.... */
  279. 0x54, 0x55, 0x20, 0x44, 0x72, 0x65, 0x73, 0x64, /* TU Dresd */
  280. 0x65, 0x6e, 0x31, 0x36, 0x30, 0x34, 0x06, 0x03, /* en1604.. */
  281. 0x55, 0x04, 0x0b, 0x13, 0x2d, 0x43, 0x68, 0x61, /* U...-Cha */
  282. 0x69, 0x72, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x50, /* ir for P */
  283. 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x20, 0x43, /* rocess C */
  284. 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x20, 0x53, /* ontrol S */
  285. 0x79, 0x73, 0x74, 0x65, 0x6d, 0x73, 0x20, 0x45, /* ystems E */
  286. 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, /* ngineeri */
  287. 0x6e, 0x67, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, /* ng1.0... */
  288. 0x55, 0x04, 0x03, 0x13, 0x08, 0x55, 0x61, 0x45, /* U....UaE */
  289. 0x78, 0x70, 0x65, 0x72, 0x74, 0x82, 0x04, 0x53, /* xpert..S */
  290. 0x1b, 0x10, 0x9f, 0x30, 0x0e, 0x06, 0x03, 0x55, /* ...0...U */
  291. 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, /* ........ */
  292. 0x02, 0x02, 0xf4, 0x30, 0x20, 0x06, 0x03, 0x55, /* ...0 ..U */
  293. 0x1d, 0x25, 0x01, 0x01, 0xff, 0x04, 0x16, 0x30, /* .%.....0 */
  294. 0x14, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, /* ...+.... */
  295. 0x07, 0x03, 0x01, 0x06, 0x08, 0x2b, 0x06, 0x01, /* .....+.. */
  296. 0x05, 0x05, 0x07, 0x03, 0x02, 0x30, 0x4e, 0x06, /* .....0N. */
  297. 0x03, 0x55, 0x1d, 0x11, 0x04, 0x47, 0x30, 0x45, /* .U...G0E */
  298. 0x86, 0x2d, 0x75, 0x72, 0x6e, 0x3a, 0x6d, 0x72, /* .-urn:mr */
  299. 0x74, 0x2d, 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, /* t-Virtua */
  300. 0x6c, 0x42, 0x6f, 0x78, 0x3a, 0x55, 0x6e, 0x69, /* lBox:Uni */
  301. 0x66, 0x69, 0x65, 0x64, 0x41, 0x75, 0x74, 0x6f, /* fiedAuto */
  302. 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x55, /* mation:U */
  303. 0x61, 0x45, 0x78, 0x70, 0x65, 0x72, 0x74, 0x82, /* aExpert. */
  304. 0x0e, 0x6d, 0x72, 0x74, 0x2d, 0x56, 0x69, 0x72, /* .mrt-Vir */
  305. 0x74, 0x75, 0x61, 0x6c, 0x42, 0x6f, 0x78, 0x87, /* tualBox. */
  306. 0x04, 0xc0, 0xa8, 0x02, 0x73, 0x30, 0x0d, 0x06, /* ....s0.. */
  307. 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, /* .*.H.... */
  308. 0x01, 0x05, 0x05, 0x00, 0x03, 0x81, 0x81, 0x00, /* ........ */
  309. 0x77, 0x2c, 0x9c, 0x23, 0x60, 0x13, 0x3f, 0xa5, /* w,.#`.?. */
  310. 0xc8, 0xb3, 0x20, 0x27, 0x64, 0xda, 0x7f, 0xaa, /* .. 'd... */
  311. 0xc5, 0x86, 0xfa, 0xd7, 0x24, 0x2e, 0xbe, 0xa0, /* ....$... */
  312. 0xfc, 0x49, 0x8f, 0xc0, 0xef, 0xfb, 0x9a, 0xe6, /* .I...... */
  313. 0x50, 0xe6, 0xb3, 0x53, 0x91, 0x91, 0x89, 0xd3, /* P..S.... */
  314. 0x5a, 0xa5, 0xc9, 0x9c, 0xf6, 0x7b, 0x8f, 0x93, /* Z....{.. */
  315. 0xb4, 0x98, 0xc3, 0x92, 0x26, 0x49, 0x8a, 0x96, /* ....&I.. */
  316. 0x6e, 0x8f, 0xf5, 0x93, 0x48, 0x90, 0x9e, 0x7e, /* n...H..~ */
  317. 0x1d, 0xad, 0x63, 0xbb, 0x5e, 0x1c, 0x0c, 0x86, /* ..c.^... */
  318. 0x2d, 0xce, 0xe2, 0xe1, 0x87, 0x8d, 0x4c, 0x4b, /* -.....LK */
  319. 0x89, 0x24, 0x77, 0xff, 0x62, 0x95, 0xf7, 0xec, /* .$w.b... */
  320. 0x16, 0x7c, 0x8a, 0x1e, 0x4d, 0x89, 0xcb, 0x3d, /* .|..M..= */
  321. 0xc8, 0xc0, 0x7c, 0x12, 0x5a, 0x29, 0xf2, 0xe7, /* ..|.Z).. */
  322. 0x68, 0xf9, 0xb9, 0x85, 0xe5, 0xc0, 0x46, 0xac, /* h.....F. */
  323. 0x89, 0xdb, 0xd0, 0x87, 0xaa, 0xa1, 0x7a, 0x73, /* ......zs */
  324. 0x71, 0xcc, 0x8e, 0x01, 0x80, 0xf3, 0x07, 0x70, /* q......p */
  325. 0x00, 0x00, 0x00, 0x00, 0x80, 0x4f, 0x32, 0x41, /* .....O2A */
  326. 0xff, 0xff, 0xff, 0xff /* .... */
  327. };
  328. START_TEST(emptyIndicationShallYieldNoResponse)
  329. {
  330. // given
  331. UA_Int32 handle = stackTestFixture_create(responseMsg);
  332. UA_ByteString message = { -1, (UA_Byte*) UA_NULL };
  333. // when
  334. indicateMsg(handle, &message);
  335. // then
  336. ck_assert_int_eq(stackTestFixture_getFixture(handle)->respMsg.length,0);
  337. // finally
  338. stackTestFixture_delete(handle);
  339. }
  340. END_TEST
  341. START_TEST(validHELIndicationShallYieldACKResponse)
  342. {
  343. // given
  344. UA_Int32 handle = stackTestFixture_create(responseMsg);
  345. UA_ByteString message_001 = { sizeof(pkt_HEL), pkt_HEL };
  346. // when
  347. indicateMsg(handle, &message_001);
  348. // then
  349. ck_assert_int_eq(stackTestFixture_getFixture(handle)->respMsg.length,28);
  350. ck_assert_int_eq(stackTestFixture_getFixture(handle)->respMsg.data[0],'A');
  351. ck_assert_int_eq(stackTestFixture_getFixture(handle)->respMsg.data[1],'C');
  352. ck_assert_int_eq(stackTestFixture_getFixture(handle)->respMsg.data[2],'K');
  353. // finally
  354. stackTestFixture_delete(handle);
  355. }
  356. END_TEST
  357. START_TEST(validOpeningSequenceShallCreateChannel)
  358. {
  359. // given
  360. UA_Int32 handle = stackTestFixture_create(responseMsg);
  361. UA_ByteString message_001 = { sizeof(pkt_HEL), pkt_HEL };
  362. UA_ByteString message_002 = { sizeof(pkt_OPN), pkt_OPN };
  363. // when
  364. indicateMsg(handle, &message_001);
  365. indicateMsg(handle, &message_002);
  366. // then
  367. ck_assert_int_eq(stackTestFixture_getFixture(handle)->respMsg.data[0],'O');
  368. ck_assert_int_eq(stackTestFixture_getFixture(handle)->respMsg.data[1],'P');
  369. ck_assert_int_eq(stackTestFixture_getFixture(handle)->respMsg.data[2],'N');
  370. ck_assert_int_eq(stackTestFixture_getFixture(handle)->connection.connectionState, CONNECTIONSTATE_ESTABLISHED);
  371. // finally
  372. stackTestFixture_delete(handle);
  373. }
  374. END_TEST
  375. START_TEST(validCreateSessionShallCreateSession)
  376. {
  377. // given
  378. UA_Int32 handle = stackTestFixture_create(responseMsg);
  379. UA_ByteString message_001 = { sizeof(pkt_HEL), pkt_HEL };
  380. UA_ByteString message_002 = { sizeof(pkt_OPN), pkt_OPN };
  381. UA_ByteString message_003 = { sizeof(pkt_MSG_CreateSession), pkt_MSG_CreateSession };
  382. // when
  383. indicateMsg(handle, &message_001);
  384. indicateMsg(handle, &message_002);
  385. UA_Int32 pos = 8;
  386. UA_UInt32 secureChannelId = stackTestFixture_getFixture(handle)->connection.secureChannel->securityToken.secureChannelId;
  387. UA_UInt32_encodeBinary(&secureChannelId,&pos,&message_003);
  388. indicateMsg(handle, &message_003);
  389. // then
  390. ck_assert_int_eq(stackTestFixture_getFixture(handle)->respMsg.data[0],'M');
  391. ck_assert_int_eq(stackTestFixture_getFixture(handle)->respMsg.data[1],'S');
  392. ck_assert_int_eq(stackTestFixture_getFixture(handle)->respMsg.data[2],'G');
  393. ck_assert_ptr_ne(stackTestFixture_getFixture(handle)->connection.secureChannel, UA_NULL);
  394. // finally
  395. stackTestFixture_delete(handle);
  396. }
  397. END_TEST
  398. Suite* testSuite()
  399. {
  400. Suite *s = suite_create("Stack Test");
  401. TCase *tc_core = tcase_create("Core");
  402. tcase_add_test(tc_core, emptyIndicationShallYieldNoResponse);
  403. tcase_add_test(tc_core, validHELIndicationShallYieldACKResponse);
  404. tcase_add_test(tc_core, validOpeningSequenceShallCreateChannel);
  405. tcase_add_test(tc_core, validCreateSessionShallCreateSession);
  406. suite_add_tcase(s,tc_core);
  407. return s;
  408. }
  409. int main (void)
  410. {
  411. int number_failed = 0;
  412. Suite *s;
  413. SRunner *sr;
  414. s = testSuite();
  415. sr = srunner_create(s);
  416. srunner_run_all(sr,CK_NORMAL);
  417. number_failed += srunner_ntests_failed(sr);
  418. srunner_free(sr);
  419. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  420. }