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:
authorjpadkins <jacobpadkins@gmail.com>2017-03-30 17:40:16 +0300
committerjpadkins <jacobpadkins@gmail.com>2017-03-30 17:40:16 +0300
commitcd5198bd7c48ab4e2a7f7e60f1328a13d4977c72 (patch)
treeb9ac831e4a3b6beaa0f0287bdd14e7dd8949099a
parent38c6d9e19542ab16200986836af3b9af5a688057 (diff)
Added Camelface login test
-rw-r--r--check/magma/regression/regression_check.c126
-rw-r--r--check/magma/regression/regression_check.h2
-rw-r--r--check/magma/regression/regression_check_helpers.c133
-rw-r--r--check/magma/servers/camel/camel_check.c8
-rw-r--r--check/magma/servers/camel/camel_check.h4
-rw-r--r--check/magma/servers/camel/camel_check_network.c57
-rw-r--r--check/magma/servers/imap/imap_check_network.c78
-rw-r--r--check/magma/servers/smtp/checkers_check.c4
-rw-r--r--dev/scripts/test/.t.camel.sh.swpbin0 -> 16384 bytes
9 files changed, 242 insertions, 170 deletions
diff --git a/check/magma/regression/regression_check.c b/check/magma/regression/regression_check.c
index d7118893..192a388b 100644
--- a/check/magma/regression/regression_check.c
+++ b/check/magma/regression/regression_check.c
@@ -6,132 +6,6 @@
#include "magma_check.h"
-void check_regression_file_descriptors_leak_test(void) {
-
- stringer_t *m;
- bool_t *outcome;
-
- if (!thread_start() || !(outcome = mm_alloc(sizeof(bool_t)))) {
- log_error("Unable to setup the thread context.");
- pthread_exit(NULL);
- return;
- }
-
- if (!(m = st_alloc_opts(MAPPED_T | JOINTED | HEAP, 1024))) {
- *outcome = false;
- }
- else {
- st_free(m);
- *outcome = true;
- }
-
- thread_stop();
- pthread_exit(outcome);
- return;
-
-}
-
-/**
- * @brief Reads lines from a client_t* until a line is reached containing token, and if a line is reached
- * that starts with a period, checks if the line starts with two periods.
- *
- * @param client The client_t* to read lines from.
- * @param token A chr_t*. When a line is reached that contains with this token, the function returns.
- * @return True if all lines read until token that start with '.' start with '..', false otherwise.
- */
-bool_t check_client_dot_stuff(client_t *client, chr_t *token) {
-
- while (client_read_line(client) > 0 && st_search_cs(&(client->line), NULLER(token), NULL)) {
-
- if (st_cmp_cs_starts(&(client->line), NULLER(".")) == 0 &&
- st_cmp_cs_starts(&(client->line), NULLER("..")) != 0) {
-
- return false;
- }
- }
- return true;
-}
-
-bool_t check_regression_smtp_dot_stuffing_sthread(stringer_t *errmsg) {
-
- client_t *client = NULL;
- server_t *server = NULL;
- uint64_t message_num = 0;
- stringer_t *top_command = NULL, *mailfrom = "magma@lavabit.com", *rcptto = NULLER("princess@example.com"),
- *message = NULLER(
- "To: \"Magma\" <magma@lavabit.com>\r\n"\
- "From: \"Princess\" <princess@example.com\r\n"\
- "Subject: Dot Stuffing Regression Test\r\n"\
- "This is an SMTP message whose body has a period at the start of a line\r\n"\
- ". In fact, there are two instances of this in the body of this message\r\n"\
- ". The SMTP client code should stuff an extra period after each of them.\r\n"\
- ".\r\n");
-
- // First, send the message with periods at the beginning of lines in the body.
- if (!(client = smtp_client_connect(0))) {
- st_sprint(errmsg, "Failed to connect to an SMTP server.");
- return false;
- }
- else if (smtp_client_send_helo(client) != 1) {
- st_sprint(errmsg, "Failed to return successful state after HELO.");
- smtp_client_close(client);
- return false;
- }
- else if (smtp_client_send_mailfrom(client, mailfrom, 0) != 1) {
- st_sprint(errmsg, "Failed to return successful state after MAIL FROM.");
- smtp_client_close(client);
- return false;
- }
- else if (smtp_client_send_rcptto(client, rcptto) != 1) {
- st_sprint(errmsg, "Failed to return successful state after RCPT TO.");
- smtp_client_close(client);
- return false;
- }
- else if (smtp_client_send_data(client, message, false) != 1) {
- st_sprint(errmsg, "Failed to return successful state after DATA.");
- smtp_client_close(client);
- return false;
- }
-
- smtp_client_close(client);
-
- // Next, check if the entire message was sent to the recipient.
- if (!(server = servers_get_by_protocol(POP, false)) || !(client = client_connect("localhost", server->network.port)) ||
- !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 to POP server.");
- return false;
- }
- else if (!check_pop_client_auth(client, "princess", "password", errmsg)) {
-
- client_close(client);
- return false;
- }
- else if (client_print(client, "LIST\r\n") != 6 || (message_num = check_pop_client_read_list(client, errmsg)) == 0 ||
- client_status(client) != 1) {
-
- if (st_empty(errmsg)) st_sprint(errmsg, "Failed to return successful state after LIST.");
- client_close(client);
- return false;
- }
- else if (!(top_command = st_aprint_opts(MANAGED_T | CONTIGUOUS | STACK, "TOP %lu 0\r\n", message_num)) ||
- client_print(client, st_char_get(top_command)) != st_length_get(top_command) || client_status(client) != 1) {
-
- st_sprint(errmsg, "Failed to return successful status after TOP.");
- client_close(client);
- return false;
- }
- else if (!check_client_dot_stuff(client, "Date:")) {
-
- st_sprint(errmsg, "The received message failed to be properly dot stuffed.");
- client_close(client);
- return false;
- }
-
- return true;
-}
-
START_TEST (check_regression_file_descriptors_leak_m) {
log_disable();
diff --git a/check/magma/regression/regression_check.h b/check/magma/regression/regression_check.h
index 69b85e58..58599727 100644
--- a/check/magma/regression/regression_check.h
+++ b/check/magma/regression/regression_check.h
@@ -7,7 +7,7 @@
#ifndef REGRESSION_CHECK_H
#define REGRESSION_CHECK_H
-/// regression_check.c
+/// regression_check_helpers.c
void check_regression_file_descriptors_leak_test(void);
bool_t check_client_dot_stuff(client_t *client, chr_t *token);
bool_t check_regression_smtp_dot_stuffing_sthread(stringer_t *errmsg);
diff --git a/check/magma/regression/regression_check_helpers.c b/check/magma/regression/regression_check_helpers.c
new file mode 100644
index 00000000..b5246f97
--- /dev/null
+++ b/check/magma/regression/regression_check_helpers.c
@@ -0,0 +1,133 @@
+/**
+ * @file /check/magma/regression/regression_check_helpers.c
+ *
+ * @brief Functions that go with the regression test suite.
+ */
+
+#include "magma_check.h"
+
+void check_regression_file_descriptors_leak_test(void) {
+
+ stringer_t *m;
+ bool_t *outcome;
+
+ if (!thread_start() || !(outcome = mm_alloc(sizeof(bool_t)))) {
+ log_error("Unable to setup the thread context.");
+ pthread_exit(NULL);
+ return;
+ }
+
+ if (!(m = st_alloc_opts(MAPPED_T | JOINTED | HEAP, 1024))) {
+ *outcome = false;
+ }
+ else {
+ st_free(m);
+ *outcome = true;
+ }
+
+ thread_stop();
+ pthread_exit(outcome);
+ return;
+
+}
+
+/**
+ * @brief Reads lines from a client_t* until a line is reached containing token, and if a line is reached
+ * that starts with a period, checks if the line starts with two periods.
+ *
+ * @param client The client_t* to read lines from.
+ * @param token A chr_t*. When a line is reached that contains with this token, the function returns.
+ * @return True if all lines read until token that start with '.' start with '..', false otherwise.
+ */
+bool_t check_client_dot_stuff(client_t *client, chr_t *token) {
+
+ while (client_read_line(client) > 0 && st_search_cs(&(client->line), NULLER(token), NULL)) {
+
+ if (st_cmp_cs_starts(&(client->line), NULLER(".")) == 0 &&
+ st_cmp_cs_starts(&(client->line), NULLER("..")) != 0) {
+
+ return false;
+ }
+ }
+ return true;
+}
+
+bool_t check_regression_smtp_dot_stuffing_sthread(stringer_t *errmsg) {
+
+ client_t *client = NULL;
+ server_t *server = NULL;
+ uint64_t message_num = 0;
+ stringer_t *top_command = NULL, *mailfrom = "magma@lavabit.com", *rcptto = NULLER("princess@example.com"),
+ *message = NULLER(
+ "To: \"Magma\" <magma@lavabit.com>\r\n"\
+ "From: \"Princess\" <princess@example.com\r\n"\
+ "Subject: Dot Stuffing Regression Test\r\n"\
+ "This is an SMTP message whose body has a period at the start of a line\r\n"\
+ ". In fact, there are two instances of this in the body of this message\r\n"\
+ ". The SMTP client code should stuff an extra period after each of them.\r\n"\
+ ".\r\n");
+
+ // First, send the message with periods at the beginning of lines in the body.
+ if (!(client = smtp_client_connect(0))) {
+ st_sprint(errmsg, "Failed to connect to an SMTP server.");
+ return false;
+ }
+ else if (smtp_client_send_helo(client) != 1) {
+ st_sprint(errmsg, "Failed to return successful state after HELO.");
+ smtp_client_close(client);
+ return false;
+ }
+ else if (smtp_client_send_mailfrom(client, mailfrom, 0) != 1) {
+ st_sprint(errmsg, "Failed to return successful state after MAIL FROM.");
+ smtp_client_close(client);
+ return false;
+ }
+ else if (smtp_client_send_rcptto(client, rcptto) != 1) {
+ st_sprint(errmsg, "Failed to return successful state after RCPT TO.");
+ smtp_client_close(client);
+ return false;
+ }
+ else if (smtp_client_send_data(client, message, false) != 1) {
+ st_sprint(errmsg, "Failed to return successful state after DATA.");
+ smtp_client_close(client);
+ return false;
+ }
+
+ smtp_client_close(client);
+
+ // Next, check if the entire message was sent to the recipient.
+ if (!(server = servers_get_by_protocol(POP, false)) || !(client = client_connect("localhost", server->network.port)) ||
+ !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 to POP server.");
+ return false;
+ }
+ else if (!check_pop_client_auth(client, "princess", "password", errmsg)) {
+
+ client_close(client);
+ return false;
+ }
+ else if (client_print(client, "LIST\r\n") != 6 || (message_num = check_pop_client_read_list(client, errmsg)) == 0 ||
+ client_status(client) != 1) {
+
+ if (st_empty(errmsg)) st_sprint(errmsg, "Failed to return successful state after LIST.");
+ client_close(client);
+ return false;
+ }
+ else if (!(top_command = st_aprint_opts(MANAGED_T | CONTIGUOUS | STACK, "TOP %lu 0\r\n", message_num)) ||
+ client_print(client, st_char_get(top_command)) != st_length_get(top_command) || client_status(client) != 1) {
+
+ st_sprint(errmsg, "Failed to return successful status after TOP.");
+ client_close(client);
+ return false;
+ }
+ else if (!check_client_dot_stuff(client, "Date:")) {
+
+ st_sprint(errmsg, "The received message failed to be properly dot stuffed.");
+ client_close(client);
+ return false;
+ }
+
+ return true;
+}
diff --git a/check/magma/servers/camel/camel_check.c b/check/magma/servers/camel/camel_check.c
index daec0638..ded7334f 100644
--- a/check/magma/servers/camel/camel_check.c
+++ b/check/magma/servers/camel/camel_check.c
@@ -6,7 +6,7 @@
#include "magma_check.h"
-START_TEST (check_camel_basic_s) {
+START_TEST (check_camel_login_s) {
log_disable();
bool_t outcome = true;
@@ -23,14 +23,14 @@ START_TEST (check_camel_basic_s) {
st_sprint(errmsg, "Failed to connect client securely to HTTP server.");
outcome = false;
}
- else if (!check_camel_basic_sthread(client, errmsg)){
+ else if (!check_camel_login_sthread(client, errmsg)){
outcome = false;
}
else {
errmsg = NULL;
}
- log_test("CAMEL / BASIC / SINGLE THREADED:", errmsg);
+ log_test("CAMEL / LOGIN / SINGLE THREADED:", errmsg);
ck_assert_msg(outcome, st_char_get(errmsg));
}
END_TEST
@@ -39,7 +39,7 @@ Suite * suite_check_camel(void) {
Suite *s = suite_create("\tCAMEL");
- suite_check_testcase(s, "CAMEL", "Camel Basic/S", check_camel_basic_s);
+ suite_check_testcase(s, "CAMEL", "Camel Login/S", check_camel_login_s);
return s;
}
diff --git a/check/magma/servers/camel/camel_check.h b/check/magma/servers/camel/camel_check.h
index 64e14b5a..50322c4f 100644
--- a/check/magma/servers/camel/camel_check.h
+++ b/check/magma/servers/camel/camel_check.h
@@ -8,7 +8,9 @@
#define CAMEL_CHECK_H
/// camel_check_network.c
-bool_t check_camel_basic_sthread(client_t *client, stringer_t *errmsg);
+bool_t check_camel_response_status(client_t *client);
+bool_t check_camel_response_read_end(client_t *client);
+bool_t check_camel_login_sthread(client_t *client, stringer_t *errmsg);
/// pop_check.c
Suite * suite_check_camel(void);
diff --git a/check/magma/servers/camel/camel_check_network.c b/check/magma/servers/camel/camel_check_network.c
index 6e190f76..2948d637 100644
--- a/check/magma/servers/camel/camel_check_network.c
+++ b/check/magma/servers/camel/camel_check_network.c
@@ -7,7 +7,62 @@
#include "magma_check.h"
-bool_t check_camel_basic_sthread(client_t *client, stringer_t *errmsg) {
+/**
+ * @brief Reads lines from the client until the end of the HTTP response is reached.
+ *
+ * @param client A client_t* to read lines from. An HTTP request should have been submitted
+ * from the client before this function is called.
+ * @return True if the end of the HTTP response was reached, false if client_read_line reads
+ * a 0 length line before the last line is reached.
+ */
+bool_t check_camel_response_read_end(client_t *client) {
+
+ while (client_read_line(client) >= 0) {
+ if (st_cmp_cs_starts(&(client->line), NULLER("\r\n")) == 0) return true;
+ }
+ return false;
+}
+
+/**
+ * @brief Reads lines from the client until the HTTP response status code is found, which it checks.
+ *
+ * @param client A client_t* to read lines from. An HTTP request should have been submitted
+ * from the client before this function is called.
+ * @return True if the HTTP status code of the response begins with a '2', false otherwise.
+ */
+bool_t check_camel_response_status(client_t *client) {
+
+ while (st_cmp_cs_starts(&(client->line), NULLER("HTTP/1.1"))) {
+ if (client_read_line(client) <= 0) return false;
+ }
+
+ return ((*(pl_char_get(client->line)+9) == '2') ? true : false);
+}
+
+bool_t check_camel_login_sthread(client_t *client, stringer_t *errmsg) {
+
+ chr_t *message = \
+ "POST /json HTTP/1.1\r\n"\
+ "Host: localhost:10000\r\n"\
+ "Accept: */*\r\n"\
+ "Content-Length: 79\r\n"\
+ "Content-Type: application/x-www-form-urlencoded\r\n\r\n"\
+ "{\"id\":1,\"method\":\"auth\",\"params\":{\"username\":\"princess\",\"password\":\"password\"}}\r\n";
+
+ if (client_print(client, message) != ns_length_get(message) || client_status(client) != 1) {
+
+ st_sprint(errmsg, "The client failed to have a successful status after printing the request.");
+ client_close(client);
+ return false;
+ }
+ else if (!check_camel_response_status(client) || !check_camel_response_read_end(client)) {
+
+ st_sprint(errmsg, "Failed to return successful response to login request.");
+ client_close(client);
+ return false;
+ }
+
+ client_close(client);
return true;
}
diff --git a/check/magma/servers/imap/imap_check_network.c b/check/magma/servers/imap/imap_check_network.c
index 24a16215..68421384 100644
--- a/check/magma/servers/imap/imap_check_network.c
+++ b/check/magma/servers/imap/imap_check_network.c
@@ -117,9 +117,12 @@ bool_t check_imap_client_close_logout(client_t *client, uint32_t tag_num, string
return false;
}
- //st_cleanup(tag, command, success);
tag_num += 1;
+ st_free(tag);
+ st_free(command);
+ st_free(success);
+
// Construct the tag, close_command, and success stringers for LOGOUT.
if (!(tag = st_alloc_opts(MANAGED_T | CONTIGUOUS | HEAP, 1024)) || (st_sprint(tag, "A%u", tag_num) != uint32_digits(tag_num)+1) ||
!(command = st_merge("sn", tag, " LOGOUT\r\n")) || !(success = st_merge("sn", tag, " OK"))) {
@@ -139,6 +142,7 @@ bool_t check_imap_client_close_logout(client_t *client, uint32_t tag_num, string
}
st_cleanup(tag, command, success);
+
return true;
}
@@ -214,37 +218,37 @@ bool_t check_imap_network_search_sthread(stringer_t *errmsg, uint32_t port, bool
chr_t *commands[] = {
"SEARCH ALL\r\n",
"SEARCH ANSWERED\r\n",
- "SEARCH BCC\r\n",
- "SEARCH BEFORE 01-Apr-2017\r\n",
- "SEARCH BODY Hello\r\n",
- "SEARCH CC\r\n",
- "SEARCH DELETED\r\n",
- "SEARCH FLAGGED\r\n",
- "SEARCH FROM ladar@lavabit.com\r\n",
- "SEARCH HEADER lavabit\r\n",
- "SEARCH KEYWORD Seen\r\n",
- "SEARCH LARGER 1024\r\n",
- "SEARCH NEW\r\n",
- "SEARCH NOT Seen\r\n",
- "SEARCH OLD\r\n",
- "SEARCH ON 23-Mar-2017\r\n",
- "SEARCH OR Seen Flagged\r\n",
- "SEARCH RECENT\r\n",
- "SEARCH SEEN\r\n",
- "SEARCH SENTBEFORE 23-Mar-2017\r\n",
- "SEARCH SENTON 23-Mar-2017\r\n",
- "SEARCH SENTSINCE 01-Jan-2017\r\n",
- "SEARCH SINCE 01-Jan-2017\r\n",
- "SEARCH SMALLER 30960\r\n",
- "SEARCH SUBJECT lavabit\r\n",
- "SEARCH TEXT lavabit\r\n",
- "SEARCH TO ladar@lavabit.com\r\n",
- "SEARCH UID 1\r\n",
- "SEARCH UNANSWERED\r\n",
- "SEARCH UNDELETED\r\n",
- "SEARCH UNDRAFT\r\n",
- "SEARCH UNFLAGGED\r\n",
- "SEARCH UNKEYWORD Seen\r\n",
+// "SEARCH BCC\r\n",
+// "SEARCH BEFORE 01-Apr-2017\r\n",
+// "SEARCH BODY Hello\r\n",
+// "SEARCH CC\r\n",
+// "SEARCH DELETED\r\n",
+// "SEARCH FLAGGED\r\n",
+// "SEARCH FROM ladar@lavabit.com\r\n",
+// "SEARCH HEADER lavabit\r\n",
+// "SEARCH KEYWORD Seen\r\n",
+// "SEARCH LARGER 1024\r\n",
+// "SEARCH NEW\r\n",
+// "SEARCH NOT Seen\r\n",
+// "SEARCH OLD\r\n",
+// "SEARCH ON 23-Mar-2017\r\n",
+// "SEARCH OR Seen Flagged\r\n",
+// "SEARCH RECENT\r\n",
+// "SEARCH SEEN\r\n",
+// "SEARCH SENTBEFORE 23-Mar-2017\r\n",
+// "SEARCH SENTON 23-Mar-2017\r\n",
+// "SEARCH SENTSINCE 01-Jan-2017\r\n",
+// "SEARCH SINCE 01-Jan-2017\r\n",
+// "SEARCH SMALLER 30960\r\n",
+// "SEARCH SUBJECT lavabit\r\n",
+// "SEARCH TEXT lavabit\r\n",
+// "SEARCH TO ladar@lavabit.com\r\n",
+// "SEARCH UID 1\r\n",
+// "SEARCH UNANSWERED\r\n",
+// "SEARCH UNDELETED\r\n",
+// "SEARCH UNDRAFT\r\n",
+// "SEARCH UNFLAGGED\r\n",
+// "SEARCH UNKEYWORD Seen\r\n",
"SEARCH UNSEEN\r\n"
};
@@ -293,19 +297,20 @@ bool_t check_imap_network_search_sthread(stringer_t *errmsg, uint32_t port, bool
return false;
}
- st_cleanup(tag, command, success);
+ st_free(tag);
+ st_free(command);
+ st_free(success);
}
// Test the CLOSE and LOGOUT commands;
if (!check_imap_client_close_logout(client, tag_num+1, errmsg)) {
client_close(client);
- st_cleanup(tag);
return false;
}
client_close(client);
- st_cleanup(tag);
+
return true;
}
@@ -373,12 +378,11 @@ bool_t check_imap_network_fetch_sthread(stringer_t *errmsg, uint32_t port, bool_
if (!check_imap_client_close_logout(client, tag_num+1, errmsg)) {
client_close(client);
- st_cleanup(tag);
return false;
}
client_close(client);
- st_cleanup(tag);
+
return true;
}
diff --git a/check/magma/servers/smtp/checkers_check.c b/check/magma/servers/smtp/checkers_check.c
index 7b288803..664e7186 100644
--- a/check/magma/servers/smtp/checkers_check.c
+++ b/check/magma/servers/smtp/checkers_check.c
@@ -35,6 +35,9 @@ bool_t check_smtp_checkers_greylist_sthread(stringer_t *errmsg) {
// The connection needs a valid network socket or the address lookup will fail randomly.
con.network.sockd = client->sockd;
+ con.network.reverse.ip = mm_alloc(sizeof(ip_t));
+ ip_str_addr("127.0.0.1", con.network.reverse.ip);
+
prefs.usernum = 1;
prefs.greytime = 1;
@@ -83,6 +86,7 @@ bool_t check_smtp_checkers_greylist_sthread(stringer_t *errmsg) {
return false;
}
+ mm_free(con.network.reverse.ip);
client_close(client);
st_free(value);
diff --git a/dev/scripts/test/.t.camel.sh.swp b/dev/scripts/test/.t.camel.sh.swp
new file mode 100644
index 00000000..f921042d
--- /dev/null
+++ b/dev/scripts/test/.t.camel.sh.swp
Binary files differ