Skip to content

Commit

Permalink
lib-smtp: test-smtp-server-errors: Add tests for missing MAIL and RCP…
Browse files Browse the repository at this point in the history
…T commands before DATA command.
  • Loading branch information
stephanbosch authored and villesavolainen committed Mar 26, 2018
1 parent 431ab66 commit 346e837
Showing 1 changed file with 170 additions and 0 deletions.
170 changes: 170 additions & 0 deletions src/lib-smtp/test-smtp-server-errors.c
Expand Up @@ -1009,6 +1009,174 @@ static void test_too_many_recipients(void)
test_end();
}

/*
* DATA without MAIL
*/

/* client */

static void
test_data_no_mail_connected(struct client_connection *conn)
{
(void)o_stream_send_str(conn->conn.output,
"EHLO frop\r\n"
"DATA\r\n"
".\r\n"
"RSET\r\n");
}

static void test_client_data_no_mail(unsigned int index)
{
test_client_connected = test_data_no_mail_connected;
test_client_run(index);
}

/* server */

static int
test_server_data_no_mail_rcpt(void *conn_ctx ATTR_UNUSED,
struct smtp_server_cmd_ctx *cmd ATTR_UNUSED,
struct smtp_server_cmd_rcpt *data ATTR_UNUSED)
{
/* not supposed to get here */
i_assert(FALSE);
return 1;
}

static int
test_server_data_no_mail_data_begin(void *conn_ctx ATTR_UNUSED,
struct smtp_server_cmd_ctx *cmd ATTR_UNUSED,
struct smtp_server_transaction *trans ATTR_UNUSED,
struct istream *data_input ATTR_UNUSED)
{
/* not supposed to get here */
i_assert(FALSE);
return 1;
}

static int
test_server_data_no_mail_rset(void *conn_ctx ATTR_UNUSED,
struct smtp_server_cmd_ctx *cmd ATTR_UNUSED)
{
io_loop_stop(ioloop);
return 1;
}

static void test_server_data_no_mail
(const struct smtp_server_settings *server_set)
{
server_callbacks.conn_cmd_rcpt =
test_server_data_no_mail_rcpt;
server_callbacks.conn_cmd_data_begin =
test_server_data_no_mail_data_begin;
server_callbacks.conn_cmd_rset =
test_server_data_no_mail_rset;
test_server_run(server_set);
}

/* test */

static void test_data_no_mail(void)
{
struct smtp_server_settings smtp_server_set;

test_server_defaults(&smtp_server_set);
smtp_server_set.capabilities =
SMTP_CAPABILITY_BINARYMIME | SMTP_CAPABILITY_CHUNKING;
smtp_server_set.max_client_idle_time_msecs = 1000;
smtp_server_set.max_recipients = 10;

test_begin("DATA without MAIL");
test_run_client_server(&smtp_server_set,
test_server_data_no_mail,
test_client_data_no_mail, 1);
test_end();
}

/*
* DATA without RCPT
*/

/* client */

static void
test_data_no_rcpt_connected(struct client_connection *conn)
{
(void)o_stream_send_str(conn->conn.output,
"EHLO frop\r\n"
"MAIL FROM:<sender@example.com>\r\n"
"DATA\r\n"
".\r\n"
"RSET\r\n");
}

static void test_client_data_no_rcpt(unsigned int index)
{
test_client_connected = test_data_no_rcpt_connected;
test_client_run(index);
}

/* server */

static void
test_server_data_no_rcpt_trans_free(void *conn_ctx ATTR_UNUSED,
struct smtp_server_transaction *trans ATTR_UNUSED)
{
io_loop_stop(ioloop);
}

static int
test_server_data_no_rcpt_rcpt(void *conn_ctx ATTR_UNUSED,
struct smtp_server_cmd_ctx *cmd ATTR_UNUSED,
struct smtp_server_cmd_rcpt *data ATTR_UNUSED)
{
/* not supposed to get here */
i_assert(FALSE);
return 1;
}

static int
test_server_data_no_rcpt_data_begin(void *conn_ctx ATTR_UNUSED,
struct smtp_server_cmd_ctx *cmd ATTR_UNUSED,
struct smtp_server_transaction *trans ATTR_UNUSED,
struct istream *data_input ATTR_UNUSED)
{
/* not supposed to get here */
i_assert(FALSE);
return 1;
}

static void test_server_data_no_rcpt
(const struct smtp_server_settings *server_set)
{
server_callbacks.conn_trans_free =
test_server_data_no_rcpt_trans_free;
server_callbacks.conn_cmd_rcpt =
test_server_data_no_rcpt_rcpt;
server_callbacks.conn_cmd_data_begin =
test_server_data_no_rcpt_data_begin;
test_server_run(server_set);
}

/* test */

static void test_data_no_rcpt(void)
{
struct smtp_server_settings smtp_server_set;

test_server_defaults(&smtp_server_set);
smtp_server_set.capabilities =
SMTP_CAPABILITY_BINARYMIME | SMTP_CAPABILITY_CHUNKING;
smtp_server_set.max_client_idle_time_msecs = 1000;
smtp_server_set.max_recipients = 10;

test_begin("DATA without RCPT");
test_run_client_server(&smtp_server_set,
test_server_data_no_rcpt,
test_client_data_no_rcpt, 1);
test_end();
}

/*
* All tests
*/
Expand All @@ -1022,6 +1190,8 @@ static void (*const test_functions[])(void) = {
test_big_data,
test_bad_ehlo,
test_too_many_recipients,
test_data_no_mail,
test_data_no_rcpt,
NULL
};

Expand Down

0 comments on commit 346e837

Please sign in to comment.