testutil_security.hpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MPL-2.0 */
2 
3 #ifndef __TESTUTIL_SECURITY_HPP_INCLUDED__
4 #define __TESTUTIL_SECURITY_HPP_INCLUDED__
5 
6 #include "testutil_unity.hpp"
8 
9 // security test utils
10 
11 typedef void (socket_config_fn) (void *, void *);
12 
13 // NULL specific functions
14 void socket_config_null_client (void *server_, void *server_secret_);
15 
16 void socket_config_null_server (void *server_, void *server_secret_);
17 
18 // PLAIN specific functions
19 void socket_config_plain_client (void *server_, void *server_secret_);
20 
21 void socket_config_plain_server (void *server_, void *server_secret_);
22 
23 // CURVE specific functions
24 
25 // We'll generate random test keys at startup
26 extern char valid_client_public[41];
27 extern char valid_client_secret[41];
28 extern char valid_server_public[41];
29 extern char valid_server_secret[41];
30 
32 
33 void socket_config_curve_server (void *server_, void *server_secret_);
34 
36 {
37  const char *server_public;
38  const char *client_public;
39  const char *client_secret;
40 };
41 
42 void socket_config_curve_client (void *client_, void *data_);
43 
44 // --------------------------------------------------------------------------
45 // This methods receives and validates ZAP requests (allowing or denying
46 // each client connection).
47 
49 {
51  // ZAP-compliant non-standard cases
54  // ZAP protocol errors
62 };
63 
64 extern void *zap_requests_handled;
65 
66 void zap_handler_generic (zap_protocol_t zap_protocol_,
67  const char *expected_routing_id_ = "IDENT");
68 
69 void zap_handler (void * /*unused_*/);
70 
71 // Security-specific monitor event utilities
72 
73 // assert_* are macros rather than functions, to allow assertion failures be
74 // attributed to the causing source code line
75 #define assert_no_more_monitor_events_with_timeout(monitor, timeout) \
76  { \
77  int event_count = 0; \
78  int event, err; \
79  while ((event = get_monitor_event_with_timeout ((monitor), &err, NULL, \
80  (timeout))) \
81  != -1) { \
82  if (event == ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL \
83  && (err == EPIPE || err == ECONNRESET \
84  || err == ECONNABORTED)) { \
85  fprintf (stderr, \
86  "Ignored event (skipping any further events): %x " \
87  "(err = %i == %s)\n", \
88  event, err, zmq_strerror (err)); \
89  continue; \
90  } \
91  ++event_count; \
92  /* TODO write this into a buffer and attach to the assertion msg below */ \
93  print_unexpected_event_stderr (event, err, 0, 0); \
94  } \
95  TEST_ASSERT_EQUAL_INT (0, event_count); \
96  }
97 
99  void **zap_control_,
100  void **zap_thread_,
101  void **server_,
102  void **server_mon_,
103  char *my_endpoint_,
104  zmq_thread_fn zap_handler_ = &zap_handler,
106  void *socket_config_data_ = valid_server_secret,
107  const char *routing_id_ = "IDENT");
108 
109 void shutdown_context_and_server_side (void *zap_thread_,
110  void *server_,
111  void *server_mon_,
112  void *zap_control_,
113  bool zap_handler_stopped_ = false);
114 
115 void *create_and_connect_client (char *my_endpoint_,
116  socket_config_fn socket_config_,
117  void *socket_config_data_,
118  void **client_mon_ = NULL);
119 
120 void expect_new_client_bounce_fail (char *my_endpoint_,
121  void *server_,
122  socket_config_fn socket_config_,
123  void *socket_config_data_,
124  void **client_mon_ = NULL,
125  int expected_client_event_ = 0,
126  int expected_client_value_ = 0);
127 
128 #endif
socket_config_fn
void() socket_config_fn(void *, void *)
Definition: testutil_security.hpp:11
curve_client_data_t
Definition: testutil_security.hpp:35
expect_new_client_bounce_fail
void expect_new_client_bounce_fail(char *my_endpoint_, void *server_, socket_config_fn socket_config_, void *socket_config_data_, void **client_mon_=NULL, int expected_client_event_=0, int expected_client_value_=0)
Definition: testutil_security.cpp:362
data_
StringPiece data_
Definition: bytestream_unittest.cc:60
zap_status_internal_error
@ zap_status_internal_error
Definition: testutil_security.hpp:53
zap_ok
@ zap_ok
Definition: testutil_security.hpp:50
NULL
NULL
Definition: test_security_zap.cpp:405
curve_client_data_t::client_public
const char * client_public
Definition: testutil_security.hpp:38
valid_client_secret
char valid_client_secret[41]
Definition: testutil_security.cpp:53
setup_context_and_server_side
void setup_context_and_server_side(void **zap_control_, void **zap_thread_, void **server_, void **server_mon_, char *my_endpoint_, zmq_thread_fn zap_handler_=&zap_handler, socket_config_fn socket_config_=&socket_config_curve_server, void *socket_config_data_=valid_server_secret, const char *routing_id_="IDENT")
Definition: testutil_security.cpp:264
zap_protocol_t
zap_protocol_t
Definition: testutil_security.hpp:48
zap_too_many_parts
@ zap_too_many_parts
Definition: testutil_security.hpp:58
curve_client_data_t::server_public
const char * server_public
Definition: testutil_security.hpp:37
zap_do_not_recv
@ zap_do_not_recv
Definition: testutil_security.hpp:60
valid_client_public
char valid_client_public[41]
Definition: testutil_security.cpp:52
zap_wrong_request_id
@ zap_wrong_request_id
Definition: testutil_security.hpp:56
zmq_thread_fn
void() zmq_thread_fn(void *)
Definition: zmq.h:605
zap_handler_generic
void zap_handler_generic(zap_protocol_t zap_protocol_, const char *expected_routing_id_="IDENT")
Definition: testutil_security.cpp:98
testutil_unity.hpp
valid_server_public
char valid_server_public[41]
Definition: testutil_security.cpp:54
valid_server_secret
char valid_server_secret[41]
Definition: testutil_security.cpp:55
create_and_connect_client
void * create_and_connect_client(char *my_endpoint_, socket_config_fn socket_config_, void *socket_config_data_, void **client_mon_=NULL)
Definition: testutil_security.cpp:338
zap_do_not_send
@ zap_do_not_send
Definition: testutil_security.hpp:61
zap_status_temporary_failure
@ zap_status_temporary_failure
Definition: testutil_security.hpp:52
void
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
socket_config_plain_client
void socket_config_plain_client(void *server_, void *server_secret_)
Definition: testutil_security.cpp:31
setup_testutil_security_curve
void setup_testutil_security_curve()
Definition: testutil_security.cpp:57
shutdown_context_and_server_side
void shutdown_context_and_server_side(void *zap_thread_, void *server_, void *server_mon_, void *zap_control_, bool zap_handler_stopped_=false)
Definition: testutil_security.cpp:314
socket_config_null_client
void socket_config_null_client(void *server_, void *server_secret_)
Definition: testutil_security.cpp:9
socket_config_curve_client
void socket_config_curve_client(void *client_, void *data_)
Definition: testutil_security.cpp:83
testutil_monitoring.hpp
socket_config_null_server
void socket_config_null_server(void *server_, void *server_secret_)
Definition: testutil_security.cpp:15
zap_status_invalid
@ zap_status_invalid
Definition: testutil_security.hpp:57
socket_config_plain_server
void socket_config_plain_server(void *server_, void *server_secret_)
Definition: testutil_security.cpp:41
zap_handler
void zap_handler(void *)
Definition: testutil_security.cpp:238
curve_client_data_t::client_secret
const char * client_secret
Definition: testutil_security.hpp:39
zap_requests_handled
void * zap_requests_handled
Definition: testutil_security.cpp:96
zap_wrong_version
@ zap_wrong_version
Definition: testutil_security.hpp:55
socket_config_curve_server
void socket_config_curve_server(void *server_, void *server_secret_)
Definition: testutil_security.cpp:66
zap_disconnect
@ zap_disconnect
Definition: testutil_security.hpp:59


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:59