Skip to content

Commit

Permalink
Problem: no tests for cases 5 and 6 of #2711
Browse files Browse the repository at this point in the history
Solution: added tests
  • Loading branch information
sigiesec committed Sep 18, 2017
1 parent e546f92 commit 07eb193
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
48 changes: 46 additions & 2 deletions tests/test_security_zap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ static void zap_handler_disconnect (void *ctx)
zap_handler_generic (ctx, zap_disconnect);
}

static void zap_handler_do_not_recv (void *ctx)
{
zap_handler_generic (ctx, zap_do_not_recv);
}

static void zap_handler_do_not_send (void *ctx)
{
zap_handler_generic (ctx, zap_do_not_send);
}

int expect_new_client_bounce_fail_and_count_monitor_events (
void *ctx,
char *my_endpoint,
Expand Down Expand Up @@ -344,8 +354,42 @@ void test_zap_errors (socket_config_fn server_socket_config_,
0, 0,
#endif
client_socket_config_, client_socket_config_data_);
shutdown_context_and_server_side(ctx, zap_thread, server, server_mon,
handler, true);
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
handler, true);

// ZAP handler does not read request
fprintf (stderr,
"test_zap_unsuccessful ZAP handler does not read request\n");
setup_context_and_server_side (&ctx, &handler, &zap_thread, &server,
&server_mon, my_endpoint, &zap_handler_do_not_recv,
server_socket_config_);
test_zap_unsuccessful_no_handler (
ctx, my_endpoint, server, server_mon,
#ifdef ZMQ_BUILD_DRAFT_API
ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, EPIPE,
#else
0, 0,
#endif
client_socket_config_, client_socket_config_data_);
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
handler);

// ZAP handler does not send reply
fprintf (stderr,
"test_zap_unsuccessful ZAP handler does not write reply\n");
setup_context_and_server_side (
&ctx, &handler, &zap_thread, &server, &server_mon, my_endpoint,
&zap_handler_do_not_send, server_socket_config_);
test_zap_unsuccessful_no_handler (
ctx, my_endpoint, server, server_mon,
#ifdef ZMQ_BUILD_DRAFT_API
ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, EPIPE,
#else
0, 0,
#endif
client_socket_config_, client_socket_config_data_);
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
handler);
}

int main (void)
Expand Down
15 changes: 11 additions & 4 deletions tests/testutil_security.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ enum zap_protocol_t
zap_wrong_request_id,
zap_status_invalid,
zap_too_many_parts,
zap_disconnect
zap_disconnect,
zap_do_not_recv,
zap_do_not_send
};

void *zap_requests_handled;
Expand Down Expand Up @@ -182,8 +184,11 @@ void zap_handler_generic (void *ctx,
{handler, 0, ZMQ_POLLIN, 0},
};

// if ordered not to receive the request, ignore the second poll item
const int numitems = (zap_protocol == zap_do_not_recv) ? 1 : 2;

// Process ZAP requests forever
while (zmq_poll (items, 2, -1) >= 0) {
while (zmq_poll (items, numitems, -1) >= 0) {
if (items[0].revents & ZMQ_POLLIN) {
char *buf = s_recv (control);
assert (buf);
Expand Down Expand Up @@ -268,12 +273,14 @@ void zap_handler_generic (void *ctx,
if (zap_protocol == zap_too_many_parts) {
s_sendmore (handler, "");
}
s_send (handler, "");
if (zap_protocol != zap_do_not_send)
s_send (handler, "");
} else {
s_sendmore (handler, "400");
s_sendmore (handler, "Invalid client public key");
s_sendmore (handler, "");
s_send (handler, "");
if (zap_protocol != zap_do_not_send)
s_send(handler, "");
}
free (version);
free (sequence);
Expand Down

0 comments on commit 07eb193

Please sign in to comment.