Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
ee8b8bd2
Commit
ee8b8bd2
authored
Sep 18, 2017
by
sigiesec
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: no test for ZAP handler terminating in flight
Solution: added test & some improvements of test utils
parent
a5f94cb6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
16 deletions
+48
-16
test_security_zap.cpp
tests/test_security_zap.cpp
+21
-0
testutil_security.hpp
tests/testutil_security.hpp
+27
-16
No files found.
tests/test_security_zap.cpp
View file @
ee8b8bd2
...
@@ -59,6 +59,11 @@ static void zap_handler_too_many_parts (void *ctx)
...
@@ -59,6 +59,11 @@ static void zap_handler_too_many_parts (void *ctx)
zap_handler_generic
(
ctx
,
zap_too_many_parts
);
zap_handler_generic
(
ctx
,
zap_too_many_parts
);
}
}
static
void
zap_handler_disconnect
(
void
*
ctx
)
{
zap_handler_generic
(
ctx
,
zap_disconnect
);
}
int
expect_new_client_bounce_fail_and_count_monitor_events
(
int
expect_new_client_bounce_fail_and_count_monitor_events
(
void
*
ctx
,
void
*
ctx
,
char
*
my_endpoint
,
char
*
my_endpoint
,
...
@@ -325,6 +330,22 @@ void test_zap_errors (socket_config_fn server_socket_config_,
...
@@ -325,6 +330,22 @@ void test_zap_errors (socket_config_fn server_socket_config_,
client_socket_config_
,
client_socket_config_data_
);
client_socket_config_
,
client_socket_config_data_
);
shutdown_context_and_server_side
(
ctx
,
zap_thread
,
server
,
server_mon
,
shutdown_context_and_server_side
(
ctx
,
zap_thread
,
server
,
server_mon
,
handler
);
handler
);
// ZAP handler disconnecting on first message
fprintf
(
stderr
,
"test_zap_unsuccessful ZAP handler disconnects
\n
"
);
setup_context_and_server_side
(
&
ctx
,
&
handler
,
&
zap_thread
,
&
server
,
&
server_mon
,
my_endpoint
,
&
zap_handler_disconnect
,
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
,
true
);
}
}
int
main
(
void
)
int
main
(
void
)
...
...
tests/testutil_security.hpp
View file @
ee8b8bd2
...
@@ -153,7 +153,8 @@ enum zap_protocol_t
...
@@ -153,7 +153,8 @@ enum zap_protocol_t
zap_wrong_version
,
zap_wrong_version
,
zap_wrong_request_id
,
zap_wrong_request_id
,
zap_status_invalid
,
zap_status_invalid
,
zap_too_many_parts
zap_too_many_parts
,
zap_disconnect
};
};
void
*
zap_requests_handled
;
void
*
zap_requests_handled
;
...
@@ -196,6 +197,8 @@ void zap_handler_generic (void *ctx,
...
@@ -196,6 +197,8 @@ void zap_handler_generic (void *ctx,
char
*
version
=
s_recv
(
handler
);
char
*
version
=
s_recv
(
handler
);
if
(
!
version
)
if
(
!
version
)
break
;
// Terminating - peer's socket closed
break
;
// Terminating - peer's socket closed
if
(
zap_protocol
==
zap_disconnect
)
break
;
char
*
sequence
=
s_recv
(
handler
);
char
*
sequence
=
s_recv
(
handler
);
char
*
domain
=
s_recv
(
handler
);
char
*
domain
=
s_recv
(
handler
);
...
@@ -285,8 +288,11 @@ void zap_handler_generic (void *ctx,
...
@@ -285,8 +288,11 @@ void zap_handler_generic (void *ctx,
assert
(
rc
==
0
);
assert
(
rc
==
0
);
close_zero_linger
(
handler
);
close_zero_linger
(
handler
);
rc
=
s_send
(
control
,
"STOPPED"
);
if
(
zap_protocol
!=
zap_disconnect
)
assert
(
rc
==
7
);
{
rc
=
s_send
(
control
,
"STOPPED"
);
assert
(
rc
==
7
);
}
close_zero_linger
(
control
);
close_zero_linger
(
control
);
}
}
...
@@ -321,7 +327,7 @@ void setup_handshake_socket_monitor (void *ctx,
...
@@ -321,7 +327,7 @@ void setup_handshake_socket_monitor (void *ctx,
void
setup_context_and_server_side
(
void
setup_context_and_server_side
(
void
**
ctx
,
void
**
ctx
,
void
**
handler
,
void
**
zap_control
,
void
**
zap_thread
,
void
**
zap_thread
,
void
**
server
,
void
**
server
,
void
**
server_mon
,
void
**
server_mon
,
...
@@ -338,15 +344,15 @@ void setup_context_and_server_side (
...
@@ -338,15 +344,15 @@ void setup_context_and_server_side (
zap_requests_handled
=
zmq_atomic_counter_new
();
zap_requests_handled
=
zmq_atomic_counter_new
();
assert
(
zap_requests_handled
!=
NULL
);
assert
(
zap_requests_handled
!=
NULL
);
*
handler
=
zmq_socket
(
*
ctx
,
ZMQ_REP
);
*
zap_control
=
zmq_socket
(
*
ctx
,
ZMQ_REP
);
assert
(
*
handler
);
assert
(
*
zap_control
);
int
rc
=
zmq_bind
(
*
handler
,
"inproc://handler-control"
);
int
rc
=
zmq_bind
(
*
zap_control
,
"inproc://handler-control"
);
assert
(
rc
==
0
);
assert
(
rc
==
0
);
if
(
zap_handler_
)
{
if
(
zap_handler_
)
{
*
zap_thread
=
zmq_threadstart
(
zap_handler_
,
*
ctx
);
*
zap_thread
=
zmq_threadstart
(
zap_handler_
,
*
ctx
);
char
*
buf
=
s_recv
(
*
handler
);
char
*
buf
=
s_recv
(
*
zap_control
);
assert
(
buf
);
assert
(
buf
);
assert
(
streq
(
buf
,
"GO"
));
assert
(
streq
(
buf
,
"GO"
));
free
(
buf
);
free
(
buf
);
...
@@ -374,20 +380,24 @@ void setup_context_and_server_side (
...
@@ -374,20 +380,24 @@ void setup_context_and_server_side (
server_monitor_endpoint
);
server_monitor_endpoint
);
}
}
void
shutdown_context_and_server_side
(
void
shutdown_context_and_server_side
(
void
*
ctx
,
void
*
ctx
,
void
*
zap_thread
,
void
*
server
,
void
*
server_mon
,
void
*
handler
)
void
*
zap_thread
,
void
*
server
,
void
*
server_mon
,
void
*
zap_control
,
bool
zap_handler_stopped
=
false
)
{
{
if
(
zap_thread
)
{
if
(
zap_thread
&&
!
zap_handler_stopped
)
{
int
rc
=
s_send
(
handler
,
"STOP"
);
int
rc
=
s_send
(
zap_control
,
"STOP"
);
assert
(
rc
==
4
);
assert
(
rc
==
4
);
char
*
buf
=
s_recv
(
handler
);
char
*
buf
=
s_recv
(
zap_control
);
assert
(
buf
);
assert
(
buf
);
assert
(
streq
(
buf
,
"STOPPED"
));
assert
(
streq
(
buf
,
"STOPPED"
));
free
(
buf
);
free
(
buf
);
rc
=
zmq_unbind
(
handler
,
"inproc://handler-control"
);
rc
=
zmq_unbind
(
zap_control
,
"inproc://handler-control"
);
assert
(
rc
==
0
);
assert
(
rc
==
0
);
}
}
close_zero_linger
(
handler
);
close_zero_linger
(
zap_control
);
#ifdef ZMQ_BUILD_DRAFT_API
#ifdef ZMQ_BUILD_DRAFT_API
close_zero_linger
(
server_mon
);
close_zero_linger
(
server_mon
);
...
@@ -576,7 +586,8 @@ int expect_monitor_event_multiple (void *server_mon,
...
@@ -576,7 +586,8 @@ int expect_monitor_event_multiple (void *server_mon,
// to the peer and then tries to read the socket before the peer reads
// to the peer and then tries to read the socket before the peer reads
// ECONNABORTED happens when a client aborts a connection via RST/timeout
// ECONNABORTED happens when a client aborts a connection via RST/timeout
if
(
event
==
ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL
if
(
event
==
ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL
&&
(
err
==
EPIPE
||
err
==
ECONNRESET
||
err
==
ECONNABORTED
))
{
&&
((
err
==
EPIPE
&&
expected_err
!=
EPIPE
)
||
err
==
ECONNRESET
||
err
==
ECONNABORTED
))
{
fprintf
(
stderr
,
fprintf
(
stderr
,
"Ignored event (skipping any further events): %x (err = "
"Ignored event (skipping any further events): %x (err = "
"%i == %s)
\n
"
,
"%i == %s)
\n
"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment