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-31 00:33:28 +0300
committerjpadkins <jacobpadkins@gmail.com>2017-03-31 00:33:28 +0300
commit8a70541a696f5c41f6f21758879e43ddefb13290 (patch)
treedbf27643eb9ced2f85ed7e7e67a2e73fbc57b393 /check/magma
parenta7c5aea2f767a3cf78a5213230e60e705cc1886d (diff)
Refactored client_print's to client_writes in network tests.
Diffstat (limited to 'check/magma')
-rw-r--r--check/magma/regression/regression_check_helpers.c9
-rw-r--r--check/magma/servers/camel/camel_check_network.c2
-rw-r--r--check/magma/servers/http/http_check_network.c4
-rw-r--r--check/magma/servers/imap/imap_check_network.c60
-rw-r--r--check/magma/servers/pop/pop_check_network.c33
-rw-r--r--check/magma/servers/smtp/smtp_check_network.c32
6 files changed, 69 insertions, 71 deletions
diff --git a/check/magma/regression/regression_check_helpers.c b/check/magma/regression/regression_check_helpers.c
index 0b40eca7..96f5d381 100644
--- a/check/magma/regression/regression_check_helpers.c
+++ b/check/magma/regression/regression_check_helpers.c
@@ -56,7 +56,7 @@ 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"),
+ stringer_t *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"\
@@ -100,6 +100,7 @@ bool_t check_regression_smtp_dot_stuffing_sthread(stringer_t *errmsg) {
st_cmp_cs_starts(&(client->line), NULLER("+OK"))) {
st_sprint(errmsg, "Failed to connect to POP server.");
+ client_close(client);
return false;
}
else if (!check_pop_client_auth(client, "princess", "password", errmsg)) {
@@ -107,15 +108,14 @@ bool_t check_regression_smtp_dot_stuffing_sthread(stringer_t *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 ||
+ else if (client_write(client, PLACER("LIST\r\n", 6)) != 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) {
+ else if (client_print(client, "TOP %lu 0\r\n", message_num) != (uint16_digits(message_num) + 8) || client_status(client) != 1) {
st_sprint(errmsg, "Failed to return successful status after TOP.");
client_close(client);
@@ -128,5 +128,6 @@ bool_t check_regression_smtp_dot_stuffing_sthread(stringer_t *errmsg) {
return false;
}
+ client_close(client);
return true;
}
diff --git a/check/magma/servers/camel/camel_check_network.c b/check/magma/servers/camel/camel_check_network.c
index 2948d637..37f1e397 100644
--- a/check/magma/servers/camel/camel_check_network.c
+++ b/check/magma/servers/camel/camel_check_network.c
@@ -49,7 +49,7 @@ bool_t check_camel_login_sthread(client_t *client, stringer_t *errmsg) {
"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) {
+ if (client_write(client, PLACER(message, ns_length_get(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);
diff --git a/check/magma/servers/http/http_check_network.c b/check/magma/servers/http/http_check_network.c
index 7499f42e..b4928eb0 100644
--- a/check/magma/servers/http/http_check_network.c
+++ b/check/magma/servers/http/http_check_network.c
@@ -119,7 +119,7 @@ bool_t check_http_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_
return false;
}
// Test submitting a GET request.
- else if (client_print(client, "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n") != 35 || client_status(client) != 1 ||
+ else if (client_write(client, PLACER("GET / HTTP/1.1\r\nHost: localhost\r\n\r\n", 35)) != 35 || client_status(client) != 1 ||
!(content_length = check_http_content_length_get(client, errmsg))) {
if (st_empty(errmsg)) st_sprint(errmsg, "Failed to return a valid GET response.");
@@ -161,7 +161,7 @@ bool_t check_http_network_options_sthread(stringer_t *errmsg, uint32_t port, boo
return false;
}
// Test OPTIONS
- else if (client_print(client, "OPTIONS /portal/camel HTTP/1.1\r\n\r\n") != 34 || client_status(client) != 1 ||
+ else if (client_write(client, PLACER("OPTIONS /portal/camel HTTP/1.1\r\n\r\n", 34)) != 34 || client_status(client) != 1 ||
!check_http_options(client, options, errmsg)) {
client_close(client);
diff --git a/check/magma/servers/imap/imap_check_network.c b/check/magma/servers/imap/imap_check_network.c
index 68421384..d5316589 100644
--- a/check/magma/servers/imap/imap_check_network.c
+++ b/check/magma/servers/imap/imap_check_network.c
@@ -43,17 +43,11 @@ bool_t check_imap_client_read_end(client_t *client, chr_t *tag) {
bool_t check_imap_client_login(client_t *client, chr_t *user, chr_t *pass, chr_t *tag, stringer_t *errmsg) {
stringer_t *login_line = NULL;
- uint32_t login_line_len = ns_length_get(tag) + ns_length_get(user) + ns_length_get(pass) + 10;
- // Construct the login command
- if (!(login_line = st_merge("nsnsns", tag, NULLER(" LOGIN "), user, NULLER(" "), pass, NULLER("\r\n")))) {
-
- st_sprint(errmsg, "Failed to construct the login command.");
- return false;
- }
// Test the LOGIN command.
- else if (client_print(client, st_char_get(login_line)) != login_line_len || !check_imap_client_read_end(client, tag) ||
- client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER(tag))) {
+ if (client_print(client, "%s LOGIN %s %s\r\n", tag, user, pass) <= 0 ||
+ !check_imap_client_read_end(client, tag) || client_status(client) != 1 ||
+ st_cmp_cs_starts(&(client->line), NULLER(tag))) {
st_sprint(errmsg, "Failed to return a successful state after LOGIN.");
return false;
@@ -75,8 +69,9 @@ bool_t check_imap_client_login(client_t *client, chr_t *user, chr_t *pass, chr_t
bool_t check_imap_client_select(client_t *client, chr_t *folder, chr_t *tag, stringer_t *errmsg) {
// Test the SELECT command.
- if (client_print(client, "%s SELECT Inbox\r\n", tag) <= 0 || !check_imap_client_read_end(client, tag) ||
- client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER(tag))) {
+ if (client_print(client, "%s SELECT Inbox\r\n", tag) != (ns_length_get(tag) + 15) ||
+ !check_imap_client_read_end(client, tag) || client_status(client) != 1 ||
+ st_cmp_cs_starts(&(client->line), NULLER(tag))) {
st_sprint(errmsg, "Failed to return a successful state after SELECT.");
return false;
@@ -100,7 +95,7 @@ bool_t check_imap_client_close_logout(client_t *client, uint32_t tag_num, string
tag_num += 1;
// Construct the tag, close_command, and success stringers for CLOSE.
- if (!(tag = st_alloc_opts(MANAGED_T | CONTIGUOUS | HEAP, 1024)) || (st_sprint(tag, "A%u", tag_num) != uint32_digits(tag_num)+1) ||
+ if (!(tag = st_alloc(1024)) || (st_sprint(tag, "A%u", tag_num) != uint32_digits(tag_num)+1) ||
!(command = st_merge("sn", tag, " CLOSE\r\n")) || !(success = st_merge("sn", tag, " OK"))) {
st_sprint(errmsg, "Failed to construct tag, command, or success strings for CLOSE.");
@@ -124,7 +119,7 @@ bool_t check_imap_client_close_logout(client_t *client, uint32_t tag_num, string
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) ||
+ if (!(tag = st_alloc(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"))) {
st_sprint(errmsg, "Failed to construct tag, command, or success strings for LOGOUT.");
@@ -214,7 +209,7 @@ bool_t check_imap_network_search_sthread(stringer_t *errmsg, uint32_t port, bool
uint32_t tag_num = 0;
client_t *client = NULL;
- stringer_t *tag = NULL, *command = NULL, *success = NULL;
+ stringer_t *tag = NULL, *success = NULL;
chr_t *commands[] = {
"SEARCH ALL\r\n",
"SEARCH ANSWERED\r\n",
@@ -279,26 +274,25 @@ bool_t check_imap_network_search_sthread(stringer_t *errmsg, uint32_t port, bool
tag_num = i + 2;
- if (!(tag = st_alloc_opts(MANAGED_T | CONTIGUOUS | HEAP, 1024)) ||//(uint32_digits(tag_num) +1))) ||
- (st_sprint(tag, "A%u", tag_num) != uint32_digits(tag_num)+1) || !(command = st_merge("snn", tag, " ", commands[i])) ||
+ if (!(tag = st_alloc(uint32_digits(tag_num) + 2)) || (st_sprint(tag, "A%u", tag_num) != uint32_digits(tag_num) + 1) ||
!(success = st_merge("sn", tag, " OK Search complete.\r\n"))) {
- st_sprint(errmsg, "Failed to construct the command or success strings. { i = %d }", i);
- st_cleanup(tag, command, success);
+ st_sprint(errmsg, "Failed to construct the tag or success strings. { i = %d }", i);
+ st_cleanup(tag, success);
client_close(client);
return false;
}
- else if (client_print(client, st_char_get(command)) <= 0 || !check_imap_client_read_end(client, st_char_get(tag)) ||
- client_status(client) != 1 || st_cmp_cs_eq(&(client->line), success)) {
+ else if (client_print(client, "%s %s\r\n", st_char_get(tag), commands[i]) <= 0 ||
+ !check_imap_client_read_end(client, st_char_get(tag)) || client_status(client) != 1 ||
+ st_cmp_cs_eq(&(client->line), success)) {
- st_sprint(errmsg, "Failed to return a successful status. { command = \"%s\" }", st_char_get(command));
- st_cleanup(tag, command, success);
+ st_sprint(errmsg, "Failed to return a successful status. { command = \"%s\" }", commands[i]);
+ st_cleanup(tag, success);
client_close(client);
return false;
}
st_free(tag);
- st_free(command);
st_free(success);
}
@@ -318,7 +312,7 @@ bool_t check_imap_network_fetch_sthread(stringer_t *errmsg, uint32_t port, bool_
uint32_t tag_num = 0;
client_t *client = NULL;
- stringer_t *tag = NULL, *command = NULL, *success = NULL;
+ stringer_t *tag = NULL, *success = NULL;
chr_t *commands[] = {
"FETCH 1:* FLAGS\r\n",
"FETCH 1 (BODY [])\r\n",
@@ -354,25 +348,25 @@ bool_t check_imap_network_fetch_sthread(stringer_t *errmsg, uint32_t port, bool_
tag_num = i + 2;
- if (!(tag = st_alloc_opts(MANAGED_T | CONTIGUOUS | HEAP, 1024)) ||//(uint32_digits(tag_num) +1))) ||
- (st_sprint(tag, "A%u", tag_num) != uint32_digits(tag_num)+1) || !(command = st_merge("snn", tag, " ", commands[i])) ||
+ if (!(tag = st_alloc(uint32_digits(tag_num) + 2)) || (st_sprint(tag, "A%u", tag_num) != uint32_digits(tag_num) + 1) ||
!(success = st_merge("sn", tag, " OK"))) {
- st_sprint(errmsg, "Failed to construct the command or success strings. { i = %d }", i);
- st_cleanup(tag, command, success);
+ st_sprint(errmsg, "Failed to construct the tag or success strings. { i = %d }", i);
+ st_cleanup(tag, success);
client_close(client);
return false;
}
- else if (client_print(client, st_char_get(command)) <= 0 || !check_imap_client_read_end(client, st_char_get(tag)) ||
- client_status(client) != 1 || st_cmp_cs_starts(&(client->line), success)) {
+ else if (client_print(client, "%s %s\r\n", st_char_get(tag), commands[i]) <= 0 ||
+ !check_imap_client_read_end(client, st_char_get(tag)) || client_status(client) != 1 ||
+ st_cmp_cs_starts(&(client->line), success)) {
- st_sprint(errmsg, "Failed to return a successful status. { command = \"%s\" }", st_char_get(command));
- st_cleanup(tag, command, success);
+ st_sprint(errmsg, "Failed to return a successful status. { command = \"%s\" }", commands[i]);
+ st_cleanup(tag, success);
client_close(client);
return false;
}
- st_cleanup(tag, command, success);
+ st_cleanup(tag, success);
}
// Test the CLOSE and LOGOUT commands;
if (!check_imap_client_close_logout(client, tag_num+1, errmsg)) {
diff --git a/check/magma/servers/pop/pop_check_network.c b/check/magma/servers/pop/pop_check_network.c
index 87cbc7ad..b45c477d 100644
--- a/check/magma/servers/pop/pop_check_network.c
+++ b/check/magma/servers/pop/pop_check_network.c
@@ -69,16 +69,13 @@ uint64_t check_pop_client_read_list(client_t *client, stringer_t *errmsg) {
bool_t check_pop_client_auth(client_t *client, chr_t *user, chr_t *pass, stringer_t *errmsg) {
- stringer_t *user_command = st_aprint_opts(MANAGED_T | CONTIGUOUS | STACK, "USER %s\r\n", user),
- *pass_command = st_aprint_opts(MANAGED_T | CONTIGUOUS | STACK, "PASS %s\r\n", pass);
-
- if (client_print(client, st_char_get(user_command)) != st_length_get(user_command) || client_read_line(client) <= 0 ||
+ if (client_print(client, "USER %s\r\n", user) != (ns_length_get(user) + 7) || 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.");
return false;
}
- else if (client_print(client, st_char_get(pass_command)) != st_length_get(pass_command) || client_read_line(client) <= 0 ||
+ else if (client_print(client, "PASS %s\r\n", pass) != (ns_length_get(pass) + 7) || 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 PASS.");
@@ -91,7 +88,6 @@ bool_t check_pop_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_t
uint64_t message_num;
client_t *client = NULL;
- stringer_t *top_command = NULL;
// Connect the client.
if (!(client = client_connect("localhost", port)) || (secure && (client_secure(client) == -1)) ||
@@ -104,14 +100,14 @@ bool_t check_pop_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_t
}
// Test the USER and PASS commands with incorrect credentials.
- else if (client_print(client, "USER princess\r\n") != 15 || client_read_line(client) <= 0 ||
+ else if (client_write(client, PLACER("USER princess\r\n", 15)) != 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);
return false;
}
- else if (client_print(client, "PASS lavabit\r\n") != 14 || client_read_line(client) <= 0 ||
+ else if (client_write(client, PLACER("PASS lavabit\r\n", 14)) != 14 || client_read_line(client) <= 0 ||
client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("-ERR"))) {
st_sprint(errmsg, "Failed to return an error state after PASS with incorrect credentials.");
@@ -120,14 +116,14 @@ bool_t check_pop_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_t
}
// Test the USER and PASS commands with correct credentials.
- else if (client_print(client, "USER princess\r\n") != 15 || client_read_line(client) <= 0 ||
+ else if (client_write(client, PLACER("USER princess\r\n", 15)) != 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);
return false;
}
- else if (client_print(client, "PASS password\r\n") != 15 || client_read_line(client) <= 0 ||
+ else if (client_write(client, PLACER("PASS password\r\n", 15)) != 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.");
@@ -136,7 +132,7 @@ bool_t check_pop_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_t
}
// Test the LIST command.
- else if (client_print(client, "LIST\r\n") != 6 || !(message_num = check_pop_client_read_list(client, errmsg)) ||
+ else if (client_write(client, PLACER("LIST\r\n", 6)) != 6 || !(message_num = check_pop_client_read_list(client, errmsg)) ||
client_status(client) != 1) {
if (!errmsg) st_sprint(errmsg, "Failed to return a successful state after LIST.");
@@ -145,7 +141,7 @@ bool_t check_pop_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_t
}
// Test the RETR command.
- else if (client_print(client, "RETR 1\r\n") != 8 || !check_pop_client_read_end(client, NULL, NULL) ||
+ else if (client_write(client, PLACER("RETR 1\r\n", 8)) != 8 || !check_pop_client_read_end(client, NULL, NULL) ||
client_status(client) != 1) {
st_sprint(errmsg, "Failed to return a successful state after RETR.");
@@ -154,7 +150,7 @@ bool_t check_pop_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_t
}
// Test the DELE command.
- else if (client_print(client, "DELE 1\r\n") != 8 || client_read_line(client) <= 0 || client_status(client) != 1 ||
+ else if (client_write(client, PLACER("DELE 1\r\n", 8)) != 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.");
@@ -163,7 +159,7 @@ bool_t check_pop_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_t
}
// Test the NOOP command.
- else if (client_print(client, "NOOP\r\n") != 6 || client_read_line(client) <= 0 || client_status(client) != 1 ||
+ else if (client_write(client, PLACER("NOOP\r\n", 6)) != 6 || 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 NOOP.");
@@ -172,9 +168,8 @@ bool_t check_pop_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_t
}
// Test the TOP command.
- 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 ||
- client_read_line(client) <= 0 || st_cmp_cs_starts(&(client->line), NULLER("+OK"))||
+ else if (client_print(client, "TOP %lu 0\r\n", message_num) != (uint16_digits(message_num) + 8) ||
+ client_status(client) != 1 || client_read_line(client) <= 0 || st_cmp_cs_starts(&(client->line), NULLER("+OK"))||
!check_pop_client_read_end(client, NULL, NULL)) {
st_sprint(errmsg, "Failed to return a successful state after TOP.");
@@ -183,7 +178,7 @@ bool_t check_pop_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_t
}
// Test the RSET command.
- else if (client_print(client, "RSET\r\n") != 6 || client_read_line(client) <= 0 || client_status(client) != 1 ||
+ else if (client_write(client, PLACER("RSET\r\n", 6)) != 6 || client_read_line(client) <= 0 || client_status(client) != 1 ||
st_cmp_cs_eq(&(client->line), NULLER("+OK All messages were reset.\r\n"))) {
st_sprint(errmsg, "Failed to return a successful state after RSET.");
@@ -192,7 +187,7 @@ bool_t check_pop_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_t
}
// Test the QUIT command.
- else if (client_print(client, "QUIT 1\r\n") <= 0 || client_read_line(client) <= 0 || client_status(client) != 1 ||
+ else if (client_write(client, PLACER("QUIT 1\r\n", 8)) != 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 QUIT.");
diff --git a/check/magma/servers/smtp/smtp_check_network.c b/check/magma/servers/smtp/smtp_check_network.c
index 18ad4d64..0a68fbed 100644
--- a/check/magma/servers/smtp/smtp_check_network.c
+++ b/check/magma/servers/smtp/smtp_check_network.c
@@ -51,7 +51,7 @@ bool_t check_smtp_client_mail_rcpt_data(client_t *client, chr_t *from, chr_t *to
}
// Issue DATA command.
- else if (client_print(client, "DATA\r\n") != 6 || !check_smtp_client_read_end(client) ||
+ else if (client_write(client, PLACER("DATA\r\n", 6)) != 6 || !check_smtp_client_read_end(client) ||
client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("354"))) {
st_sprint(errmsg, "Failed to return a proceed status code after DATA.");
return false;
@@ -96,7 +96,7 @@ bool_t check_smtp_client_auth_plain(client_t *client, chr_t *auth, stringer_t *e
*/
bool_t check_smtp_client_auth_login(client_t *client, chr_t *user, chr_t *pass, stringer_t *errmsg) {
- if (client_print(client, "AUTH LOGIN\r\n") != 12 || !check_smtp_client_read_end(client) ||
+ if (client_write(client, PLACER("AUTH LOGIN\r\n", 12)) != 12 || !check_smtp_client_read_end(client) ||
client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("334"))) {
st_sprint(errmsg, "Failed to return a proceed status code after AUTH LOGIN.");
@@ -129,7 +129,7 @@ bool_t check_smtp_client_auth_login(client_t *client, chr_t *user, chr_t *pass,
bool_t check_smtp_client_quit(client_t *client, stringer_t *errmsg) {
// Test the QUIT command.
- if (client_print(client, "QUIT\r\n") != 6 || client_read_line(client) <= 0 ||
+ if (client_write(client, PLACER("QUIT\r\n", 6)) != 6 || client_read_line(client) <= 0 ||
client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("221"))) {
st_sprint(errmsg, "Failed to return successful status following the QUIT command.");
@@ -149,6 +149,8 @@ bool_t check_smtp_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_
size_t location = 0;
client_t *client = NULL;
+ chr_t *message = "To: magma@lavabit.com\r\nFrom: princess@example.com\r\nSubject: Unit Tests\r\n\r\n"\
+ "Aren't unit tests great?\r\n.\r\n";
// Test the connect banner.
if (!(client = client_connect("localhost", port)) || (secure && (client_secure(client) == -1)) ||
@@ -161,49 +163,55 @@ bool_t check_smtp_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_
}
// Test the HELO command.
- else if (client_print(client, "HELO localhost\r\n") != 16 || client_read_line(client) <= 0 ||
+ else if (client_write(client, PLACER("HELO localhost\r\n", 16)) != 16 || client_read_line(client) <= 0 ||
client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("250"))) {
+
st_sprint(errmsg, "Failed to return successful status after HELO.");
client_close(client);
return false;
}
// Test the EHLO command.
- else if (client_print(client, "EHLO localhost\r\n") != 16 || !check_smtp_client_read_end(client) ||
+ else if (client_write(client, PLACER("EHLO localhost\r\n", 16)) != 16 || !check_smtp_client_read_end(client) ||
client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("250"))) {
+
st_sprint(errmsg, "Failed to return successful status after EHLO.");
client_close(client);
return false;
}
// Test the MAIL command.
- else if (client_print(client, "MAIL FROM: <>\r\n") != 15 || client_read_line(client) <= 0 ||
+ else if (client_write(client, PLACER("MAIL FROM: <>\r\n", 15)) != 15 || client_read_line(client) <= 0 ||
client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("250"))) {
+
st_sprint(errmsg, "Failed to return successful status after MAIL.");
client_close(client);
return false;
}
// Test the RCPT command.
- else if (client_print(client, "RCPT TO: <princess@example.com>\r\n") != 33 || client_read_line(client) <= 0 ||
+ else if (client_write(client, PLACER("RCPT TO: <princess@example.com>\r\n", 33)) != 33 || client_read_line(client) <= 0 ||
client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("250"))) {
+
st_sprint(errmsg, "Failed to return successful status after RCPT.");
client_close(client);
return false;
}
// Test the DATA command.
- else if (client_print(client, "DATA\r\n") != 6 || client_read_line(client) <= 0 ||
+ else if (client_write(client, PLACER("DATA\r\n", 6)) != 6 || client_read_line(client) <= 0 ||
client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("354"))) {
+
st_sprint(errmsg, "Failed to return a proceed status code after DATA.");
client_close(client);
return false;
}
// Test sending the contents of an email.
- else if (client_print(client, "To: magma@lavabit.com\r\nFrom: princess@example.com\r\nSubject: Unit Tests\r\n\r\n" \
- "Aren't unit tests great?\r\n.\r\n") != 103 || client_read_line(client) <= 0 ||
- client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("250"))) {
+ else if (client_write(client, PLACER(message, ns_length_get(message))) != ns_length_get(message) ||
+ client_read_line(client) <= 0 || client_status(client) != 1 ||
+ st_cmp_cs_starts(&(client->line), NULLER("250"))) {
+
st_sprint(errmsg, "Failed to get a successful status code after email submission.");
client_close(client);
return false;
@@ -234,7 +242,7 @@ bool_t check_smtp_network_auth_sthread(stringer_t *errmsg, uint32_t port, bool_t
return false;
}
// Issue EHLO.
- else if (client_print(client, "EHLO localhost\r\n") != 16 || !check_smtp_client_read_end(client) ||
+ else if (client_write(client, PLACER("EHLO localhost\r\n", 16)) != 16 || !check_smtp_client_read_end(client) ||
client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("250"))) {
st_sprint(errmsg, "Failed to return successful status after EHLO.");