2023-06-05 00:16:05 +01:00
|
|
|
/* SPDX-License-Identifier: MPL-2.0 */
|
2017-08-17 11:45:18 +02:00
|
|
|
|
|
|
|
#include "testutil_security.hpp"
|
2019-03-20 12:34:47 +01:00
|
|
|
#include "testutil_unity.hpp"
|
|
|
|
|
2019-03-24 12:51:28 -04:00
|
|
|
SETUP_TEARDOWN_TESTCONTEXT
|
2017-08-17 11:45:18 +02:00
|
|
|
|
2019-03-20 16:03:06 +01:00
|
|
|
static void zap_handler_wrong_version (void * /*unused_*/)
|
2017-08-17 11:45:18 +02:00
|
|
|
{
|
2019-03-20 16:03:06 +01:00
|
|
|
zap_handler_generic (zap_wrong_version);
|
2017-08-17 11:45:18 +02:00
|
|
|
}
|
|
|
|
|
2019-03-20 16:03:06 +01:00
|
|
|
static void zap_handler_wrong_request_id (void * /*unused_*/)
|
2017-08-17 11:45:18 +02:00
|
|
|
{
|
2019-03-20 16:03:06 +01:00
|
|
|
zap_handler_generic (zap_wrong_request_id);
|
2017-08-17 11:45:18 +02:00
|
|
|
}
|
|
|
|
|
2019-03-20 16:03:06 +01:00
|
|
|
static void zap_handler_wrong_status_invalid (void * /*unused_*/)
|
2017-08-17 11:45:18 +02:00
|
|
|
{
|
2019-03-20 16:03:06 +01:00
|
|
|
zap_handler_generic (zap_status_invalid);
|
2017-08-17 11:45:18 +02:00
|
|
|
}
|
|
|
|
|
2019-03-20 16:03:06 +01:00
|
|
|
static void zap_handler_wrong_status_temporary_failure (void * /*unused_*/)
|
2017-08-17 11:45:18 +02:00
|
|
|
{
|
2019-03-20 16:03:06 +01:00
|
|
|
zap_handler_generic (zap_status_temporary_failure);
|
2017-08-17 11:45:18 +02:00
|
|
|
}
|
|
|
|
|
2019-03-20 16:03:06 +01:00
|
|
|
static void zap_handler_wrong_status_internal_error (void * /*unused_*/)
|
2017-08-17 11:45:18 +02:00
|
|
|
{
|
2019-03-20 16:03:06 +01:00
|
|
|
zap_handler_generic (zap_status_internal_error);
|
2017-08-17 11:45:18 +02:00
|
|
|
}
|
|
|
|
|
2019-03-20 16:03:06 +01:00
|
|
|
static void zap_handler_too_many_parts (void * /*unused_*/)
|
2017-08-17 11:45:18 +02:00
|
|
|
{
|
2019-03-20 16:03:06 +01:00
|
|
|
zap_handler_generic (zap_too_many_parts);
|
2017-08-17 11:45:18 +02:00
|
|
|
}
|
|
|
|
|
2019-03-20 16:03:06 +01:00
|
|
|
static void zap_handler_disconnect (void * /*unused_*/)
|
2017-09-18 15:11:51 +02:00
|
|
|
{
|
2019-03-20 16:03:06 +01:00
|
|
|
zap_handler_generic (zap_disconnect);
|
2017-09-18 15:11:51 +02:00
|
|
|
}
|
|
|
|
|
2019-03-20 16:03:06 +01:00
|
|
|
static void zap_handler_do_not_recv (void * /*unused_*/)
|
2017-09-18 17:19:36 +02:00
|
|
|
{
|
2019-03-20 16:03:06 +01:00
|
|
|
zap_handler_generic (zap_do_not_recv);
|
2017-09-18 17:19:36 +02:00
|
|
|
}
|
|
|
|
|
2019-03-20 16:03:06 +01:00
|
|
|
static void zap_handler_do_not_send (void * /*unused_*/)
|
2017-09-18 17:19:36 +02:00
|
|
|
{
|
2019-03-20 16:03:06 +01:00
|
|
|
zap_handler_generic (zap_do_not_send);
|
2017-09-18 17:19:36 +02:00
|
|
|
}
|
|
|
|
|
2017-09-18 11:48:14 +02:00
|
|
|
int expect_new_client_bounce_fail_and_count_monitor_events (
|
2018-05-27 07:01:36 -04:00
|
|
|
char *my_endpoint_,
|
|
|
|
void *server_,
|
2017-09-18 11:48:14 +02:00
|
|
|
socket_config_fn socket_config_,
|
|
|
|
void *socket_config_data_,
|
2018-05-27 07:01:36 -04:00
|
|
|
void **client_mon_,
|
|
|
|
void *server_mon_,
|
|
|
|
int expected_server_event_,
|
|
|
|
int expected_server_value_,
|
|
|
|
int expected_client_event_ = 0,
|
|
|
|
int expected_client_value_ = 0)
|
2017-09-18 11:48:14 +02:00
|
|
|
{
|
2017-09-19 11:05:46 +02:00
|
|
|
expect_new_client_bounce_fail (
|
2019-03-20 16:03:06 +01:00
|
|
|
my_endpoint_, server_, socket_config_, socket_config_data_, client_mon_,
|
|
|
|
expected_client_event_, expected_client_value_);
|
2017-09-18 11:48:14 +02:00
|
|
|
|
|
|
|
int events_received = 0;
|
2017-09-19 11:05:46 +02:00
|
|
|
events_received = expect_monitor_event_multiple (
|
2018-05-27 07:01:36 -04:00
|
|
|
server_mon_, expected_server_event_, expected_server_value_);
|
2017-09-18 11:48:14 +02:00
|
|
|
|
|
|
|
return events_received;
|
|
|
|
}
|
|
|
|
|
2019-03-20 16:03:06 +01:00
|
|
|
void test_zap_unsuccessful (char *my_endpoint_,
|
2018-05-27 07:01:36 -04:00
|
|
|
void *server_,
|
|
|
|
void *server_mon_,
|
|
|
|
int expected_server_event_,
|
|
|
|
int expected_server_value_,
|
2017-08-17 11:45:18 +02:00
|
|
|
socket_config_fn socket_config_,
|
2017-08-18 13:19:07 +02:00
|
|
|
void *socket_config_data_,
|
2018-05-27 07:01:36 -04:00
|
|
|
void **client_mon_ = NULL,
|
|
|
|
int expected_client_event_ = 0,
|
|
|
|
int expected_client_value_ = 0)
|
2017-08-17 11:45:18 +02:00
|
|
|
{
|
2017-09-19 11:05:46 +02:00
|
|
|
int server_events_received =
|
2017-09-18 11:48:14 +02:00
|
|
|
expect_new_client_bounce_fail_and_count_monitor_events (
|
2019-03-20 16:03:06 +01:00
|
|
|
my_endpoint_, server_, socket_config_, socket_config_data_, client_mon_,
|
|
|
|
server_mon_, expected_server_event_, expected_server_value_,
|
|
|
|
expected_client_event_, expected_client_value_);
|
2017-08-17 11:45:18 +02:00
|
|
|
|
2017-09-18 11:48:14 +02:00
|
|
|
// there may be more than one ZAP request due to repeated attempts by the
|
2017-08-18 13:19:07 +02:00
|
|
|
// client (actually only in case if ZAP status code 300)
|
2019-03-20 12:34:47 +01:00
|
|
|
TEST_ASSERT_TRUE (server_events_received == 0
|
|
|
|
|| 1 <= zmq_atomic_counter_value (zap_requests_handled));
|
2017-08-17 11:45:18 +02:00
|
|
|
}
|
|
|
|
|
2019-03-20 16:03:06 +01:00
|
|
|
void test_zap_unsuccessful_no_handler (char *my_endpoint_,
|
2018-05-27 07:01:36 -04:00
|
|
|
void *server_,
|
|
|
|
void *server_mon_,
|
|
|
|
int expected_event_,
|
|
|
|
int expected_err_,
|
2017-09-18 11:48:14 +02:00
|
|
|
socket_config_fn socket_config_,
|
|
|
|
void *socket_config_data_,
|
2018-05-27 07:01:36 -04:00
|
|
|
void **client_mon_ = NULL)
|
2017-09-18 11:48:14 +02:00
|
|
|
{
|
2019-03-20 12:34:47 +01:00
|
|
|
const int events_received =
|
2017-09-18 11:48:14 +02:00
|
|
|
expect_new_client_bounce_fail_and_count_monitor_events (
|
2019-03-20 16:03:06 +01:00
|
|
|
my_endpoint_, server_, socket_config_, socket_config_data_, client_mon_,
|
|
|
|
server_mon_, expected_event_, expected_err_);
|
2017-09-18 11:48:14 +02:00
|
|
|
|
|
|
|
// there may be more than one ZAP request due to repeated attempts by the
|
|
|
|
// client
|
2019-03-20 12:34:47 +01:00
|
|
|
TEST_ASSERT_GREATER_THAN_INT (0, events_received);
|
2017-09-18 11:48:14 +02:00
|
|
|
}
|
|
|
|
|
2019-03-20 16:03:06 +01:00
|
|
|
void test_zap_protocol_error (char *my_endpoint_,
|
2018-05-27 07:01:36 -04:00
|
|
|
void *server_,
|
|
|
|
void *server_mon_,
|
2017-08-17 11:45:18 +02:00
|
|
|
socket_config_fn socket_config_,
|
2017-08-17 17:54:07 +02:00
|
|
|
void *socket_config_data_,
|
2018-05-27 07:01:36 -04:00
|
|
|
int expected_error_)
|
2017-08-17 11:45:18 +02:00
|
|
|
{
|
2019-03-20 16:03:06 +01:00
|
|
|
test_zap_unsuccessful (my_endpoint_, server_, server_mon_,
|
2018-05-27 07:01:36 -04:00
|
|
|
ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, expected_error_,
|
2017-08-17 11:45:18 +02:00
|
|
|
socket_config_, socket_config_data_);
|
|
|
|
}
|
|
|
|
|
2019-03-20 16:03:06 +01:00
|
|
|
void test_zap_unsuccessful_status_300 (char *my_endpoint_,
|
2018-05-27 07:01:36 -04:00
|
|
|
void *server_,
|
|
|
|
void *server_mon_,
|
2017-08-18 13:19:07 +02:00
|
|
|
socket_config_fn client_socket_config_,
|
|
|
|
void *client_socket_config_data_)
|
|
|
|
{
|
|
|
|
void *client_mon;
|
2018-11-18 11:37:52 +00:00
|
|
|
test_zap_unsuccessful (
|
2019-03-20 16:03:06 +01:00
|
|
|
my_endpoint_, server_, server_mon_, ZMQ_EVENT_HANDSHAKE_FAILED_AUTH, 300,
|
|
|
|
client_socket_config_, client_socket_config_data_, &client_mon);
|
2017-08-18 13:19:07 +02:00
|
|
|
|
2017-09-19 11:05:46 +02:00
|
|
|
// we can use a 0 timeout here, since the client socket is already closed
|
|
|
|
assert_no_more_monitor_events_with_timeout (client_mon, 0);
|
2017-08-18 13:19:07 +02:00
|
|
|
|
2019-03-20 16:03:06 +01:00
|
|
|
test_context_socket_close (client_mon);
|
2017-08-18 13:19:07 +02:00
|
|
|
}
|
|
|
|
|
2019-03-20 16:03:06 +01:00
|
|
|
void test_zap_unsuccessful_status_500 (char *my_endpoint_,
|
2018-05-27 07:01:36 -04:00
|
|
|
void *server_,
|
|
|
|
void *server_mon_,
|
2017-08-18 13:19:07 +02:00
|
|
|
socket_config_fn client_socket_config_,
|
|
|
|
void *client_socket_config_data_)
|
|
|
|
{
|
2019-03-20 16:03:06 +01:00
|
|
|
test_zap_unsuccessful (my_endpoint_, server_, server_mon_,
|
2017-08-18 13:19:07 +02:00
|
|
|
ZMQ_EVENT_HANDSHAKE_FAILED_AUTH, 500,
|
|
|
|
client_socket_config_, client_socket_config_data_,
|
2018-11-18 11:37:52 +00:00
|
|
|
NULL, ZMQ_EVENT_HANDSHAKE_FAILED_AUTH, 500);
|
2017-08-18 13:19:07 +02:00
|
|
|
}
|
|
|
|
|
2019-03-20 12:34:47 +01:00
|
|
|
static void
|
|
|
|
test_zap_protocol_error_closure (socket_config_fn server_socket_config_,
|
|
|
|
socket_config_fn client_socket_config_,
|
|
|
|
void *client_socket_config_data_,
|
|
|
|
void *server_socket_config_data_,
|
|
|
|
zmq_thread_fn zap_handler_,
|
|
|
|
int expected_failure_)
|
2017-08-17 11:45:18 +02:00
|
|
|
{
|
2019-03-20 16:03:06 +01:00
|
|
|
void *handler, *zap_thread, *server, *server_mon;
|
2017-08-17 11:45:18 +02:00
|
|
|
char my_endpoint[MAX_SOCKET_STRING];
|
|
|
|
|
|
|
|
setup_context_and_server_side (
|
2019-03-20 16:03:06 +01:00
|
|
|
&handler, &zap_thread, &server, &server_mon, my_endpoint, zap_handler_,
|
|
|
|
server_socket_config_, server_socket_config_data_);
|
|
|
|
test_zap_protocol_error (my_endpoint, server, server_mon,
|
2017-08-17 17:54:07 +02:00
|
|
|
client_socket_config_, client_socket_config_data_,
|
2019-03-20 12:34:47 +01:00
|
|
|
expected_failure_);
|
2019-03-20 16:03:06 +01:00
|
|
|
shutdown_context_and_server_side (zap_thread, server, server_mon, handler);
|
2019-03-20 12:34:47 +01:00
|
|
|
}
|
2017-08-17 11:45:18 +02:00
|
|
|
|
2019-03-20 12:34:47 +01:00
|
|
|
static void
|
|
|
|
test_zap_protocol_error_wrong_version (socket_config_fn server_socket_config_,
|
|
|
|
socket_config_fn client_socket_config_,
|
|
|
|
void *client_socket_config_data_,
|
|
|
|
void *server_socket_config_data_)
|
|
|
|
{
|
|
|
|
test_zap_protocol_error_closure (
|
|
|
|
server_socket_config_, client_socket_config_, client_socket_config_data_,
|
|
|
|
server_socket_config_data_, &zap_handler_wrong_version,
|
|
|
|
ZMQ_PROTOCOL_ERROR_ZAP_BAD_VERSION);
|
|
|
|
}
|
2017-08-17 11:45:18 +02:00
|
|
|
|
2019-03-20 12:34:47 +01:00
|
|
|
static void test_zap_protocol_error_wrong_request_id (
|
|
|
|
socket_config_fn server_socket_config_,
|
|
|
|
socket_config_fn client_socket_config_,
|
|
|
|
void *client_socket_config_data_,
|
|
|
|
void *server_socket_config_data_)
|
|
|
|
{
|
|
|
|
test_zap_protocol_error_closure (
|
|
|
|
server_socket_config_, client_socket_config_, client_socket_config_data_,
|
|
|
|
server_socket_config_data_, &zap_handler_wrong_request_id,
|
|
|
|
ZMQ_PROTOCOL_ERROR_ZAP_BAD_REQUEST_ID);
|
|
|
|
}
|
2017-08-17 11:45:18 +02:00
|
|
|
|
2019-03-20 12:34:47 +01:00
|
|
|
static void test_zap_protocol_error_wrong_status_invalid (
|
|
|
|
socket_config_fn server_socket_config_,
|
|
|
|
socket_config_fn client_socket_config_,
|
|
|
|
void *client_socket_config_data_,
|
|
|
|
void *server_socket_config_data_)
|
|
|
|
{
|
|
|
|
test_zap_protocol_error_closure (
|
|
|
|
server_socket_config_, client_socket_config_, client_socket_config_data_,
|
|
|
|
server_socket_config_data_, &zap_handler_wrong_status_invalid,
|
|
|
|
ZMQ_PROTOCOL_ERROR_ZAP_INVALID_STATUS_CODE);
|
|
|
|
}
|
2017-08-17 11:45:18 +02:00
|
|
|
|
2019-03-20 12:34:47 +01:00
|
|
|
static void
|
|
|
|
test_zap_protocol_error_too_many_parts (socket_config_fn server_socket_config_,
|
|
|
|
socket_config_fn client_socket_config_,
|
|
|
|
void *client_socket_config_data_,
|
|
|
|
void *server_socket_config_data_)
|
|
|
|
{
|
|
|
|
test_zap_protocol_error_closure (
|
|
|
|
server_socket_config_, client_socket_config_, client_socket_config_data_,
|
|
|
|
server_socket_config_data_, &zap_handler_too_many_parts,
|
|
|
|
ZMQ_PROTOCOL_ERROR_ZAP_MALFORMED_REPLY);
|
|
|
|
}
|
2017-08-17 11:45:18 +02:00
|
|
|
|
2019-03-20 12:34:47 +01:00
|
|
|
// TODO the failed status (300/500) should be observable as monitoring events on the client side as well (they are
|
|
|
|
// already transmitted as an ERROR message)
|
2017-08-17 11:45:18 +02:00
|
|
|
|
2019-03-20 12:34:47 +01:00
|
|
|
static void
|
|
|
|
test_zap_wrong_status_temporary_failure (socket_config_fn server_socket_config_,
|
|
|
|
socket_config_fn client_socket_config_,
|
|
|
|
void *client_socket_config_data_,
|
|
|
|
void *server_socket_config_data_)
|
|
|
|
{
|
2019-03-20 16:03:06 +01:00
|
|
|
void *handler, *zap_thread, *server, *server_mon;
|
2019-03-20 12:34:47 +01:00
|
|
|
char my_endpoint[MAX_SOCKET_STRING];
|
2017-08-17 11:45:18 +02:00
|
|
|
setup_context_and_server_side (
|
2019-03-20 16:03:06 +01:00
|
|
|
&handler, &zap_thread, &server, &server_mon, my_endpoint,
|
2017-08-17 11:45:18 +02:00
|
|
|
&zap_handler_wrong_status_temporary_failure, server_socket_config_,
|
|
|
|
server_socket_config_data_);
|
2019-03-20 16:03:06 +01:00
|
|
|
test_zap_unsuccessful_status_300 (my_endpoint, server, server_mon,
|
2017-08-18 13:19:07 +02:00
|
|
|
client_socket_config_,
|
|
|
|
client_socket_config_data_);
|
2019-03-20 16:03:06 +01:00
|
|
|
shutdown_context_and_server_side (zap_thread, server, server_mon, handler);
|
2019-03-20 12:34:47 +01:00
|
|
|
}
|
2017-08-17 11:45:18 +02:00
|
|
|
|
2019-03-20 12:34:47 +01:00
|
|
|
static void
|
|
|
|
test_zap_wrong_status_internal_error (socket_config_fn server_socket_config_,
|
|
|
|
socket_config_fn client_socket_config_,
|
|
|
|
void *client_socket_config_data_)
|
|
|
|
{
|
2019-03-20 16:03:06 +01:00
|
|
|
void *handler, *zap_thread, *server, *server_mon;
|
2019-03-20 12:34:47 +01:00
|
|
|
char my_endpoint[MAX_SOCKET_STRING];
|
2017-08-17 11:45:18 +02:00
|
|
|
setup_context_and_server_side (
|
2019-03-20 16:03:06 +01:00
|
|
|
&handler, &zap_thread, &server, &server_mon, my_endpoint,
|
2017-08-17 11:45:18 +02:00
|
|
|
&zap_handler_wrong_status_internal_error, server_socket_config_);
|
2019-03-20 16:03:06 +01:00
|
|
|
test_zap_unsuccessful_status_500 (my_endpoint, server, server_mon,
|
2017-08-18 13:19:07 +02:00
|
|
|
client_socket_config_,
|
|
|
|
client_socket_config_data_);
|
2019-03-20 16:03:06 +01:00
|
|
|
shutdown_context_and_server_side (zap_thread, server, server_mon, handler);
|
2019-03-20 12:34:47 +01:00
|
|
|
}
|
2017-09-18 11:48:14 +02:00
|
|
|
|
2019-03-20 12:34:47 +01:00
|
|
|
static void
|
|
|
|
test_zap_unsuccesful_no_handler_started (socket_config_fn server_socket_config_,
|
|
|
|
socket_config_fn client_socket_config_,
|
|
|
|
void *client_socket_config_data_,
|
|
|
|
void *server_socket_config_data_)
|
|
|
|
{
|
2017-10-07 18:34:18 +01:00
|
|
|
#ifdef ZMQ_ZAP_ENFORCE_DOMAIN
|
2019-03-20 16:03:06 +01:00
|
|
|
void *handler, *zap_thread, *server, *server_mon;
|
2019-03-20 12:34:47 +01:00
|
|
|
char my_endpoint[MAX_SOCKET_STRING];
|
|
|
|
// TODO this looks wrong, where will the enforce value be used?
|
|
|
|
|
2017-08-17 15:09:17 +02:00
|
|
|
// no ZAP handler
|
2018-03-22 19:27:23 +00:00
|
|
|
int enforce = 1;
|
|
|
|
setup_context_and_server_side (
|
2019-03-20 16:03:06 +01:00
|
|
|
&handler, &zap_thread, &server, &server_mon, my_endpoint, NULL,
|
2018-03-22 19:27:23 +00:00
|
|
|
server_socket_config_,
|
|
|
|
server_socket_config_data_ ? server_socket_config_data_ : &enforce);
|
2019-03-20 16:03:06 +01:00
|
|
|
test_zap_unsuccessful_no_handler (
|
|
|
|
my_endpoint, server, server_mon, ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL,
|
|
|
|
EFAULT, client_socket_config_, client_socket_config_data_);
|
|
|
|
shutdown_context_and_server_side (zap_thread, server, server_mon, handler);
|
2017-10-07 18:34:18 +01:00
|
|
|
#endif
|
2019-03-20 12:34:47 +01:00
|
|
|
}
|
2017-09-18 15:11:51 +02:00
|
|
|
|
2019-03-20 12:34:47 +01:00
|
|
|
static void
|
|
|
|
test_zap_unsuccesful_no_handler_closure (socket_config_fn server_socket_config_,
|
|
|
|
socket_config_fn client_socket_config_,
|
|
|
|
void *client_socket_config_data_,
|
|
|
|
zmq_thread_fn zap_handler_func_,
|
|
|
|
bool zap_handler_disconnected_ = false)
|
|
|
|
{
|
2019-03-20 16:03:06 +01:00
|
|
|
void *handler, *zap_thread, *server, *server_mon;
|
2019-03-20 12:34:47 +01:00
|
|
|
char my_endpoint[MAX_SOCKET_STRING];
|
2019-03-20 16:03:06 +01:00
|
|
|
setup_context_and_server_side (&handler, &zap_thread, &server, &server_mon,
|
|
|
|
my_endpoint, zap_handler_func_,
|
2019-03-20 12:34:47 +01:00
|
|
|
server_socket_config_);
|
2019-03-20 16:03:06 +01:00
|
|
|
test_zap_unsuccessful_no_handler (
|
|
|
|
my_endpoint, server, server_mon, ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL,
|
|
|
|
EPIPE, client_socket_config_, client_socket_config_data_);
|
|
|
|
shutdown_context_and_server_side (zap_thread, server, server_mon, handler,
|
|
|
|
zap_handler_disconnected_);
|
2019-03-20 12:34:47 +01:00
|
|
|
}
|
2017-09-18 17:19:36 +02:00
|
|
|
|
2019-03-20 12:34:47 +01:00
|
|
|
static void
|
|
|
|
test_zap_unsuccesful_disconnect (socket_config_fn server_socket_config_,
|
|
|
|
socket_config_fn client_socket_config_,
|
|
|
|
void *client_socket_config_data_)
|
|
|
|
{
|
|
|
|
test_zap_unsuccesful_no_handler_closure (
|
|
|
|
server_socket_config_, client_socket_config_, client_socket_config_data_,
|
|
|
|
&zap_handler_disconnect, true);
|
|
|
|
}
|
2017-09-18 17:19:36 +02:00
|
|
|
|
2019-03-20 12:34:47 +01:00
|
|
|
static void
|
|
|
|
test_zap_unsuccesful_do_not_recv (socket_config_fn server_socket_config_,
|
|
|
|
socket_config_fn client_socket_config_,
|
|
|
|
void *client_socket_config_data_)
|
|
|
|
{
|
|
|
|
test_zap_unsuccesful_no_handler_closure (
|
|
|
|
server_socket_config_, client_socket_config_, client_socket_config_data_,
|
|
|
|
&zap_handler_do_not_recv);
|
2017-08-17 11:45:18 +02:00
|
|
|
}
|
|
|
|
|
2019-03-20 12:34:47 +01:00
|
|
|
static void
|
|
|
|
test_zap_unsuccesful_do_not_send (socket_config_fn server_socket_config_,
|
|
|
|
socket_config_fn client_socket_config_,
|
|
|
|
void *client_socket_config_data_)
|
2017-08-17 11:45:18 +02:00
|
|
|
{
|
2019-03-20 12:34:47 +01:00
|
|
|
test_zap_unsuccesful_no_handler_closure (
|
|
|
|
server_socket_config_, client_socket_config_, client_socket_config_data_,
|
|
|
|
&zap_handler_do_not_send);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DEFINE_ZAP_ERROR_TESTS( \
|
|
|
|
name_, server_socket_config_, server_socket_config_data_, \
|
|
|
|
client_socket_config_, client_socket_config_data_) \
|
|
|
|
void test_zap_protocol_error_wrong_version_##name_ () \
|
|
|
|
{ \
|
|
|
|
test_zap_protocol_error_wrong_version ( \
|
|
|
|
server_socket_config_, client_socket_config_, \
|
|
|
|
client_socket_config_data_, server_socket_config_data_); \
|
|
|
|
} \
|
|
|
|
void test_zap_protocol_error_wrong_request_id_##name_ () \
|
|
|
|
{ \
|
|
|
|
test_zap_protocol_error_wrong_request_id ( \
|
|
|
|
server_socket_config_, client_socket_config_, \
|
|
|
|
client_socket_config_data_, server_socket_config_data_); \
|
|
|
|
} \
|
|
|
|
void test_zap_protocol_error_wrong_status_invalid_##name_ () \
|
|
|
|
{ \
|
|
|
|
test_zap_protocol_error_wrong_status_invalid ( \
|
|
|
|
server_socket_config_, client_socket_config_, \
|
|
|
|
client_socket_config_data_, server_socket_config_data_); \
|
|
|
|
} \
|
|
|
|
void test_zap_protocol_error_too_many_parts_##name_ () \
|
|
|
|
{ \
|
|
|
|
test_zap_protocol_error_too_many_parts ( \
|
|
|
|
server_socket_config_, client_socket_config_, \
|
|
|
|
client_socket_config_data_, server_socket_config_data_); \
|
|
|
|
} \
|
|
|
|
void test_zap_wrong_status_temporary_failure_##name_ () \
|
|
|
|
{ \
|
|
|
|
test_zap_wrong_status_temporary_failure ( \
|
|
|
|
server_socket_config_, client_socket_config_, \
|
|
|
|
client_socket_config_data_, server_socket_config_data_); \
|
|
|
|
} \
|
|
|
|
void test_zap_wrong_status_internal_error_##name_ () \
|
|
|
|
{ \
|
|
|
|
test_zap_wrong_status_internal_error (server_socket_config_, \
|
|
|
|
client_socket_config_, \
|
|
|
|
client_socket_config_data_); \
|
|
|
|
} \
|
|
|
|
void test_zap_unsuccessful_no_handler_started_##name_ () \
|
|
|
|
{ \
|
|
|
|
test_zap_unsuccesful_no_handler_started ( \
|
|
|
|
server_socket_config_, client_socket_config_, \
|
|
|
|
client_socket_config_data_, server_socket_config_data_); \
|
|
|
|
} \
|
|
|
|
void test_zap_unsuccessful_disconnect_##name_ () \
|
|
|
|
{ \
|
|
|
|
test_zap_unsuccesful_disconnect (server_socket_config_, \
|
|
|
|
client_socket_config_, \
|
|
|
|
client_socket_config_data_); \
|
|
|
|
} \
|
|
|
|
void test_zap_unsuccessful_do_not_recv_##name_ () \
|
|
|
|
{ \
|
|
|
|
test_zap_unsuccesful_do_not_recv (server_socket_config_, \
|
|
|
|
client_socket_config_, \
|
|
|
|
client_socket_config_data_); \
|
|
|
|
} \
|
|
|
|
void test_zap_unsuccessful_do_not_send_##name_ () \
|
|
|
|
{ \
|
|
|
|
test_zap_unsuccesful_do_not_send (server_socket_config_, \
|
|
|
|
client_socket_config_, \
|
|
|
|
client_socket_config_data_); \
|
|
|
|
}
|
2017-08-17 11:45:18 +02:00
|
|
|
|
2019-03-20 12:34:47 +01:00
|
|
|
DEFINE_ZAP_ERROR_TESTS (
|
|
|
|
null, &socket_config_null_server, NULL, &socket_config_null_client, NULL)
|
|
|
|
|
|
|
|
DEFINE_ZAP_ERROR_TESTS (
|
|
|
|
plain, &socket_config_plain_server, NULL, &socket_config_plain_client, NULL)
|
|
|
|
|
|
|
|
static curve_client_data_t curve_client_data = {
|
|
|
|
valid_server_public, valid_client_public, valid_client_secret};
|
|
|
|
|
|
|
|
DEFINE_ZAP_ERROR_TESTS (curve,
|
|
|
|
&socket_config_curve_server,
|
|
|
|
valid_server_secret,
|
|
|
|
&socket_config_curve_client,
|
|
|
|
&curve_client_data)
|
|
|
|
|
|
|
|
#define RUN_ZAP_ERROR_TESTS(name_) \
|
|
|
|
{ \
|
|
|
|
RUN_TEST (test_zap_protocol_error_wrong_version_##name_); \
|
|
|
|
RUN_TEST (test_zap_protocol_error_wrong_request_id_##name_); \
|
|
|
|
RUN_TEST (test_zap_protocol_error_wrong_status_invalid_##name_); \
|
|
|
|
RUN_TEST (test_zap_protocol_error_too_many_parts_##name_); \
|
|
|
|
RUN_TEST (test_zap_wrong_status_temporary_failure_##name_); \
|
|
|
|
RUN_TEST (test_zap_wrong_status_internal_error_##name_); \
|
|
|
|
RUN_TEST (test_zap_unsuccessful_no_handler_started_##name_); \
|
|
|
|
RUN_TEST (test_zap_unsuccessful_disconnect_##name_); \
|
|
|
|
RUN_TEST (test_zap_unsuccessful_do_not_recv_##name_); \
|
|
|
|
RUN_TEST (test_zap_unsuccessful_do_not_send_##name_); \
|
|
|
|
}
|
2017-08-17 12:11:14 +02:00
|
|
|
|
2019-03-20 12:34:47 +01:00
|
|
|
int main ()
|
|
|
|
{
|
|
|
|
setup_test_environment ();
|
2017-08-17 12:22:26 +02:00
|
|
|
|
2017-09-07 15:47:43 +03:00
|
|
|
if (zmq_has ("curve")) {
|
|
|
|
setup_testutil_security_curve ();
|
2019-03-20 12:34:47 +01:00
|
|
|
}
|
2017-09-07 15:47:43 +03:00
|
|
|
|
2019-03-20 12:34:47 +01:00
|
|
|
UNITY_BEGIN ();
|
|
|
|
RUN_ZAP_ERROR_TESTS (null);
|
|
|
|
RUN_ZAP_ERROR_TESTS (plain);
|
|
|
|
if (zmq_has ("curve")) {
|
|
|
|
RUN_ZAP_ERROR_TESTS (curve);
|
2017-09-07 15:47:43 +03:00
|
|
|
}
|
2019-03-20 12:34:47 +01:00
|
|
|
return UNITY_END ();
|
2017-08-17 11:45:18 +02:00
|
|
|
}
|