Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/lavabit/magma.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLadar Levison <ladar@lavabit.com>2017-03-11 01:57:32 +0300
committerLadar Levison <ladar@lavabit.com>2017-03-11 01:57:32 +0300
commite4799845c5aded3b6b810f41bbe4a9ec1c762515 (patch)
tree214d69563556638eddfaabcc4f93afc80768db64 /check/magma
parent7b60e76fd9709def42ad0bbb46f3027d008b7bb1 (diff)
Cleanup and review of the SMTP/IMAP network tests.
Diffstat (limited to 'check/magma')
-rw-r--r--check/magma/servers/imap/imap_check.h4
-rw-r--r--check/magma/servers/imap/imap_check_network.c29
-rw-r--r--check/magma/servers/smtp/smtp_check.c10
-rw-r--r--check/magma/servers/smtp/smtp_check_network.c5
4 files changed, 28 insertions, 20 deletions
diff --git a/check/magma/servers/imap/imap_check.h b/check/magma/servers/imap/imap_check.h
index 402faf6a..8ea8c10f 100644
--- a/check/magma/servers/imap/imap_check.h
+++ b/check/magma/servers/imap/imap_check.h
@@ -8,8 +8,8 @@
#define IMAP_CHECK_H
/// imap_check_network.c
-bool_t check_imap_client_read_lines_to_end(client_t* client, chr_t* token);
-bool_t check_imap_network_basic_sthread(stringer_t* errmsg, uint32_t port);
+bool_t check_imap_client_read_lines_to_end(client_t *client, chr_t *tag);
+bool_t check_imap_network_basic_sthread(stringer_t *errmsg, uint32_t port);
Suite * suite_check_imap(void);
diff --git a/check/magma/servers/imap/imap_check_network.c b/check/magma/servers/imap/imap_check_network.c
index 66781ebd..21192b51 100644
--- a/check/magma/servers/imap/imap_check_network.c
+++ b/check/magma/servers/imap/imap_check_network.c
@@ -1,5 +1,6 @@
+
/**
- * @file /magma/check/magma/servers/smtp/smtp_check_helpers.c
+ * @file /magma/check/magma/servers/imap/imap_check_helpers.c
*
* @brief Functions used to test IMAP connections over a network connection.
*
@@ -8,20 +9,19 @@
#include "magma_check.h"
/**
- * Calls client_read_line on a client until it finds a line matching "<token> OK"
+ * @brief Calls client_read_line on a client until it finds a line matching "<token> OK"
*
* @param client The client to read from (which should be connected to an IMAP server).
* @param token The unique token that identifies the current imap command dialogue.
*
* @return Returns true if client_read_line was successful until the last line was found.
- * specified in num and there was no error. Otherwise returns false.
+ * specified in num and there was no error. Otherwise returns false.
*/
-bool_t check_imap_client_read_lines_to_end(client_t *client, chr_t *token) {
+bool_t check_imap_client_read_lines_to_end(client_t *client, chr_t *tag) {
bool_t outcome = false;
- stringer_t *last_line = st_merge("ss", NULLER(token), NULLER(" OK"));
+ stringer_t *last_line = st_merge("ss", NULLER(tag), NULLER(" OK"));
- // TODO: Add a timeout mechanism to client_read_line and update this function.
while (!outcome && client_read_line(client) > 0) {
if (!st_cmp_cs_starts(&client->line, last_line)) outcome = true;
}
@@ -35,8 +35,8 @@ bool_t check_imap_network_basic_sthread(stringer_t *errmsg, uint32_t port) {
client_t *client = NULL;
// Check the initial response.
- if (!(client = client_connect("localhost", port)) || client_read_line(client) <= 0 || (client->status != 1) ||
- st_cmp_cs_starts(&(client->line), NULLER("* OK"))) {
+ if (!(client = client_connect("localhost", port)) || !net_set_timeout(client->sockd, 20, 20) ||
+ client_read_line(client) <= 0 || (client->status != 1) || st_cmp_cs_starts(&(client->line), NULLER("* OK"))) {
st_sprint(errmsg, "Failed to connect with the IMAP server.");
client_close(client);
@@ -70,10 +70,19 @@ bool_t check_imap_network_basic_sthread(stringer_t *errmsg, uint32_t port) {
return false;
}
- // Test the LOGOUT command.
- else if (client_print(client, "A4 LOGOUT\r\n") <= 0 || !check_imap_client_read_lines_to_end(client, "A4") ||
+ // Test the CLOSE command.
+ else if (client_print(client, "A4 CLOSE\r\n") <= 0 || !check_imap_client_read_lines_to_end(client, "A4") ||
client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("A4 OK"))) {
+ st_sprint(errmsg, "Failed to return a successful state after CLOSE.");
+ client_close(client);
+ return false;
+ }
+
+ // Test the LOGOUT command.
+ else if (client_print(client, "A5 LOGOUT\r\n") <= 0 || !check_imap_client_read_lines_to_end(client, "A5") ||
+ client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("A5 OK"))) {
+
st_sprint(errmsg, "Failed to return a successful state after LOGOUT.");
client_close(client);
return false;
diff --git a/check/magma/servers/smtp/smtp_check.c b/check/magma/servers/smtp/smtp_check.c
index 25506ee3..390b0052 100644
--- a/check/magma/servers/smtp/smtp_check.c
+++ b/check/magma/servers/smtp/smtp_check.c
@@ -59,11 +59,11 @@ START_TEST (check_smtp_checkers_filters_s) {
bool_t outcome = true;
stringer_t *errmsg = MANAGEDBUF(1024);
- if (status()) outcome = check_smtp_checkers_regex_sthread(errmsg);
- if (status() && outcome) outcome = check_smtp_checkers_filters_sthread(errmsg, SMTP_FILTER_ACTION_DELETE, -2);
- if (status() && outcome) outcome = check_smtp_checkers_filters_sthread(errmsg, SMTP_FILTER_ACTION_MOVE, 2);
- if (status() && outcome) outcome = check_smtp_checkers_filters_sthread(errmsg, SMTP_FILTER_ACTION_LABEL, 3);
- if (status() && outcome) outcome = check_smtp_checkers_filters_sthread(errmsg, SMTP_FILTER_ACTION_MARK_READ, 4);
+ if (status()) outcome = check_smtp_checkers_regex_sthread(errmsg);
+ if (status() && outcome) outcome = check_smtp_checkers_filters_sthread(errmsg, SMTP_FILTER_ACTION_DELETE, -2);
+ if (status() && outcome) outcome = check_smtp_checkers_filters_sthread(errmsg, SMTP_FILTER_ACTION_MOVE, 2);
+ if (status() && outcome) outcome = check_smtp_checkers_filters_sthread(errmsg, SMTP_FILTER_ACTION_LABEL, 3);
+ if (status() && outcome) outcome = check_smtp_checkers_filters_sthread(errmsg, SMTP_FILTER_ACTION_MARK_READ, 4);
log_test("SMTP / CHECKERS / FILTERS / SINGLE THREADED:", errmsg);
ck_assert_msg(outcome, st_char_get(errmsg));
diff --git a/check/magma/servers/smtp/smtp_check_network.c b/check/magma/servers/smtp/smtp_check_network.c
index 4c6b9b42..30ecb66a 100644
--- a/check/magma/servers/smtp/smtp_check_network.c
+++ b/check/magma/servers/smtp/smtp_check_network.c
@@ -18,7 +18,6 @@
*/
bool_t check_smtp_client_read_line_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 (pl_char_get(client->line)[3] == ' ') return true;
}
@@ -31,8 +30,8 @@ bool_t check_smtp_network_simple_sthread(stringer_t *errmsg, uint32_t port) {
client_t *client = NULL;
// Test the connect banner.
- if (!(client = client_connect("localhost", port)) || client_read_line(client) <= 0 ||
- client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("220")) ||
+ if (!(client = client_connect("localhost", port)) || !net_set_timeout(client->sockd, 20, 20) ||
+ client_read_line(client) <= 0 || client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("220")) ||
!st_search_cs(&(client->line), NULLER(" ESMTP "), &location)) {
st_sprint(errmsg, "Failed to connect with the SMTP server.");