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
f21116b7
Commit
f21116b7
authored
May 02, 2014
by
Martin Hurton
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1003 from hintjens/master
Added test_metadata
parents
dd6c7528
b0647431
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
172 additions
and
50 deletions
+172
-50
.gitignore
.gitignore
+1
-0
zmq_msg_gets.txt
doc/zmq_msg_gets.txt
+7
-2
curve_client.cpp
src/curve_client.cpp
+1
-2
curve_server.cpp
src/curve_server.cpp
+1
-2
gssapi_mechanism_base.cpp
src/gssapi_mechanism_base.cpp
+2
-4
gssapi_server.cpp
src/gssapi_server.cpp
+3
-0
mechanism.cpp
src/mechanism.cpp
+3
-1
plain_mechanism.cpp
src/plain_mechanism.cpp
+4
-8
stream_engine.cpp
src/stream_engine.cpp
+1
-0
Makefile.am
tests/Makefile.am
+4
-2
test_metadata.cpp
tests/test_metadata.cpp
+116
-0
test_security_null.cpp
tests/test_security_null.cpp
+29
-29
No files found.
.gitignore
View file @
f21116b7
...
...
@@ -91,6 +91,7 @@ tests/test_srcfd
tests/test_stream_disconnect
tests/test_proxy_chain
tests/test_bind_src_address
tests/test_metadata
tests/test*.log
tests/test*.trs
src/platform.hpp*
...
...
doc/zmq_msg_gets.txt
View file @
f21116b7
...
...
@@ -37,9 +37,14 @@ The requested _property_ is unknown.
EXAMPLE
-------
.
To be done
.
Getting the ZAP authenticated user id for a message:
----
zmq_msg_t frame;
zmq_msg_t msg;
zmq_msg_init (&msg);
rc = zmq_msg_recv (&msg, dealer, 0);
assert (rc != -1);
const char *user_id = zmq_msg_gets (&msg, "User-Id");
zmq_msg_close (&msg);
----
...
...
src/curve_client.cpp
View file @
f21116b7
...
...
@@ -336,8 +336,7 @@ int zmq::curve_client_t::produce_initiate (msg_t *msg_)
if
(
options
.
type
==
ZMQ_REQ
||
options
.
type
==
ZMQ_DEALER
||
options
.
type
==
ZMQ_ROUTER
)
ptr
+=
add_property
(
ptr
,
"Identity"
,
options
.
identity
,
options
.
identity_size
);
ptr
+=
add_property
(
ptr
,
"Identity"
,
options
.
identity
,
options
.
identity_size
);
const
size_t
mlen
=
ptr
-
initiate_plaintext
;
...
...
src/curve_server.cpp
View file @
f21116b7
...
...
@@ -497,8 +497,7 @@ int zmq::curve_server_t::produce_ready (msg_t *msg_)
if
(
options
.
type
==
ZMQ_REQ
||
options
.
type
==
ZMQ_DEALER
||
options
.
type
==
ZMQ_ROUTER
)
ptr
+=
add_property
(
ptr
,
"Identity"
,
options
.
identity
,
options
.
identity_size
);
ptr
+=
add_property
(
ptr
,
"Identity"
,
options
.
identity
,
options
.
identity_size
);
const
size_t
mlen
=
ptr
-
ready_plaintext
;
...
...
src/gssapi_mechanism_base.cpp
View file @
f21116b7
...
...
@@ -271,10 +271,8 @@ int zmq::gssapi_mechanism_base_t::produce_ready (msg_t *msg_)
// Add identity property
if
(
options
.
type
==
ZMQ_REQ
||
options
.
type
==
ZMQ_DEALER
||
options
.
type
==
ZMQ_ROUTER
)
{
ptr
+=
add_property
(
ptr
,
"Identity"
,
options
.
identity
,
options
.
identity_size
);
}
||
options
.
type
==
ZMQ_ROUTER
)
ptr
+=
add_property
(
ptr
,
"Identity"
,
options
.
identity
,
options
.
identity_size
);
const
size_t
command_size
=
ptr
-
command_buffer
;
const
int
rc
=
msg_
->
init_size
(
command_size
);
...
...
src/gssapi_server.cpp
View file @
f21116b7
...
...
@@ -266,6 +266,9 @@ int zmq::gssapi_server_t::receive_and_process_zap_reply ()
goto
error
;
}
// Save user id
set_user_id
(
msg
[
5
].
data
(),
msg
[
5
].
size
());
// Process metadata frame
rc
=
parse_metadata
(
static_cast
<
const
unsigned
char
*>
(
msg
[
6
].
data
()),
msg
[
6
].
size
(),
true
);
...
...
src/mechanism.cpp
View file @
f21116b7
...
...
@@ -50,6 +50,9 @@ void zmq::mechanism_t::peer_identity (msg_t *msg_)
void
zmq
::
mechanism_t
::
set_user_id
(
const
void
*
data_
,
size_t
size_
)
{
user_id
=
blob_t
(
static_cast
<
const
unsigned
char
*>
(
data_
),
size_
);
zap_properties
.
insert
(
metadata_t
::
dict_t
::
value_type
(
"User-Id"
,
std
::
string
((
char
*
)
data_
,
size_
)));
}
zmq
::
blob_t
zmq
::
mechanism_t
::
get_user_id
()
const
...
...
@@ -125,7 +128,6 @@ int zmq::mechanism_t::parse_metadata (const unsigned char *ptr_,
if
(
rc
==
-
1
)
return
-
1
;
}
if
(
zap_flag
)
zap_properties
.
insert
(
metadata_t
::
dict_t
::
value_type
(
...
...
src/plain_mechanism.cpp
View file @
f21116b7
...
...
@@ -279,10 +279,8 @@ int zmq::plain_mechanism_t::produce_initiate (msg_t *msg_) const
// Add identity property
if
(
options
.
type
==
ZMQ_REQ
||
options
.
type
==
ZMQ_DEALER
||
options
.
type
==
ZMQ_ROUTER
)
{
ptr
+=
add_property
(
ptr
,
"Identity"
,
options
.
identity
,
options
.
identity_size
);
}
||
options
.
type
==
ZMQ_ROUTER
)
ptr
+=
add_property
(
ptr
,
"Identity"
,
options
.
identity
,
options
.
identity_size
);
const
size_t
command_size
=
ptr
-
command_buffer
;
const
int
rc
=
msg_
->
init_size
(
command_size
);
...
...
@@ -327,10 +325,8 @@ int zmq::plain_mechanism_t::produce_ready (msg_t *msg_) const
// Add identity property
if
(
options
.
type
==
ZMQ_REQ
||
options
.
type
==
ZMQ_DEALER
||
options
.
type
==
ZMQ_ROUTER
)
{
ptr
+=
add_property
(
ptr
,
"Identity"
,
options
.
identity
,
options
.
identity_size
);
}
||
options
.
type
==
ZMQ_ROUTER
)
ptr
+=
add_property
(
ptr
,
"Identity"
,
options
.
identity
,
options
.
identity_size
);
const
size_t
command_size
=
ptr
-
command_buffer
;
const
int
rc
=
msg_
->
init_size
(
command_size
);
...
...
src/stream_engine.cpp
View file @
f21116b7
...
...
@@ -33,6 +33,7 @@
#include <string.h>
#include <new>
#include <sstream>
#include <iostream>
#include "stream_engine.hpp"
#include "io_thread.hpp"
...
...
tests/Makefile.am
View file @
f21116b7
...
...
@@ -14,7 +14,6 @@ noinst_PROGRAMS = test_system \
test_invalid_rep
\
test_msg_flags
\
test_connect_resolve
\
test_bind_src_address
\
test_immediate
\
test_last_endpoint
\
test_term_endpoint
\
...
...
@@ -48,7 +47,9 @@ noinst_PROGRAMS = test_system \
test_many_sockets
\
test_ipc_wildcard
\
test_diffserv
\
test_connect_rid
test_connect_rid
\
test_bind_src_address
\
test_metadata
if
!ON_MINGW
noinst_PROGRAMS
+=
test_shutdown_stress
\
...
...
@@ -116,6 +117,7 @@ test_ipc_wildcard_SOURCES = test_ipc_wildcard.cpp
test_diffserv_SOURCES
=
test_diffserv.cpp
test_connect_rid_SOURCES
=
test_connect_rid.cpp
test_bind_src_address_SOURCES
=
test_bind_src_address.cpp
test_metadata_SOURCES
=
test_metadata.cpp
if
!ON_MINGW
test_shutdown_stress_SOURCES
=
test_shutdown_stress.cpp
test_pair_ipc_SOURCES
=
test_pair_ipc.cpp testutil.hpp
...
...
tests/test_metadata.cpp
0 → 100644
View file @
f21116b7
/*
Copyright (c) 2007-2014 Contributors as noted in the AUTHORS file
This file is part of 0MQ.
0MQ is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
0MQ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "testutil.hpp"
static
void
zap_handler
(
void
*
handler
)
{
uint8_t
metadata
[]
=
{
5
,
'H'
,
'e'
,
'l'
,
'l'
,
'o'
,
0
,
0
,
0
,
5
,
'W'
,
'o'
,
'r'
,
'l'
,
'd'
};
// Process ZAP requests forever
while
(
true
)
{
char
*
version
=
s_recv
(
handler
);
if
(
!
version
)
break
;
// Terminating
char
*
sequence
=
s_recv
(
handler
);
char
*
domain
=
s_recv
(
handler
);
char
*
address
=
s_recv
(
handler
);
char
*
identity
=
s_recv
(
handler
);
char
*
mechanism
=
s_recv
(
handler
);
assert
(
streq
(
version
,
"1.0"
));
assert
(
streq
(
mechanism
,
"NULL"
));
s_sendmore
(
handler
,
version
);
s_sendmore
(
handler
,
sequence
);
if
(
streq
(
domain
,
"DOMAIN"
))
{
s_sendmore
(
handler
,
"200"
);
s_sendmore
(
handler
,
"OK"
);
s_sendmore
(
handler
,
"anonymous"
);
zmq_send
(
handler
,
metadata
,
sizeof
(
metadata
),
0
);
}
else
{
s_sendmore
(
handler
,
"400"
);
s_sendmore
(
handler
,
"BAD DOMAIN"
);
s_sendmore
(
handler
,
""
);
s_send
(
handler
,
""
);
}
free
(
version
);
free
(
sequence
);
free
(
domain
);
free
(
address
);
free
(
identity
);
free
(
mechanism
);
}
close_zero_linger
(
handler
);
}
int
main
(
void
)
{
setup_test_environment
();
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
// Spawn ZAP handler
// We create and bind ZAP socket in main thread to avoid case
// where child thread does not start up fast enough.
void
*
handler
=
zmq_socket
(
ctx
,
ZMQ_REP
);
assert
(
handler
);
int
rc
=
zmq_bind
(
handler
,
"inproc://zeromq.zap.01"
);
assert
(
rc
==
0
);
void
*
zap_thread
=
zmq_threadstart
(
&
zap_handler
,
handler
);
void
*
server
=
zmq_socket
(
ctx
,
ZMQ_DEALER
);
assert
(
server
);
void
*
client
=
zmq_socket
(
ctx
,
ZMQ_DEALER
);
assert
(
client
);
rc
=
zmq_setsockopt
(
server
,
ZMQ_ZAP_DOMAIN
,
"DOMAIN"
,
6
);
assert
(
rc
==
0
);
rc
=
zmq_bind
(
server
,
"tcp://127.0.0.1:9001"
);
assert
(
rc
==
0
);
rc
=
zmq_connect
(
client
,
"tcp://127.0.0.1:9001"
);
assert
(
rc
==
0
);
s_send
(
client
,
"This is a message"
);
zmq_msg_t
msg
;
zmq_msg_init
(
&
msg
);
rc
=
zmq_msg_recv
(
&
msg
,
server
,
0
);
assert
(
rc
!=
-
1
);
assert
(
streq
(
zmq_msg_gets
(
&
msg
,
"Hello"
),
"World"
));
assert
(
streq
(
zmq_msg_gets
(
&
msg
,
"Socket-Type"
),
"DEALER"
));
assert
(
streq
(
zmq_msg_gets
(
&
msg
,
"User-Id"
),
"anonymous"
));
zmq_msg_close
(
&
msg
);
close_zero_linger
(
client
);
close_zero_linger
(
server
);
// Shutdown
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
// Wait until ZAP handler terminates
zmq_threadclose
(
zap_thread
);
return
0
;
}
tests/test_security_null.cpp
View file @
f21116b7
...
...
@@ -78,26 +78,26 @@ int main (void)
// We bounce between a binding server and a connecting client
//
// We first test client/server with no ZAP domain
//
// Libzmq does not call our ZAP handler, the connect must succeed
//
void *server = zmq_socket (ctx, ZMQ_DEALER);
//
assert (server);
//
void *client = zmq_socket (ctx, ZMQ_DEALER);
//
assert (client);
//
rc = zmq_bind (server, "tcp://127.0.0.1:9000");
//
assert (rc == 0);
//
rc = zmq_connect (client, "tcp://127.0.0.1:9000");
//
assert (rc == 0);
//
bounce (server, client);
//
close_zero_linger (client);
//
close_zero_linger (server);
// We first test client/server with no ZAP domain
// Libzmq does not call our ZAP handler, the connect must succeed
void
*
server
=
zmq_socket
(
ctx
,
ZMQ_DEALER
);
assert
(
server
);
void
*
client
=
zmq_socket
(
ctx
,
ZMQ_DEALER
);
assert
(
client
);
rc
=
zmq_bind
(
server
,
"tcp://127.0.0.1:9000"
);
assert
(
rc
==
0
);
rc
=
zmq_connect
(
client
,
"tcp://127.0.0.1:9000"
);
assert
(
rc
==
0
);
bounce
(
server
,
client
);
close_zero_linger
(
client
);
close_zero_linger
(
server
);
// Now define a ZAP domain for the server; this enables
// authentication. We're using the wrong domain so this test
// must fail.
void
*
server
=
zmq_socket
(
ctx
,
ZMQ_DEALER
);
server
=
zmq_socket
(
ctx
,
ZMQ_DEALER
);
assert
(
server
);
void
*
client
=
zmq_socket
(
ctx
,
ZMQ_DEALER
);
client
=
zmq_socket
(
ctx
,
ZMQ_DEALER
);
assert
(
client
);
rc
=
zmq_setsockopt
(
server
,
ZMQ_ZAP_DOMAIN
,
"WRONG"
,
5
);
assert
(
rc
==
0
);
...
...
@@ -109,20 +109,20 @@ int main (void)
close_zero_linger
(
client
);
close_zero_linger
(
server
);
//
// Now use the right domain, the test must pass
//
server = zmq_socket (ctx, ZMQ_DEALER);
//
assert (server);
//
client = zmq_socket (ctx, ZMQ_DEALER);
//
assert (client);
//
rc = zmq_setsockopt (server, ZMQ_ZAP_DOMAIN, "TEST", 4);
//
assert (rc == 0);
//
rc = zmq_bind (server, "tcp://127.0.0.1:9002");
//
assert (rc == 0);
//
rc = zmq_connect (client, "tcp://127.0.0.1:9002");
//
assert (rc == 0);
//
bounce (server, client);
//
close_zero_linger (client);
//
close_zero_linger (server);
// Now use the right domain, the test must pass
server
=
zmq_socket
(
ctx
,
ZMQ_DEALER
);
assert
(
server
);
client
=
zmq_socket
(
ctx
,
ZMQ_DEALER
);
assert
(
client
);
rc
=
zmq_setsockopt
(
server
,
ZMQ_ZAP_DOMAIN
,
"TEST"
,
4
);
assert
(
rc
==
0
);
rc
=
zmq_bind
(
server
,
"tcp://127.0.0.1:9002"
);
assert
(
rc
==
0
);
rc
=
zmq_connect
(
client
,
"tcp://127.0.0.1:9002"
);
assert
(
rc
==
0
);
bounce
(
server
,
client
);
close_zero_linger
(
client
);
close_zero_linger
(
server
);
// Shutdown
rc
=
zmq_ctx_term
(
ctx
);
...
...
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