Commit Graph

676 Commits

Author SHA1 Message Date
sigiesec
f9af5503b4 Problem: missing test cases for zmq_poller_* functions called with invalid arguments
Solution: added test cases
2017-08-22 19:28:07 +02:00
sigiesec
9a336622fb Problem: no tests for socket-related functions passing NULL as socket
Soluton: added tests
2017-08-22 16:22:38 +02:00
Simon Giesecke
0aef54421d Problem: test_monitor is disabled on Windows
Solution: enable test
2017-08-21 12:20:37 +02:00
Simon Giesecke
82227136ea Problem: test_monitor sometimes fails due to a wrong event received, but not known which
Solution: add diagnostic output
2017-08-21 12:20:36 +02:00
Simon Giesecke
74203729bd Problem: test_zap_unsuccessful_status_500 and test_curve_security_with_bogus_client_credentials sometimes fail, particulary on slow/valgrind runs
Solutio: relax test assertion
2017-08-20 22:47:15 +02:00
sigiesec
bd0675b93f Problem: no tests for client-side events for successful handshake and authentication failure in handshake
Solution: added tests for CURVE, add emitting of client-side event in curve_client_t; add ZAP code 300/500 tests for all mechanisms; suppress sending an error message for ZAP code 300
2017-08-20 22:45:14 +02:00
Luca Boccassi
b239d99a2c Problem: test_security_gssapi does not close messages
Solution: do it to avoid leaks. Even though they are below 33 bytes so
it's all allocated on the stack, the small message size might change in
the future.
2017-08-20 11:54:49 +01:00
Luca Boccassi
cd09065c8a Problem: test_security_gssapi expects wrong event
Solution: fix it
2017-08-20 11:54:13 +01:00
Simon Giesecke
00c6962516 Problem: test failing due to too few messages sent relative to SNDHWM
Solution: relaxed assertion to accept 10% of the SNDHWM, and updated documentation accordingly
2017-08-20 11:51:09 +02:00
sigiesec
4c2acdacca Problem: wrong assumption on behavior of ZMQ_SNDHWM in test_sockopt_hwm.cpp
Solution: align assertions with specification of ZMQ_SNDHWM (actual number of enqueueable messages may be lower)
2017-08-20 11:43:13 +02:00
Luca Boccassi
90b6c102bb Problem: various unused variables warnings
Solution: use LIBZMQ_UNUSED where necessary
2017-08-19 12:18:51 +01:00
Luca Boccassi
5b1c0cd0ac Problem: test_security_gssapi fails to build
Solution: monitor new events only if DRAFT APIs are enabled, and
convert to new event types. Same for DRAFT socket options.
2017-08-18 16:56:36 +01:00
Luca Boccassi
330856daec Problem: double definition in test_security_gssapi
Solution: remove the second one to fix build failure
2017-08-18 16:28:03 +01:00
sigiesec
301f3c70c2 Problem: code duplication between curve_client_t and curve_server_t decode and encode
Solution: extracted common base class curve_mechanism_base_t
2017-08-18 11:34:22 +02:00
sigiesec
e2d3ba9c62 Problem: classification ZMQ_HANDSHAKE_FAILED_* events is coarse-grained and partially misleading
Solution: redesign ZMQ_HANDSHAKE_FAILED_* events, introduce new class of ZMQ_HANDSHAKE_FAILED_AUTH events
2017-08-18 09:17:59 +02:00
sigiesec
863a02b4a1 Problem: no ZAP tests for PLAIN mechanism
Solution: added ZAP tests for PLAIN
2017-08-17 12:22:26 +02:00
sigiesec
00816875b8 Problem: no ZAP tests for NULL mechanism
Solution: added ZAP tests for NULL
2017-08-17 12:11:14 +02:00
sigiesec
406af1ef67 Problem: ZAP tests are now generic but placed in test_security_curve.cpp
Solution: Move ZAP tests to own file test_security_zap.cpp, move common code to testutil_security.hpp
2017-08-17 11:45:18 +02:00
sigiesec
59d8060165 Problem: ZAP tests are only run with CURVE security
Solution: as a first step, parametrize mechanism configuration in CURVE tests
2017-08-17 11:10:11 +02:00
Simon Giesecke
4a18f6204c Problem: Possible buffer overruns related to metadata in various mechanisms (#2683)
* Problem: no test case with CURVE encryption and large identity

Solution: added test case (currently crashing)

* Problem: possible buffer overflow in mechanism_t::add_property

Solution: add target buffer length parameter and check the buffer is sufficiently large

* Problem: test cases accidentally excluded from build

Solution: remove #if/#endif

* Problem: possible buffer overruns related to metadata at various locations

Solution: allocate buffer large enough for actual metadata, reduce code duplication

* Problem: syntax error related to pointer type conversion

Solution: change argument type of make_command_with_basic_properties to const char *

* Problem: large metadata may cause an assertion in produce_initiate

Solution: Allow metadata of arbitrary size in produce_initiate
2017-08-15 18:42:31 +01:00
Simon Giesecke
d5e4319edc [WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680)
* Extracted connect_vanilla_socket function

* Problem: no tests for ZMTP-CURVE protocol errors

Solution: added two test cases with erroneous HELLO commands

* Problem: insufficient tests for ZMTP-CURVE protocol errors

Solution: added two test cases with erroneous HELLO command version

* Problem: test HELLO message is invalid apart from deliberate errors

Solution: create cryptographically correct HELLO message
add tweetnacl.c to test_security_curve

* Problem: nonce is incorrect, build fails with GCC

Solution: use correct non prefix

* Problem: make builds are failing

Solution: transfer CMake changes to (auto)make files

* Problem: nonce is incorrect, build fails with GCC

Solution: use correct non prefix

* Problem: make builds are failing

Solution: transfer CMake changes to (auto)make files

* Problem: no test with INITIATE command with invalid length

Solution: added test case

* Problem: code duplication between test_security_curve.cpp and curve_client.cpp

Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function

* Problem: code duplication between test_security_curve.cpp and curve_client.cpp

Solution: extracted further parts of zmq::curve_client_t into reusable functions
added missing file

* Problem: mechanism_t::add_property can be declared static

Solution: declare mechanism_t::add_property static

* Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t

Solution: add non-static member functions

* Problem: msg_t instance may be closed twice

Solution: remove offending close

* Problem: prepare_hello uses static curve_client_tools_t::produce_hello

Solution: Use non-static curve_client_tools_t::produce_hello

* Problem: no test with invalid command name where INITIATE command is expected

Solution: added test case

* Problem: make builds are failing due to curve_client_tools.hpp not being found

Solution: add curve_client_tools.hpp to list of source files

* Problem: wrong initializer order in zmq::curve_client_t

Solution: reorder

* Problem: under non-Windows systems, test fails because random_open was not called

Solution: call random_open/random_close within test

* Problem: conflict between custom function htonll and macro definition on Darwin

Solution: define htonll function only if not defined as a macro

* Problem: nullptr not defined on all platforms

Solution: replace nullptr by NULL

* Problem: libsodium builds not working

Solution: adapt compile and link file sets for libsodium builds

* Problem: Makefile.am broken

Solution: Fix syntax

* Problem: no tests for garbage encrypted cookie or content in INITIATE

Solution: added test cases

* Problem: test cases accidentally excluded from build

Solution: remove #if/#endif

* Solution: some error cases are unreachable

Problem: for the time being, added some comments without changing the code

* Added comments on hard-to-test cases
2017-08-15 15:28:24 +01:00
Simon Giesecke
a6cef4ef86 Problem: ZAP status codes != 200 do not result in an appropriate monitor event (#2665)
* Problem: missing test for status code 300, inadequate assertion for status code 500

Solution: add test, change assertion (currently test fails)

* Problem: gcc compiler error deprecated conversion from string constant

Solution: declare variable as const

* Problem: in case of ZAP handler returning a status code other than 200, no appropriate event is emitted

Solution: immediately emit event after receiving reply from ZAP handler

* Problem: endpoint address is not included in zap-reply monitor event

Solution: added functions to retrieve endpoint address in zmq::i_engine and zmq::session_base_t
removed unused code block in zmq::stream_engine_t::next_handshake_command

* Problem: wrong formatting

Solution: fix formatting

* Problem: test fails because of EPIPE

Solution: add EPIPE/ECONNRESET/ECONNAGAIN handling for more test cases
2017-08-08 13:10:20 +01:00
Simon Giesecke
834b9e4cd7 Problem: some test cases may still fail because of EPIPE/ECONNABORT/ECONNRESET (#2664)
* Problem: CI failure on Appveyor with err==ECONNRESET

Solution: ignore ECONNRESET analogous to EPIPE

* Problem: blocking test execution

Solution: added more debug output, do not wait for monitor infinitely without output
2017-08-07 17:07:37 +01:00
Jim Klimov
612d81a831 Merge pull request #2659 from bluca/fix_getrandom
Problems: test_security_curve occasionally hangs or fails due to ECONNABORTED
2017-08-07 12:36:59 +02:00
Luca Boccassi
20bbd016c1 Merge pull request #2663 from sigiesec/fix-zap-assertion
Problem: failing assertion on ZAP protocol error
2017-08-07 11:15:54 +01:00
Simon Giesecke
de82cbe4ba Problem: failing assertion on ZAP protocol error
Solution: do not assert on ZAP protocol error when connection was closed by client
2017-08-07 10:59:36 +02:00
Simon Giesecke
8842e0f0a9 Problem: occasional test failures due to messages not (yet) received in test assertion
Solution: add sleep
2017-08-07 10:35:25 +02:00
Luca Boccassi
5f6ff69f62 Problem: test_security_curve fails due to ECONNABORTED
Solution: expect that error, which can happen on very slow machines
due to a client timimng out or RST before the connection is accepted
by the server
2017-08-07 09:26:38 +01:00
Luca Boccassi
1c1f10a25a Problem: test_security_curve occasionally hangs
Solution: refactor the ZAP thread to avoid creating the socket in the
main thread and using it in the ZAP thread, and also to eliminate
races at shutdown use another inproc control socket to signal
termination to the thread
2017-08-07 09:18:37 +01:00
Luca Boccassi
14df80ae3a Problem: test_security_curve does not account for ECONNRESET
Solution: ignore ECONNRESET as with EPIPE - it can happen on very
slow machines when the engine sends data to the peer and then tries
to read from the TCP socket before the peer has read
2017-08-05 18:08:21 +01:00
Luca Boccassi
9c085381ee Problem: test_security_curve timeouts on CMake
Solution: bump timeout from 20 to 60 seconds
2017-08-04 16:25:59 +01:00
Simon Giesecke
7ba70e95e5 Problem: test failure on CI due to ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL/EPIPE problem
Solution: add workaround at another place, unify two code fragments to remove duplication
2017-08-04 16:05:20 +02:00
Simon Giesecke
aacb219acd Problem: open TODOs in test code
Solution: removed code duplication
improved global variable naming
added assertions on number of ZAP requests handled
added assertion on monitor event to test_curve_security_with_plain_client_credentials
2017-08-04 15:11:14 +02:00
Jim Klimov
e84804d4cc Merge pull request #2647 from bluca/travis_test
Problems: too many OSX travis builds, curve test uses hard-coded TCP port
2017-08-04 13:21:02 +02:00
Luca Boccassi
32085870df Merge pull request #2650 from sigiesec/connection-close-event-workaround
Problem: sporadic failure in test_curve_security_with_null_client_credentials
2017-08-04 11:48:27 +01:00
Simon Giesecke
4b847f3ff9 Problem: no tests for ZAP handler that has an invalid protocol (#2648)
* Problem: no tests for ZAP protocol errors

Solution: added first test for a bogus version number in ZAP reply

* Problem: no tests for ZAP protocol errors

Solution: added more test cases

* Problem: cannot compile without ZMQ_BUILD_DRAFT_API

Solution: conditionally compile parts that depend on draft API

* Problem: test_security_curve times out in CI

Solution: Increase timeout for this test to 20 seconds
2017-08-04 11:07:41 +01:00
Simon Giesecke
4fec4c99be Problem: sporadic failure in test_curve_security_with_null_client_credentials
Solution: add workaround for EPIPE error
2017-08-04 11:35:00 +02:00
Luca Boccassi
ccb1250fcc Problem: a curve test uses hard-coded TCP port
Solution: use the wildcard endpoint instead
2017-08-03 14:41:36 +01:00
Simon Giesecke
5d4e30eb13 Replace console output by monitoring events for curve security issues (#2645)
* Fixing #2002 one way of doing it

 * Mechanisms can implement a new method `error_detail()`
 * This error detail have three values for the moment: no_detail
 (default), protocol, encryption.
    + generic enough to make sense for all mechanisms.
    - low granularity level on information.

* Fixing #2002: implementation of the error details

The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details
as value.

* Removed Microsoft extenstion for enum member access

This was leading to compilation error under linux.

* Adaptation of CURVE test cases

* Monitoring event: changed API for detailed events

Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by:
- ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL,
- ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL,
- ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION

Adaptation of text case `security_curve`

* Removed event value comparison

This was introduced for the previous API model adaptation

* Removed the prints in std output and added missing details

`current_error_detail` was not set in every protocol error cases

* Fixed initialization of current_error_detail

* Fixed error in greeting test case

The handshake failure due to mechanism mismatch in greeting is actually
a protocol error. The error handling method consider it like so and
send a protocol handshake failure monitoring event instead of no_detail.

Fixed the test_security_curve expectation as well.

* Upgraded tests of monitoring events

The tests check the number of monitoring events received

* Problem: does not build under Linux or without ZMQ_DRAFT_API

Solution:
- properly use ZMQ_DRAFT_API conditional compilation
- use receive timeouts instead of Sleep

* Problem: duplicate definition of variable 'timeout'

Solution: merged definitions

* Problem: inconsistent timing dependencies

Solution: reduce timing dependency by using timeouts at more places

* Problem: assertion failure under Linux due to unexpected monitor event

Solution: output event type to aid debugging

* Problem: erroneous assertion code

* Problem: assertion failure with a garbage server key due to an extra third event

Solution: changed assertion to expect three events (needs to be checked)

* Problem: extra include directive to non-existent file

Solution: removed include directive

* Problem: assertion failure on appveyor for unknown reason

Solution: improve debug output

* Problem: no build with libsodium and draft api

Solution: add build configurations with libsodium and draft api

* Problem: assertion failure on CI

Solution: change assertion to reflect actual behaviour on CI (at least temporarily)

* Problem: error in condition in assertion code

* Problem: assertion failure on CI

Solution: generalize assertion to match behavior on CI

* Problem: assertion failures on CI

Solution: removed inconsistent assertion on no monitor events before flushing
improved debuggability by converting function into macro

* Problem: diverging test code for three analogous test cases with garbage key

Solution: extract common code into function

* Problem: does not build without ZMQ_BUILD_DRAFT_API

Solution: introduce dummy variable

* Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again

* Problem: EAGAIN error after handshake complete if there is no more data in inbuffer

Solution: Skip tcp_read attempt in that case

* Problem: handshaking event emitted after handshaking failed

Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking

* Include error code in debug output

* Improve debugging output: output flushed events

* Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP

* Fixed compilation without ZMQ_BUILD_DRAFT_API

* Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency

* Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency

* Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency

* Fixed assert_monitor_event (require event instead of allowing no event)
Reverted erroneous change to handshaking condition
Renamed test_wrong_key to test_garbage_key
Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE

* Better isolate test cases from each other by providing a fresh context & server for each

* Added diagnostic output

* Changed assertion to reflect actual behavior on CI

* Fixed formatting, observe maximum line length

* Fixed formatting, observe maximum line length

* Increase timeout to check if this fixes valgrind run

* Close server with close_zero_linger

* Increase timeout to check if this fixes valgrind run

* Increase timeout to check if this fixes valgrind run

* Generalize assertion to also work with valgrind

* Fixed formatting

* Add more diagnostic output

* Generalize assertion to also work with valgrind
2017-08-03 14:15:56 +01:00
Luca Boccassi
415bdbc1b9 Problem: ZMQ_BINDTODEVICE is DRAFT but not DRAFT
Solution: move definition in the DRAFT section of the header
2017-07-31 16:31:31 +01:00
Brian Russell
b963542e8f Add socket option BINDTODEVICE
Linux now supports Virtual Routing and Forwarding (VRF) as per:

https://www.kernel.org/doc/Documentation/networking/vrf.txt

In order for an application to bind or connect to a socket with an
address in a VRF, they need to first bind the socket to the VRF device:

    setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, dev, strlen(dev)+1);

Note "dev" is the VRF device, eg. VRF "blue", rather than an interface
enslaved to the VRF.

Add a new socket option, ZMQ_BINDTODEVICE, to bind a socket to a device.
In general, if a socket is bound to a device, eg. an interface, only
packets received from that particular device are processed by the socket.

If device is a VRF device, then subsequent binds/connects to that socket
use addresses in the VRF routing table.
2017-07-31 15:31:47 +01:00
Luca Boccassi
3536c4b9c4 Problem: XPUB_MANUAL subscriptions not removed on peer term
Solution: remove the pipe from the real trie when a peer disconnects.
Also add a unit test that exercises the behaviour by reconnecting
a different socket and sending a message that matches.
Fixes #2601 and introduced by #2042
2017-06-22 01:02:08 +01:00
Luca Boccassi
8e2027983a Problem: XPUB_MANUAL takes effect for the next bind
Solution: fix unit test to bind after setting the option.
2017-06-22 00:58:44 +01:00
Joe Eli McIlvain
2d83acceff Merge pull request #2596 from bluca/zap_curve
Problems: ZAP can be set up incorrectly, CURVE and GSSAPI can be used only with ZAP
2017-06-15 11:51:43 -07:00
Iban Cereijo
2c4e5364aa Problem: missing Ws2_32.lib when cross compiling
Solution: use lower case ws2_32.lib to enable cross compilation
from platforms with case-sensitive filesystems.

When cross compiling the tests with Mingw-w64, CMake cannot
locate Ws2_32.lib
2017-06-14 15:54:03 +02:00
Luca Boccassi
0ce18eac25 Problem: CURVE can no longer be used without ZAP
Solution: revert change that made ZAP mandatory.
The "Stonehouse" pattern, where CURVE is used only for encryption and
without authentication, is a valid use case so we should still
support it.
Also restore CURVE testing in the test_heartbeat.

Fixes #2594
2017-06-13 22:56:32 +01:00
Luca Boccassi
17637536b8 Problem: use-after-free in test_poller
Solution: remove server socket from poller before closing it
Fixes #2581
2017-05-18 13:10:19 +01:00
Luca Boccassi
bdc676f687 Problem: REP leaves label msgs for dead REQ in pipe
Solution: roll back the pipe if writing messages other than the
first fails in router::xsend. Roll it back also when the pipe is
terminating.
Also add test case that reproduces the memory leak when ran with
valgrind.
Fixes #2567
2017-05-17 09:18:15 +01:00
BJovke
1489fc1ac5 Revert "Problem: REP leaves label msgs for dead REQ in pipe" 2017-05-16 11:20:03 +02:00
Luca Boccassi
0999fdd885 Problem: REP leaves label msgs for dead REQ in pipe
Solution: roll back the pipe if writing messages other than the
first fails in router::xsend.
Also add test case that reproduces the memory leak when ran with
valgrind.
Fixes #2567
2017-05-10 23:44:03 +01:00