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
c6d3bc68
Commit
c6d3bc68
authored
Apr 26, 2020
by
Luca Boccassi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: ZMTP mocks duplicated across tests
Solution: define buffers in common header
parent
4f35d1af
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
42 deletions
+47
-42
test_heartbeats.cpp
tests/test_heartbeats.cpp
+10
-15
test_mock_pub_sub.cpp
tests/test_mock_pub_sub.cpp
+10
-16
test_security_curve.cpp
tests/test_security_curve.cpp
+6
-11
testutil.hpp
tests/testutil.hpp
+21
-0
No files found.
tests/test_heartbeats.cpp
View file @
c6d3bc68
...
@@ -91,29 +91,24 @@ static void recv_with_retry (raw_socket fd_, char *buffer_, int bytes_)
...
@@ -91,29 +91,24 @@ static void recv_with_retry (raw_socket fd_, char *buffer_, int bytes_)
static
void
mock_handshake
(
raw_socket
fd_
,
int
mock_ping_
)
static
void
mock_handshake
(
raw_socket
fd_
,
int
mock_ping_
)
{
{
const
uint8_t
zmtp_greeting
[
33
]
=
{
0xff
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0x7f
,
3
,
0
,
'N'
,
'U'
,
'L'
,
'L'
,
0
};
char
buffer
[
128
];
char
buffer
[
128
];
memset
(
buffer
,
0
,
sizeof
(
buffer
));
memset
(
buffer
,
0
,
sizeof
(
buffer
));
memcpy
(
buffer
,
zmtp_greeting
,
sizeof
(
zmtp_greeting
));
memcpy
(
buffer
,
zmtp_greeting
_null
,
sizeof
(
zmtp_greeting_null
));
int
rc
=
TEST_ASSERT_SUCCESS_RAW_ERRNO
(
send
(
fd_
,
buffer
,
64
,
0
));
int
rc
=
TEST_ASSERT_SUCCESS_RAW_ERRNO
(
TEST_ASSERT_EQUAL_INT
(
64
,
rc
);
send
(
fd_
,
buffer
,
sizeof
(
zmtp_greeting_null
),
0
));
TEST_ASSERT_EQUAL_INT
(
sizeof
(
zmtp_greeting_null
),
rc
);
recv_with_retry
(
fd_
,
buffer
,
64
);
recv_with_retry
(
fd_
,
buffer
,
sizeof
(
zmtp_greeting_null
));
const
uint8_t
zmtp_ready
[
43
]
=
{
4
,
41
,
5
,
'R'
,
'E'
,
'A'
,
'D'
,
'Y'
,
11
,
'S'
,
'o'
,
'c'
,
'k'
,
'e'
,
't'
,
'-'
,
'T'
,
'y'
,
'p'
,
'e'
,
0
,
0
,
0
,
6
,
'D'
,
'E'
,
'A'
,
'L'
,
'E'
,
'R'
,
8
,
'I'
,
'd'
,
'e'
,
'n'
,
't'
,
'i'
,
't'
,
'y'
,
0
,
0
,
0
,
0
};
memset
(
buffer
,
0
,
sizeof
(
buffer
));
memset
(
buffer
,
0
,
sizeof
(
buffer
));
memcpy
(
buffer
,
zmtp_ready
,
43
);
memcpy
(
buffer
,
zmtp_ready_dealer
,
sizeof
(
zmtp_ready_dealer
));
rc
=
TEST_ASSERT_SUCCESS_RAW_ERRNO
(
send
(
fd_
,
buffer
,
43
,
0
));
rc
=
TEST_ASSERT_SUCCESS_RAW_ERRNO
(
TEST_ASSERT_EQUAL_INT
(
43
,
rc
);
send
(
fd_
,
buffer
,
sizeof
(
zmtp_ready_dealer
),
0
));
TEST_ASSERT_EQUAL_INT
(
sizeof
(
zmtp_ready_dealer
),
rc
);
// greeting
// greeting
recv_with_retry
(
fd_
,
buffer
,
43
);
recv_with_retry
(
fd_
,
buffer
,
sizeof
(
zmtp_ready_dealer
)
);
if
(
mock_ping_
)
{
if
(
mock_ping_
)
{
// test PING context - should be replicated in the PONG
// test PING context - should be replicated in the PONG
...
...
tests/test_mock_pub_sub.cpp
View file @
c6d3bc68
...
@@ -72,11 +72,9 @@ static void recv_with_retry (fd_t fd_, char *buffer_, int bytes_)
...
@@ -72,11 +72,9 @@ static void recv_with_retry (fd_t fd_, char *buffer_, int bytes_)
static
void
mock_handshake
(
fd_t
fd_
,
bool
sub_command
,
bool
mock_pub
)
static
void
mock_handshake
(
fd_t
fd_
,
bool
sub_command
,
bool
mock_pub
)
{
{
const
uint8_t
zmtp_greeting
[
33
]
=
{
0xff
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0x7f
,
3
,
0
,
'N'
,
'U'
,
'L'
,
'L'
,
0
};
char
buffer
[
128
];
char
buffer
[
128
];
memset
(
buffer
,
0
,
sizeof
(
buffer
));
memset
(
buffer
,
0
,
sizeof
(
buffer
));
memcpy
(
buffer
,
zmtp_greeting
,
sizeof
(
zmtp_greeting
));
memcpy
(
buffer
,
zmtp_greeting
_null
,
sizeof
(
zmtp_greeting_null
));
// Mock ZMTP 3.1 which uses commands
// Mock ZMTP 3.1 which uses commands
if
(
sub_command
)
{
if
(
sub_command
)
{
...
@@ -88,24 +86,20 @@ static void mock_handshake (fd_t fd_, bool sub_command, bool mock_pub)
...
@@ -88,24 +86,20 @@ static void mock_handshake (fd_t fd_, bool sub_command, bool mock_pub)
recv_with_retry
(
fd_
,
buffer
,
64
);
recv_with_retry
(
fd_
,
buffer
,
64
);
if
(
!
mock_pub
)
{
if
(
!
mock_pub
)
{
const
uint8_t
zmtp_ready
[
27
]
=
{
rc
=
TEST_ASSERT_SUCCESS_RAW_ERRNO
(
send
(
4
,
25
,
5
,
'R'
,
'E'
,
'A'
,
'D'
,
'Y'
,
11
,
'S'
,
'o'
,
'c'
,
'k'
,
'e'
,
fd_
,
(
const
char
*
)
zmtp_ready_sub
,
sizeof
(
zmtp_ready_sub
),
0
));
't'
,
'-'
,
'T'
,
'y'
,
'p'
,
'e'
,
0
,
0
,
0
,
3
,
'S'
,
'U'
,
'B'
};
TEST_ASSERT_EQUAL_INT
(
sizeof
(
zmtp_ready_sub
),
rc
);
rc
=
TEST_ASSERT_SUCCESS_RAW_ERRNO
(
send
(
fd_
,
(
const
char
*
)
zmtp_ready
,
27
,
0
));
TEST_ASSERT_EQUAL_INT
(
27
,
rc
);
}
else
{
}
else
{
const
uint8_t
zmtp_ready
[
28
]
=
{
rc
=
TEST_ASSERT_SUCCESS_RAW_ERRNO
(
send
(
4
,
26
,
5
,
'R'
,
'E'
,
'A'
,
'D'
,
'Y'
,
11
,
'S'
,
'o'
,
'c'
,
'k'
,
'e'
,
fd_
,
(
const
char
*
)
zmtp_ready_xpub
,
sizeof
(
zmtp_ready_xpub
),
0
));
't'
,
'-'
,
'T'
,
'y'
,
'p'
,
'e'
,
0
,
0
,
0
,
4
,
'X'
,
'P'
,
'U'
,
'B'
};
TEST_ASSERT_EQUAL_INT
(
sizeof
(
zmtp_ready_xpub
),
rc
);
rc
=
TEST_ASSERT_SUCCESS_RAW_ERRNO
(
send
(
fd_
,
(
const
char
*
)
zmtp_ready
,
28
,
0
));
TEST_ASSERT_EQUAL_INT
(
28
,
rc
);
}
}
// greeting - XPUB has one extra byte
// greeting - XPUB has one extra byte
memset
(
buffer
,
0
,
sizeof
(
buffer
));
memset
(
buffer
,
0
,
sizeof
(
buffer
));
recv_with_retry
(
fd_
,
buffer
,
mock_pub
?
27
:
28
);
recv_with_retry
(
fd_
,
buffer
,
mock_pub
?
sizeof
(
zmtp_ready_sub
)
:
sizeof
(
zmtp_ready_xpub
));
}
}
static
void
prep_server_socket
(
void
**
server_out_
,
static
void
prep_server_socket
(
void
**
server_out_
,
...
...
tests/test_security_curve.cpp
View file @
c6d3bc68
...
@@ -242,21 +242,16 @@ template <size_t N> void send (fd_t fd_, const char (&data_)[N])
...
@@ -242,21 +242,16 @@ template <size_t N> void send (fd_t fd_, const char (&data_)[N])
send_all
(
fd_
,
data_
,
N
-
1
);
send_all
(
fd_
,
data_
,
N
-
1
);
}
}
void
send_greeting
(
fd_t
s_
)
template
<
size_t
N
>
void
send
(
fd_t
fd_
,
const
uint8_t
(
&
data_
)[
N
]
)
{
{
send
(
s_
,
"
\xff\0\0\0\0\0\0\0\0\x7f
"
);
// signature
send_all
(
fd_
,
reinterpret_cast
<
const
char
*>
(
&
data_
),
N
);
send
(
s_
,
"
\x03\x00
"
);
// version 3.0
send
(
s_
,
"CURVE
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
"
);
// mechanism CURVE
send
(
s_
,
"
\0
"
);
// as-server == false
send
(
s_
,
"
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
"
);
}
}
void
test_curve_security_invalid_hello_wrong_length
()
void
test_curve_security_invalid_hello_wrong_length
()
{
{
fd_t
s
=
connect_socket
(
my_endpoint
);
fd_t
s
=
connect_socket
(
my_endpoint
);
// send GREETING
send
(
s
,
zmtp_greeting_curve
);
send_greeting
(
s
);
// send CURVE HELLO of wrong size
// send CURVE HELLO of wrong size
send
(
s
,
"
\x04\x06\x05
HELLO"
);
send
(
s
,
"
\x04\x06\x05
HELLO"
);
...
@@ -322,7 +317,7 @@ void test_curve_security_invalid_hello_command_name ()
...
@@ -322,7 +317,7 @@ void test_curve_security_invalid_hello_command_name ()
{
{
fd_t
s
=
connect_socket
(
my_endpoint
);
fd_t
s
=
connect_socket
(
my_endpoint
);
send
_greeting
(
s
);
send
(
s
,
zmtp_greeting_curve
);
zmq
::
curve_client_tools_t
tools
=
make_curve_client_tools
();
zmq
::
curve_client_tools_t
tools
=
make_curve_client_tools
();
...
@@ -344,7 +339,7 @@ void test_curve_security_invalid_hello_version ()
...
@@ -344,7 +339,7 @@ void test_curve_security_invalid_hello_version ()
{
{
fd_t
s
=
connect_socket
(
my_endpoint
);
fd_t
s
=
connect_socket
(
my_endpoint
);
send
_greeting
(
s
);
send
(
s
,
zmtp_greeting_curve
);
zmq
::
curve_client_tools_t
tools
=
make_curve_client_tools
();
zmq
::
curve_client_tools_t
tools
=
make_curve_client_tools
();
...
@@ -396,7 +391,7 @@ fd_t connect_exchange_greeting_and_send_hello (
...
@@ -396,7 +391,7 @@ fd_t connect_exchange_greeting_and_send_hello (
{
{
fd_t
s
=
connect_socket
(
my_endpoint_
);
fd_t
s
=
connect_socket
(
my_endpoint_
);
send
_greeting
(
s
);
send
(
s
,
zmtp_greeting_curve
);
recv_greeting
(
s
);
recv_greeting
(
s
);
// send valid CURVE HELLO
// send valid CURVE HELLO
...
...
tests/testutil.hpp
View file @
c6d3bc68
...
@@ -65,6 +65,27 @@
...
@@ -65,6 +65,27 @@
#define ENDPOINT_5 "udp://127.0.0.1:5560"
#define ENDPOINT_5 "udp://127.0.0.1:5560"
#define PORT_6 5561
#define PORT_6 5561
// For tests that mock ZMTP
const
uint8_t
zmtp_greeting_null
[
64
]
=
{
0xff
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0x7f
,
3
,
0
,
'N'
,
'U'
,
'L'
,
'L'
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
const
uint8_t
zmtp_greeting_curve
[
64
]
=
{
0xff
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0x7f
,
3
,
0
,
'C'
,
'U'
,
'R'
,
'V'
,
'E'
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
const
uint8_t
zmtp_ready_dealer
[
43
]
=
{
4
,
41
,
5
,
'R'
,
'E'
,
'A'
,
'D'
,
'Y'
,
11
,
'S'
,
'o'
,
'c'
,
'k'
,
'e'
,
't'
,
'-'
,
'T'
,
'y'
,
'p'
,
'e'
,
0
,
0
,
0
,
6
,
'D'
,
'E'
,
'A'
,
'L'
,
'E'
,
'R'
,
8
,
'I'
,
'd'
,
'e'
,
'n'
,
't'
,
'i'
,
't'
,
'y'
,
0
,
0
,
0
,
0
};
const
uint8_t
zmtp_ready_xpub
[
28
]
=
{
4
,
26
,
5
,
'R'
,
'E'
,
'A'
,
'D'
,
'Y'
,
11
,
'S'
,
'o'
,
'c'
,
'k'
,
'e'
,
't'
,
'-'
,
'T'
,
'y'
,
'p'
,
'e'
,
0
,
0
,
0
,
4
,
'X'
,
'P'
,
'U'
,
'B'
};
const
uint8_t
zmtp_ready_sub
[
27
]
=
{
4
,
25
,
5
,
'R'
,
'E'
,
'A'
,
'D'
,
'Y'
,
11
,
'S'
,
'o'
,
'c'
,
'k'
,
'e'
,
't'
,
'-'
,
'T'
,
'y'
,
'p'
,
'e'
,
0
,
0
,
0
,
3
,
'S'
,
'U'
,
'B'
};
#undef NDEBUG
#undef NDEBUG
// duplicated from fd.hpp
// duplicated from fd.hpp
...
...
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