Commit 76dfec7f authored by Luca Boccassi's avatar Luca Boccassi Committed by GitHub

Merge pull request #2755 from sigiesec/client-side-error

Problem: tests where client should receive an ERROR sometimes do not
parents 843e627b e0243dcb
...@@ -64,13 +64,15 @@ void expect_new_client_curve_bounce_fail (void *ctx, ...@@ -64,13 +64,15 @@ void expect_new_client_curve_bounce_fail (void *ctx,
char *client_secret, char *client_secret,
char *my_endpoint, char *my_endpoint,
void *server, void *server,
void **client_mon = NULL) void **client_mon = NULL,
int expected_client_event = 0,
int expected_client_value = 0)
{ {
curve_client_data_t curve_client_data = {server_public, client_public, curve_client_data_t curve_client_data = {server_public, client_public,
client_secret}; client_secret};
expect_new_client_bounce_fail (ctx, my_endpoint, server, expect_new_client_bounce_fail (
socket_config_curve_client, ctx, my_endpoint, server, socket_config_curve_client, &curve_client_data,
&curve_client_data, client_mon); client_mon, expected_client_event, expected_client_value);
} }
void test_null_key (void *ctx, void test_null_key (void *ctx,
...@@ -143,25 +145,21 @@ void test_curve_security_with_bogus_client_credentials ( ...@@ -143,25 +145,21 @@ void test_curve_security_with_bogus_client_credentials (
char bogus_secret [41]; char bogus_secret [41];
zmq_curve_keypair (bogus_public, bogus_secret); zmq_curve_keypair (bogus_public, bogus_secret);
void *client_mon;
expect_new_client_curve_bounce_fail (ctx, valid_server_public, bogus_public, expect_new_client_curve_bounce_fail (ctx, valid_server_public, bogus_public,
bogus_secret, my_endpoint, server, bogus_secret, my_endpoint, server,
&client_mon); NULL,
#ifdef ZMQ_BUILD_DRAFT_API
ZMQ_EVENT_HANDSHAKE_FAILED_AUTH, 400
#else
0, 0
#endif
);
int server_event_count = 0; int server_event_count = 0;
#ifdef ZMQ_BUILD_DRAFT_API #ifdef ZMQ_BUILD_DRAFT_API
server_event_count = expect_monitor_event_multiple ( server_event_count = expect_monitor_event_multiple (
server_mon, ZMQ_EVENT_HANDSHAKE_FAILED_AUTH, 400); server_mon, ZMQ_EVENT_HANDSHAKE_FAILED_AUTH, 400);
assert (server_event_count <= 1); assert (server_event_count <= 1);
int client_event_count = expect_monitor_event_multiple (
client_mon, ZMQ_EVENT_HANDSHAKE_FAILED_AUTH, 400, true);
// this should actually be client_event_count == 1, but this is not always
// true, see https://github.com/zeromq/libzmq/issues/2705
assert (client_event_count <= 1);
int rc = zmq_close (client_mon);
assert (rc == 0);
#endif #endif
// there may be more than one ZAP request due to repeated attempts by the client // there may be more than one ZAP request due to repeated attempts by the client
......
...@@ -82,16 +82,19 @@ int expect_new_client_bounce_fail_and_count_monitor_events ( ...@@ -82,16 +82,19 @@ int expect_new_client_bounce_fail_and_count_monitor_events (
void *socket_config_data_, void *socket_config_data_,
void **client_mon, void **client_mon,
void *server_mon, void *server_mon,
int expected_event, int expected_server_event,
int expected_err) int expected_server_value,
int expected_client_event = 0,
int expected_client_value = 0)
{ {
expect_new_client_bounce_fail (ctx, my_endpoint, server, socket_config_, expect_new_client_bounce_fail (
socket_config_data_, client_mon); ctx, my_endpoint, server, socket_config_, socket_config_data_, client_mon,
expected_client_event, expected_client_value);
int events_received = 0; int events_received = 0;
#ifdef ZMQ_BUILD_DRAFT_API #ifdef ZMQ_BUILD_DRAFT_API
events_received = events_received = expect_monitor_event_multiple (
expect_monitor_event_multiple (server_mon, expected_event, expected_err); server_mon, expected_server_event, expected_server_value);
#endif #endif
return events_received; return events_received;
...@@ -101,20 +104,23 @@ void test_zap_unsuccessful (void *ctx, ...@@ -101,20 +104,23 @@ void test_zap_unsuccessful (void *ctx,
char *my_endpoint, char *my_endpoint,
void *server, void *server,
void *server_mon, void *server_mon,
int expected_event, int expected_server_event,
int expected_err, int expected_server_value,
socket_config_fn socket_config_, socket_config_fn socket_config_,
void *socket_config_data_, void *socket_config_data_,
void **client_mon = NULL) void **client_mon = NULL,
int expected_client_event = 0,
int expected_client_value = 0)
{ {
int events_received = int server_events_received =
expect_new_client_bounce_fail_and_count_monitor_events ( expect_new_client_bounce_fail_and_count_monitor_events (
ctx, my_endpoint, server, socket_config_, socket_config_data_, ctx, my_endpoint, server, socket_config_, socket_config_data_,
client_mon, server_mon, expected_event, expected_err); client_mon, server_mon, expected_server_event, expected_server_value,
expected_client_event, expected_client_value);
// there may be more than one ZAP request due to repeated attempts by the // there may be more than one ZAP request due to repeated attempts by the
// client (actually only in case if ZAP status code 300) // client (actually only in case if ZAP status code 300)
assert (events_received == 0 assert (server_events_received == 0
|| 1 <= zmq_atomic_counter_value (zap_requests_handled)); || 1 <= zmq_atomic_counter_value (zap_requests_handled));
} }
...@@ -177,7 +183,8 @@ void test_zap_unsuccessful_status_300 (void *ctx, ...@@ -177,7 +183,8 @@ void test_zap_unsuccessful_status_300 (void *ctx,
&client_mon); &client_mon);
#ifdef ZMQ_BUILD_DRAFT_API #ifdef ZMQ_BUILD_DRAFT_API
assert_no_more_monitor_events_with_timeout (client_mon, 250); // we can use a 0 timeout here, since the client socket is already closed
assert_no_more_monitor_events_with_timeout (client_mon, 0);
int rc = zmq_close (client_mon); int rc = zmq_close (client_mon);
assert (rc == 0); assert (rc == 0);
...@@ -191,7 +198,6 @@ void test_zap_unsuccessful_status_500 (void *ctx, ...@@ -191,7 +198,6 @@ void test_zap_unsuccessful_status_500 (void *ctx,
socket_config_fn client_socket_config_, socket_config_fn client_socket_config_,
void *client_socket_config_data_) void *client_socket_config_data_)
{ {
void *client_mon;
test_zap_unsuccessful (ctx, my_endpoint, server, server_mon, test_zap_unsuccessful (ctx, my_endpoint, server, server_mon,
#ifdef ZMQ_BUILD_DRAFT_API #ifdef ZMQ_BUILD_DRAFT_API
ZMQ_EVENT_HANDSHAKE_FAILED_AUTH, 500, ZMQ_EVENT_HANDSHAKE_FAILED_AUTH, 500,
...@@ -199,20 +205,13 @@ void test_zap_unsuccessful_status_500 (void *ctx, ...@@ -199,20 +205,13 @@ void test_zap_unsuccessful_status_500 (void *ctx,
0, 0, 0, 0,
#endif #endif
client_socket_config_, client_socket_config_data_, client_socket_config_, client_socket_config_data_,
&client_mon); NULL,
#ifdef ZMQ_BUILD_DRAFT_API #ifdef ZMQ_BUILD_DRAFT_API
int events_received = 0; ZMQ_EVENT_HANDSHAKE_FAILED_AUTH, 500
events_received = expect_monitor_event_multiple ( #else
client_mon, ZMQ_EVENT_HANDSHAKE_FAILED_AUTH, 500, true); 0, 0
// this should actually be events_received == 1, but this is not always
// true, see https://github.com/zeromq/libzmq/issues/2705
assert (events_received <= 1);
int rc = zmq_close (client_mon);
assert (rc == 0);
#endif #endif
);
} }
void test_zap_errors (socket_config_fn server_socket_config_, void test_zap_errors (socket_config_fn server_socket_config_,
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment