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
34999d50
Commit
34999d50
authored
Mar 24, 2019
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: s_send(more) can be replaced by safer send_string_expect_success
Solution: remove s_send(more) and replace all uses
parent
af4fa22f
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
65 additions
and
79 deletions
+65
-79
test_metadata.cpp
tests/test_metadata.cpp
+10
-10
test_proxy.cpp
tests/test_proxy.cpp
+1
-1
test_proxy_single_socket.cpp
tests/test_proxy_single_socket.cpp
+1
-2
test_proxy_terminate.cpp
tests/test_proxy_terminate.cpp
+1
-2
test_scatter_gather.cpp
tests/test_scatter_gather.cpp
+2
-1
test_security_gssapi.cpp
tests/test_security_gssapi.cpp
+10
-10
test_security_null.cpp
tests/test_security_null.cpp
+10
-10
test_security_plain.cpp
tests/test_security_plain.cpp
+11
-10
testutil.cpp
tests/testutil.cpp
+0
-12
testutil.hpp
tests/testutil.hpp
+0
-6
testutil_security.cpp
tests/testutil_security.cpp
+19
-15
No files found.
tests/test_metadata.cpp
View file @
34999d50
...
...
@@ -61,18 +61,18 @@ static void zap_handler (void *handler_)
TEST_ASSERT_EQUAL_STRING
(
"1.0"
,
version
);
TEST_ASSERT_EQUAL_STRING
(
"NULL"
,
mechanism
);
s
_sendmore
(
handler_
,
version
);
s
_sendmore
(
handler_
,
sequence
);
s
end_string_expect_success
(
handler_
,
version
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
handler_
,
sequence
,
ZMQ_SNDMORE
);
if
(
streq
(
domain
,
"DOMAIN"
))
{
s
_sendmore
(
handler_
,
"200"
);
s
_sendmore
(
handler_
,
"OK"
);
s
_sendmore
(
handler_
,
"anonymous"
);
s
end_string_expect_success
(
handler_
,
"200"
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
handler_
,
"OK"
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
handler_
,
"anonymous"
,
ZMQ_SNDMORE
);
zmq_send
(
handler_
,
metadata
,
sizeof
(
metadata
),
0
);
}
else
{
s
_sendmore
(
handler_
,
"400"
);
s
_sendmore
(
handler_
,
"BAD DOMAIN"
);
s
_sendmore
(
handler_
,
""
);
s
_send
(
handler_
,
""
);
s
end_string_expect_success
(
handler_
,
"400"
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
handler_
,
"BAD DOMAIN"
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
handler_
,
""
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
handler_
,
""
,
0
);
}
free
(
version
);
free
(
sequence
);
...
...
@@ -104,7 +104,7 @@ void test_metadata ()
bind_loopback_ipv4
(
server
,
my_endpoint
,
sizeof
(
my_endpoint
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
client
,
my_endpoint
));
s
_send
(
client
,
"This is a message"
);
s
end_string_expect_success
(
client
,
"This is a message"
,
0
);
zmq_msg_t
msg
;
zmq_msg_init
(
&
msg
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_recv
(
&
msg
,
server
,
0
));
...
...
tests/test_proxy.cpp
View file @
34999d50
...
...
@@ -234,7 +234,7 @@ void server_task (void * /*unused_*/)
}
for
(
int
i
=
0
;
i
<
QT_CLIENTS
;
++
i
)
{
TEST_ASSERT_SUCCESS_ERRNO
(
s_send
(
endpoint_receivers
[
i
],
my_endpoint
)
);
send_string_expect_success
(
endpoint_receivers
[
i
],
my_endpoint
,
0
);
}
// Connect backend to frontend via a proxy
...
...
tests/test_proxy_single_socket.cpp
View file @
34999d50
...
...
@@ -48,8 +48,7 @@ void server_task (void * /*unused_*/)
void
*
control
=
zmq_socket
(
get_test_context
(),
ZMQ_REQ
);
TEST_ASSERT_NOT_NULL
(
control
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
control
,
"inproc://control"
));
TEST_ASSERT_GREATER_THAN_INT
(
0
,
TEST_ASSERT_SUCCESS_ERRNO
(
s_send
(
control
,
my_endpoint
)));
send_string_expect_success
(
control
,
my_endpoint
,
0
);
// Use rep as both frontend and backend
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_proxy_steerable
(
rep
,
rep
,
NULL
,
control
));
...
...
tests/test_proxy_terminate.cpp
View file @
34999d50
...
...
@@ -57,8 +57,7 @@ void server_task (void * /*unused_*/)
void
*
control
=
zmq_socket
(
get_test_context
(),
ZMQ_REQ
);
TEST_ASSERT_NOT_NULL
(
control
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
control
,
"inproc://control"
));
TEST_ASSERT_GREATER_THAN_INT
(
0
,
TEST_ASSERT_SUCCESS_ERRNO
(
s_send
(
control
,
my_endpoint
)));
send_string_expect_success
(
control
,
my_endpoint
,
0
);
// Connect backend to frontend via a proxy
TEST_ASSERT_SUCCESS_ERRNO
(
...
...
tests/test_scatter_gather.cpp
View file @
34999d50
...
...
@@ -44,7 +44,8 @@ void test_scatter_gather_multipart_fails ()
zmq_connect
(
gather
,
"inproc://test-scatter-gather"
));
// Should fail, multipart is not supported
TEST_ASSERT_FAILURE_ERRNO
(
EINVAL
,
s_sendmore
(
scatter
,
"1"
));
TEST_ASSERT_FAILURE_ERRNO
(
EINVAL
,
zmq_send_const
(
scatter
,
"1"
,
1
,
ZMQ_SNDMORE
));
test_context_socket_close
(
scatter
);
test_context_socket_close
(
gather
);
...
...
tests/test_security_gssapi.cpp
View file @
34999d50
...
...
@@ -82,20 +82,20 @@ static void zap_handler (void *handler_)
TEST_ASSERT_EQUAL_STRING
(
"1.0"
,
version
);
TEST_ASSERT_EQUAL_STRING
(
"GSSAPI"
,
mechanism
);
s
_sendmore
(
handler_
,
version
);
s
_sendmore
(
handler_
,
sequence
);
s
end_string_expect_success
(
handler_
,
version
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
handler_
,
sequence
,
ZMQ_SNDMORE
);
if
(
!
zap_deny_all
)
{
s
_sendmore
(
handler_
,
"200"
);
s
_sendmore
(
handler_
,
"OK"
);
s
_sendmore
(
handler_
,
"anonymous"
);
s
_send
(
handler_
,
""
);
s
end_string_expect_success
(
handler_
,
"200"
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
handler_
,
"OK"
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
handler_
,
"anonymous"
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
handler_
,
""
,
0
);
//fprintf (stderr, "ALLOW %s\n", principal);
}
else
{
s
_sendmore
(
handler_
,
"400"
);
s
_sendmore
(
handler_
,
"Denied"
);
s
_sendmore
(
handler_
,
""
);
s
_send
(
handler_
,
""
);
s
end_string_expect_success
(
handler_
,
"400"
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
handler_
,
"Denied"
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
handler_
,
""
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
handler_
,
""
,
0
);
//fprintf (stderr, "DENY %s\n", principal);
}
free
(
version
);
...
...
tests/test_security_null.cpp
View file @
34999d50
...
...
@@ -61,18 +61,18 @@ static void zap_handler (void *handler_)
TEST_ASSERT_EQUAL_STRING
(
"1.0"
,
version
);
TEST_ASSERT_EQUAL_STRING
(
"NULL"
,
mechanism
);
s
_sendmore
(
handler_
,
version
);
s
_sendmore
(
handler_
,
sequence
);
s
end_string_expect_success
(
handler_
,
version
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
handler_
,
sequence
,
ZMQ_SNDMORE
);
if
(
streq
(
domain
,
"TEST"
))
{
s
_sendmore
(
handler_
,
"200"
);
s
_sendmore
(
handler_
,
"OK"
);
s
_sendmore
(
handler_
,
"anonymous"
);
s
_send
(
handler_
,
""
);
s
end_string_expect_success
(
handler_
,
"200"
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
handler_
,
"OK"
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
handler_
,
"anonymous"
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
handler_
,
""
,
0
);
}
else
{
s
_sendmore
(
handler_
,
"400"
);
s
_sendmore
(
handler_
,
"BAD DOMAIN"
);
s
_sendmore
(
handler_
,
""
);
s
_send
(
handler_
,
""
);
s
end_string_expect_success
(
handler_
,
"400"
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
handler_
,
"BAD DOMAIN"
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
handler_
,
""
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
handler_
,
""
,
0
);
}
free
(
version
);
free
(
sequence
);
...
...
tests/test_security_plain.cpp
View file @
34999d50
...
...
@@ -64,18 +64,19 @@ static void zap_handler (void *zap_)
TEST_ASSERT_EQUAL_STRING
(
"PLAIN"
,
mechanism
);
TEST_ASSERT_EQUAL_STRING
(
"IDENT"
,
routing_id
);
s
_sendmore
(
zap_
,
version
);
s
_sendmore
(
zap_
,
sequence
);
s
end_string_expect_success
(
zap_
,
version
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
zap_
,
sequence
,
ZMQ_SNDMORE
);
if
(
streq
(
username
,
"admin"
)
&&
streq
(
password
,
"password"
))
{
s
_sendmore
(
zap_
,
"200"
);
s
_sendmore
(
zap_
,
"OK"
);
s
_sendmore
(
zap_
,
"anonymous"
);
s
_send
(
zap_
,
""
);
s
end_string_expect_success
(
zap_
,
"200"
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
zap_
,
"OK"
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
zap_
,
"anonymous"
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
zap_
,
""
,
0
);
}
else
{
s_sendmore
(
zap_
,
"400"
);
s_sendmore
(
zap_
,
"Invalid username or password"
);
s_sendmore
(
zap_
,
""
);
s_send
(
zap_
,
""
);
send_string_expect_success
(
zap_
,
"400"
,
ZMQ_SNDMORE
);
send_string_expect_success
(
zap_
,
"Invalid username or password"
,
ZMQ_SNDMORE
);
send_string_expect_success
(
zap_
,
""
,
ZMQ_SNDMORE
);
send_string_expect_success
(
zap_
,
""
,
0
);
}
free
(
version
);
free
(
sequence
);
...
...
tests/testutil.cpp
View file @
34999d50
...
...
@@ -149,18 +149,6 @@ char *s_recv (void *socket_)
return
strdup
(
buffer
);
}
int
s_send
(
void
*
socket_
,
const
char
*
string_
)
{
int
size
=
zmq_send
(
socket_
,
string_
,
strlen
(
string_
),
0
);
return
size
;
}
int
s_sendmore
(
void
*
socket_
,
const
char
*
string_
)
{
int
size
=
zmq_send
(
socket_
,
string_
,
strlen
(
string_
),
ZMQ_SNDMORE
);
return
size
;
}
void
s_send_seq
(
void
*
socket_
,
...)
{
va_list
ap
;
...
...
tests/testutil.hpp
View file @
34999d50
...
...
@@ -111,12 +111,6 @@ void expect_bounce_fail (void *server_, void *client_);
// is being terminated.
char
*
s_recv
(
void
*
socket_
);
// Convert C string to 0MQ string and send to socket
int
s_send
(
void
*
socket_
,
const
char
*
string_
);
// Sends string as 0MQ string, as multipart non-terminal
int
s_sendmore
(
void
*
socket_
,
const
char
*
string_
);
bool
streq
(
const
char
*
lhs
,
const
char
*
rhs
);
bool
strneq
(
const
char
*
lhs
,
const
char
*
rhs
);
...
...
tests/testutil_security.cpp
View file @
34999d50
...
...
@@ -203,12 +203,15 @@ void zap_handler_generic (zap_protocol_t zap_protocol_,
TEST_ASSERT_EQUAL_STRING
(
"1.0"
,
version
);
TEST_ASSERT_EQUAL_STRING
(
expected_routing_id_
,
routing_id
);
s_sendmore
(
handler
,
zap_protocol_
==
zap_wrong_version
?
"invalid_version"
:
version
);
s_sendmore
(
handler
,
zap_protocol_
==
zap_wrong_request_id
?
"invalid_request_id"
:
sequence
);
send_string_expect_success
(
handler
,
zap_protocol_
==
zap_wrong_version
?
"invalid_version"
:
version
,
ZMQ_SNDMORE
);
send_string_expect_success
(
handler
,
zap_protocol_
==
zap_wrong_request_id
?
"invalid_request_id"
:
sequence
,
ZMQ_SNDMORE
);
if
(
authentication_succeeded
)
{
const
char
*
status_code
;
...
...
@@ -225,20 +228,21 @@ void zap_handler_generic (zap_protocol_t zap_protocol_,
default:
status_code
=
"200"
;
}
s
_sendmore
(
handler
,
status_code
);
s
_sendmore
(
handler
,
"OK"
);
s
_sendmore
(
handler
,
"anonymous"
);
s
end_string_expect_success
(
handler
,
status_code
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
handler
,
"OK"
,
ZMQ_SNDMORE
);
s
end_string_expect_success
(
handler
,
"anonymous"
,
ZMQ_SNDMORE
);
if
(
zap_protocol_
==
zap_too_many_parts
)
{
s
_sendmore
(
handler
,
""
);
s
end_string_expect_success
(
handler
,
""
,
ZMQ_SNDMORE
);
}
if
(
zap_protocol_
!=
zap_do_not_send
)
s
_send
(
handler
,
""
);
s
end_string_expect_success
(
handler
,
""
,
0
);
}
else
{
s_sendmore
(
handler
,
"400"
);
s_sendmore
(
handler
,
"Invalid client public key"
);
s_sendmore
(
handler
,
""
);
send_string_expect_success
(
handler
,
"400"
,
ZMQ_SNDMORE
);
send_string_expect_success
(
handler
,
"Invalid client public key"
,
ZMQ_SNDMORE
);
send_string_expect_success
(
handler
,
""
,
ZMQ_SNDMORE
);
if
(
zap_protocol_
!=
zap_do_not_send
)
s
_send
(
handler
,
""
);
s
end_string_expect_success
(
handler
,
""
,
0
);
}
free
(
version
);
free
(
sequence
);
...
...
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