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 /check/magma/servers
parent38c6d9e19542ab16200986836af3b9af5a688057 (diff)
Added Camelface login test
Diffstat (limited to 'check/magma/servers')
-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
5 files changed, 108 insertions, 43 deletions
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);