Merge pull request #4031 from sigiesec/test-coverage-3

Some more test coverage for invalid IPC addresses
This commit is contained in:
Doron Somech 2020-09-05 15:03:07 +03:00 committed by GitHub
commit cbce0cbffe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 0 deletions

View File

@ -35,6 +35,7 @@
SETUP_TEARDOWN_TESTCONTEXT SETUP_TEARDOWN_TESTCONTEXT
static const char test_endpoint[] = "ipc://@tmp-tester"; static const char test_endpoint[] = "ipc://@tmp-tester";
static const char test_endpoint_empty[] = "ipc://@";
void test_roundtrip () void test_roundtrip ()
{ {
@ -56,11 +57,20 @@ void test_roundtrip ()
test_context_socket_close (sb); test_context_socket_close (sb);
} }
void test_empty_abstract_name ()
{
void *sb = test_context_socket (ZMQ_DEALER);
TEST_ASSERT_FAILURE_ERRNO (EINVAL, zmq_bind (sb, test_endpoint_empty));
test_context_socket_close (sb);
}
int main (void) int main (void)
{ {
setup_test_environment (); setup_test_environment ();
UNITY_BEGIN (); UNITY_BEGIN ();
RUN_TEST (test_roundtrip); RUN_TEST (test_roundtrip);
RUN_TEST (test_empty_abstract_name);
return UNITY_END (); return UNITY_END ();
} }

View File

@ -30,6 +30,8 @@
#include "testutil.hpp" #include "testutil.hpp"
#include "testutil_unity.hpp" #include "testutil_unity.hpp"
#include <string>
SETUP_TEARDOWN_TESTCONTEXT SETUP_TEARDOWN_TESTCONTEXT
void test_roundtrip () void test_roundtrip ()
@ -48,11 +50,32 @@ void test_roundtrip ()
test_context_socket_close (sb); test_context_socket_close (sb);
} }
static const char prefix[] = "ipc://";
void test_endpoint_too_long ()
{
std::string endpoint_too_long;
endpoint_too_long.append (prefix);
for (size_t i = 0; i < 108; ++i) {
endpoint_too_long.append ("a");
}
void *sb = test_context_socket (ZMQ_PAIR);
// TODO ENAMETOOLONG is not listed in the errors returned by zmq_bind,
// should this be EINVAL?
TEST_ASSERT_FAILURE_ERRNO (ENAMETOOLONG,
zmq_bind (sb, endpoint_too_long.data ()));
test_context_socket_close (sb);
}
int main (void) int main (void)
{ {
setup_test_environment (); setup_test_environment ();
UNITY_BEGIN (); UNITY_BEGIN ();
RUN_TEST (test_roundtrip); RUN_TEST (test_roundtrip);
RUN_TEST (test_endpoint_too_long);
return UNITY_END (); return UNITY_END ();
} }