From 7b60e76fd9709def42ad0bbb46f3027d008b7bb1 Mon Sep 17 00:00:00 2001 From: Ladar Levison Date: Fri, 10 Mar 2017 16:52:03 -0600 Subject: Added a TLS variant of the POP network test. --- check/magma/servers/pop/pop_check.c | 37 ++++++++++++++++++++++------- check/magma/servers/pop/pop_check.h | 2 +- check/magma/servers/pop/pop_check_network.c | 32 ++++++++++++------------- 3 files changed, 46 insertions(+), 25 deletions(-) (limited to 'check/magma') diff --git a/check/magma/servers/pop/pop_check.c b/check/magma/servers/pop/pop_check.c index d70ff331..613eb2d6 100644 --- a/check/magma/servers/pop/pop_check.c +++ b/check/magma/servers/pop/pop_check.c @@ -6,22 +6,42 @@ #include "magma_check.h" -START_TEST (check_pop_network_basic_s) { +START_TEST (check_pop_network_basic_tcp_s) { log_disable(); bool_t outcome = true; - server_t *server = NULL; + server_t *tcp = NULL; stringer_t *errmsg = MANAGEDBUF(1024); - if (!(server = servers_get_by_protocol(POP, false))) { - st_sprint(errmsg, "No POP servers were configured and available for testing."); + if (status() && !(tcp = servers_get_by_protocol(POP, false))) { + st_sprint(errmsg, "No POP servers were configured to support TCP connections."); outcome = false; } - else if (status()) { - outcome = check_pop_network_basic_sthread(errmsg, server->network.port); + else if (status() && check_pop_network_basic_sthread(errmsg, tcp->network.port, false)) { + outcome = false; + } + + log_test("POP / NETWORK / BASIC / TCP / SINGLE THREADED:", errmsg); + ck_assert_msg(outcome, st_char_get(errmsg)); +} +END_TEST + +START_TEST (check_pop_network_basic_tls_s) { + + log_disable(); + bool_t outcome = true; + server_t *tls = NULL; + stringer_t *errmsg = MANAGEDBUF(1024); + + if (status() && !(tls = servers_get_by_protocol(POP, true))) { + st_sprint(errmsg, "No POP servers were configured to support TLS connections."); + outcome = false; + } + else if (status() && !check_pop_network_basic_sthread(errmsg, tls->network.port, true)) { + outcome = false; } - log_test("POP / NETWORK / BASIC / SINGLE THREADED:", errmsg); + log_test("POP / NETWORK / BASIC / TLS / SINGLE THREADED:", errmsg); ck_assert_msg(outcome, st_char_get(errmsg)); } END_TEST @@ -30,7 +50,8 @@ Suite * suite_check_pop(void) { Suite *s = suite_create("\tPOP"); - suite_check_testcase(s, "POP", "POP Network Basic/S", check_pop_network_basic_s); + suite_check_testcase(s, "POP", "POP Network Basic / TCP/S", check_pop_network_basic_tcp_s); + suite_check_testcase(s, "POP", "POP Network Basic / TLS/S", check_pop_network_basic_tls_s); return s; } diff --git a/check/magma/servers/pop/pop_check.h b/check/magma/servers/pop/pop_check.h index ba55f524..dbc09d6c 100644 --- a/check/magma/servers/pop/pop_check.h +++ b/check/magma/servers/pop/pop_check.h @@ -9,7 +9,7 @@ /// pop_check_network.c bool_t check_pop_client_read_lines_to_end(client_t *client); -bool_t check_pop_network_basic_sthread(stringer_t *errmsg, uint32_t port); +bool_t check_pop_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_t secure); /// pop_check.c Suite * suite_check_pop(void); diff --git a/check/magma/servers/pop/pop_check_network.c b/check/magma/servers/pop/pop_check_network.c index 48c1dc58..16d84fc3 100644 --- a/check/magma/servers/pop/pop_check_network.c +++ b/check/magma/servers/pop/pop_check_network.c @@ -16,20 +16,20 @@ */ bool_t check_pop_client_read_lines_to_end(client_t *client) { - // TODO: Add a timeout mechanism to client_read_line and update this function. while (client_read_line(client) > 0) { if (!st_cmp_cs_eq(&(client->line), NULLER(".\r\n"))) return true; } return false; } -bool_t check_pop_network_basic_sthread(stringer_t *errmsg, uint32_t port) { +bool_t check_pop_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_t secure) { client_t *client = NULL; // Connect the client. - if (!(client = client_connect("localhost", port)) || client_read_line(client) <= 0 || - client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("+OK"))) { + if (!(client = client_connect("localhost", port)) || (secure && client_secure(client)) || + !net_set_timeout(client->sockd, 20, 20) || client_read_line(client) <= 0 || client_status(client) != 1 || + st_cmp_cs_starts(&(client->line), NULLER("+OK"))) { st_sprint(errmsg, "Failed to connect with the POP server."); client_close(client); @@ -37,8 +37,8 @@ bool_t check_pop_network_basic_sthread(stringer_t *errmsg, uint32_t port) { } // Test the USER command. - if (client_print(client, "USER princess\r\n") <= 0 || client_read_line(client) <= 0 || - client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("+OK"))) { + else if (client_print(client, "USER princess\r\n") != 15 || client_read_line(client) <= 0 || + client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("+OK"))) { st_sprint(errmsg, "Failed to return a successful state after USER."); client_close(client); @@ -46,8 +46,8 @@ bool_t check_pop_network_basic_sthread(stringer_t *errmsg, uint32_t port) { } // Test the PASS command. - if (client_print(client, "PASS password\r\n") <= 0 || client_read_line(client) <= 0 || - client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("+OK"))) { + else if (client_print(client, "PASS password\r\n") != 15 || client_read_line(client) <= 0 || + client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("+OK"))) { st_sprint(errmsg, "Failed to return a successful state after USER."); client_close(client); @@ -55,8 +55,8 @@ bool_t check_pop_network_basic_sthread(stringer_t *errmsg, uint32_t port) { } // Test the LIST command. - if (client_print(client, "LIST\r\n") <= 0 || !check_pop_client_read_lines_to_end(client) || - client_status(client) != 1) { + else if (client_print(client, "LIST\r\n") != 6 || !check_pop_client_read_lines_to_end(client) || + client_status(client) != 1) { st_sprint(errmsg, "Failed to return a successful state after LIST."); client_close(client); @@ -64,8 +64,8 @@ bool_t check_pop_network_basic_sthread(stringer_t *errmsg, uint32_t port) { } // Test the RETR command. - if (client_print(client, "RETR 1\r\n") <= 0 || !check_pop_client_read_lines_to_end(client) || - client_status(client) != 1) { + else if (client_print(client, "RETR 1\r\n") != 8 || !check_pop_client_read_lines_to_end(client) || + client_status(client) != 1) { st_sprint(errmsg, "Failed to return a successful state after RETR."); client_close(client); @@ -73,8 +73,8 @@ bool_t check_pop_network_basic_sthread(stringer_t *errmsg, uint32_t port) { } // Test the DELE command. - if (client_print(client, "DELE 1\r\n") <= 0 || client_read_line(client) <= 0 || client_status(client) != 1 || - st_cmp_cs_starts(&(client->line), NULLER("+OK"))) { + else if (client_print(client, "DELE 1\r\n") != 8 || client_read_line(client) <= 0 || client_status(client) != 1 || + st_cmp_cs_starts(&(client->line), NULLER("+OK"))) { st_sprint(errmsg, "Failed to return a successful state after DELE."); client_close(client); @@ -82,8 +82,8 @@ bool_t check_pop_network_basic_sthread(stringer_t *errmsg, uint32_t port) { } // Test the QUIT command. - if (client_print(client, "QUIT 1\r\n") <= 0 || client_read_line(client) <= 0 || client_status(client) != 1 || - st_cmp_cs_starts(&(client->line), NULLER("+OK"))) { + else if (client_print(client, "QUIT 1\r\n") <= 0 || client_read_line(client) <= 0 || client_status(client) != 1 || + st_cmp_cs_starts(&(client->line), NULLER("+OK"))) { st_sprint(errmsg, "Failed to return a successful state after QUIT."); client_close(client); -- cgit v1.2.3