Commit efaca82b authored by Simon Giesecke's avatar Simon Giesecke

Problem: testutil_security not using unity

Solution: migrate to unity and adapt users
parent 6e072460
...@@ -62,7 +62,6 @@ const char *zmq_errno_message () ...@@ -62,7 +62,6 @@ const char *zmq_errno_message ()
#define TEST_ASSERT_ZMQ_ERRNO(condition) \ #define TEST_ASSERT_ZMQ_ERRNO(condition) \
TEST_ASSERT_MESSAGE ((condition), zmq_errno_message ()) TEST_ASSERT_MESSAGE ((condition), zmq_errno_message ())
void *ctx;
void *handler; void *handler;
void *zap_thread; void *zap_thread;
void *server; void *server;
...@@ -71,14 +70,15 @@ char my_endpoint[MAX_SOCKET_STRING]; ...@@ -71,14 +70,15 @@ char my_endpoint[MAX_SOCKET_STRING];
void setUp () void setUp ()
{ {
setup_context_and_server_side (&ctx, &handler, &zap_thread, &server, setup_test_context ();
&server_mon, my_endpoint); setup_context_and_server_side (&handler, &zap_thread, &server, &server_mon,
my_endpoint);
} }
void tearDown () void tearDown ()
{ {
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon, shutdown_context_and_server_side (zap_thread, server, server_mon, handler);
handler); teardown_test_context ();
} }
const int timeout = 250; const int timeout = 250;
...@@ -91,13 +91,12 @@ const char large_routing_id[] = "0123456789012345678901234567890123456789" ...@@ -91,13 +91,12 @@ const char large_routing_id[] = "0123456789012345678901234567890123456789"
"0123456789012345678901234567890123456789" "0123456789012345678901234567890123456789"
"012345678901234"; "012345678901234";
static void zap_handler_large_routing_id (void *ctx_) static void zap_handler_large_routing_id (void * /*unused_*/)
{ {
zap_handler_generic (ctx_, zap_ok, large_routing_id); zap_handler_generic (zap_ok, large_routing_id);
} }
void expect_new_client_curve_bounce_fail (void *ctx_, void expect_new_client_curve_bounce_fail (char *server_public_,
char *server_public_,
char *client_public_, char *client_public_,
char *client_secret_, char *client_secret_,
char *my_endpoint_, char *my_endpoint_,
...@@ -109,20 +108,18 @@ void expect_new_client_curve_bounce_fail (void *ctx_, ...@@ -109,20 +108,18 @@ void expect_new_client_curve_bounce_fail (void *ctx_,
curve_client_data_t curve_client_data = {server_public_, client_public_, curve_client_data_t curve_client_data = {server_public_, client_public_,
client_secret_}; client_secret_};
expect_new_client_bounce_fail ( expect_new_client_bounce_fail (
ctx_, my_endpoint_, server_, socket_config_curve_client, my_endpoint_, server_, socket_config_curve_client, &curve_client_data,
&curve_client_data, client_mon_, expected_client_event_, client_mon_, expected_client_event_, expected_client_value_);
expected_client_value_);
} }
void test_null_key (void *ctx_, void test_null_key (void *server_,
void *server_,
void *server_mon_, void *server_mon_,
char *my_endpoint_, char *my_endpoint_,
char *server_public_, char *server_public_,
char *client_public_, char *client_public_,
char *client_secret_) char *client_secret_)
{ {
expect_new_client_curve_bounce_fail (ctx_, server_public_, client_public_, expect_new_client_curve_bounce_fail (server_public_, client_public_,
client_secret_, my_endpoint_, server_); client_secret_, my_endpoint_, server_);
int handshake_failed_encryption_event_count = int handshake_failed_encryption_event_count =
...@@ -148,12 +145,10 @@ void test_curve_security_with_valid_credentials () ...@@ -148,12 +145,10 @@ void test_curve_security_with_valid_credentials ()
curve_client_data_t curve_client_data = { curve_client_data_t curve_client_data = {
valid_server_public, valid_client_public, valid_client_secret}; valid_server_public, valid_client_public, valid_client_secret};
void *client_mon; void *client_mon;
void *client = void *client = create_and_connect_client (
create_and_connect_client (ctx, my_endpoint, socket_config_curve_client, my_endpoint, socket_config_curve_client, &curve_client_data, &client_mon);
&curve_client_data, &client_mon);
bounce (server, client); bounce (server, client);
int rc = zmq_close (client); test_context_socket_close (client);
TEST_ASSERT_ZMQ_ERRNO (rc == 0);
int event = get_monitor_event_with_timeout (server_mon, NULL, NULL, -1); int event = get_monitor_event_with_timeout (server_mon, NULL, NULL, -1);
assert (event == ZMQ_EVENT_HANDSHAKE_SUCCEEDED); assert (event == ZMQ_EVENT_HANDSHAKE_SUCCEEDED);
...@@ -165,8 +160,7 @@ void test_curve_security_with_valid_credentials () ...@@ -165,8 +160,7 @@ void test_curve_security_with_valid_credentials ()
assert_no_more_monitor_events_with_timeout (client_mon, timeout); assert_no_more_monitor_events_with_timeout (client_mon, timeout);
rc = zmq_close (client_mon); test_context_socket_close (client_mon);
TEST_ASSERT_ZMQ_ERRNO (rc == 0);
} }
void test_curve_security_with_bogus_client_credentials () void test_curve_security_with_bogus_client_credentials ()
...@@ -177,7 +171,7 @@ void test_curve_security_with_bogus_client_credentials () ...@@ -177,7 +171,7 @@ void test_curve_security_with_bogus_client_credentials ()
zmq_curve_keypair (bogus_public, bogus_secret); zmq_curve_keypair (bogus_public, bogus_secret);
expect_new_client_curve_bounce_fail ( expect_new_client_curve_bounce_fail (
ctx, valid_server_public, bogus_public, bogus_secret, my_endpoint, server, valid_server_public, bogus_public, bogus_secret, my_endpoint, server,
NULL, ZMQ_EVENT_HANDSHAKE_FAILED_AUTH, 400); NULL, ZMQ_EVENT_HANDSHAKE_FAILED_AUTH, 400);
int server_event_count = 0; int server_event_count = 0;
...@@ -199,7 +193,7 @@ void expect_zmtp_mechanism_mismatch (void *client_, ...@@ -199,7 +193,7 @@ void expect_zmtp_mechanism_mismatch (void *client_,
int rc = zmq_connect (client_, my_endpoint_); int rc = zmq_connect (client_, my_endpoint_);
TEST_ASSERT_ZMQ_ERRNO (rc == 0); TEST_ASSERT_ZMQ_ERRNO (rc == 0);
expect_bounce_fail (server_, client_); expect_bounce_fail (server_, client_);
close_zero_linger (client_); test_context_socket_close_zero_linger (client_);
expect_monitor_event_multiple (server_mon_, expect_monitor_event_multiple (server_mon_,
ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL,
...@@ -210,16 +204,14 @@ void expect_zmtp_mechanism_mismatch (void *client_, ...@@ -210,16 +204,14 @@ void expect_zmtp_mechanism_mismatch (void *client_,
void test_curve_security_with_null_client_credentials () void test_curve_security_with_null_client_credentials ()
{ {
void *client = zmq_socket (ctx, ZMQ_DEALER); void *client = test_context_socket (ZMQ_DEALER);
TEST_ASSERT_NOT_NULL (client);
expect_zmtp_mechanism_mismatch (client, my_endpoint, server, server_mon); expect_zmtp_mechanism_mismatch (client, my_endpoint, server, server_mon);
} }
void test_curve_security_with_plain_client_credentials () void test_curve_security_with_plain_client_credentials ()
{ {
void *client = zmq_socket (ctx, ZMQ_DEALER); void *client = test_context_socket (ZMQ_DEALER);
TEST_ASSERT_NOT_NULL (client);
int rc = zmq_setsockopt (client, ZMQ_PLAIN_USERNAME, "admin", 5); int rc = zmq_setsockopt (client, ZMQ_PLAIN_USERNAME, "admin", 5);
TEST_ASSERT_ZMQ_ERRNO (rc == 0); TEST_ASSERT_ZMQ_ERRNO (rc == 0);
rc = zmq_setsockopt (client, ZMQ_PLAIN_PASSWORD, "password", 8); rc = zmq_setsockopt (client, ZMQ_PLAIN_PASSWORD, "password", 8);
...@@ -579,7 +571,7 @@ void test_null_server_key () ...@@ -579,7 +571,7 @@ void test_null_server_key ()
{ {
// Check CURVE security with a null server key // Check CURVE security with a null server key
// This will be caught by the curve_server class, not passed to ZAP // This will be caught by the curve_server class, not passed to ZAP
test_null_key (ctx, server, server_mon, my_endpoint, null_key, test_null_key (server, server_mon, my_endpoint, null_key,
valid_client_public, valid_client_secret); valid_client_public, valid_client_secret);
} }
...@@ -587,7 +579,7 @@ void test_null_client_public_key () ...@@ -587,7 +579,7 @@ void test_null_client_public_key ()
{ {
// Check CURVE security with a null client public key // Check CURVE security with a null client public key
// This will be caught by the curve_server class, not passed to ZAP // This will be caught by the curve_server class, not passed to ZAP
test_null_key (ctx, server, server_mon, my_endpoint, valid_server_public, test_null_key (server, server_mon, my_endpoint, valid_server_public,
null_key, valid_client_secret); null_key, valid_client_secret);
} }
...@@ -595,7 +587,7 @@ void test_null_client_secret_key () ...@@ -595,7 +587,7 @@ void test_null_client_secret_key ()
{ {
// Check CURVE security with a null client public key // Check CURVE security with a null client public key
// This will be caught by the curve_server class, not passed to ZAP // This will be caught by the curve_server class, not passed to ZAP
test_null_key (ctx, server, server_mon, my_endpoint, valid_server_public, test_null_key (server, server_mon, my_endpoint, valid_server_public,
valid_client_public, null_key); valid_client_public, null_key);
} }
...@@ -637,15 +629,16 @@ int main (void) ...@@ -637,15 +629,16 @@ int main (void)
// test with a large routing id (resulting in large metadata) // test with a large routing id (resulting in large metadata)
fprintf (stderr, fprintf (stderr,
"test_curve_security_with_valid_credentials (large routing id)\n"); "test_curve_security_with_valid_credentials (large routing id)\n");
setup_context_and_server_side ( setup_test_context ();
&ctx, &handler, &zap_thread, &server, &server_mon, my_endpoint, setup_context_and_server_side (&handler, &zap_thread, &server, &server_mon,
&zap_handler_large_routing_id, &socket_config_curve_server, my_endpoint, &zap_handler_large_routing_id,
&valid_server_secret, large_routing_id); &socket_config_curve_server,
&valid_server_secret, large_routing_id);
test_curve_security_with_valid_credentials (); test_curve_security_with_valid_credentials ();
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon, shutdown_context_and_server_side (zap_thread, server, server_mon, handler);
handler); teardown_test_context ();
ctx = zmq_ctx_new (); void *ctx = zmq_ctx_new ();
test_curve_security_invalid_keysize (ctx); test_curve_security_invalid_keysize (ctx);
int rc = zmq_ctx_term (ctx); int rc = zmq_ctx_term (ctx);
TEST_ASSERT_ZMQ_ERRNO (rc == 0); TEST_ASSERT_ZMQ_ERRNO (rc == 0);
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment