bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2016-2018 Dovecot authors, see the included COPYING file */
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtypedef void (*test_server_init_t)(unsigned int index);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch (const struct smtp_client_settings *client_set);
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic struct connection_list *server_conn_list;
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic void (*test_server_input)(struct server_connection *conn);
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic int (*test_server_input_line)(struct server_connection *conn,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch const char *line);
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic int (*test_server_input_data)(struct server_connection *conn,
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic int (*test_server_init)(struct server_connection *conn);
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic void (*test_server_deinit)(struct server_connection *conn);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch * Forward declarations
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic void test_server_run(unsigned int index);
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschserver_connection_deinit(struct server_connection **_conn);
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_defaults(struct smtp_client_settings *smtp_set);
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic void test_client_deinit(void);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch const struct smtp_client_settings *client_set,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch * Unconfigured SSL
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch /* nothing */
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_server_unconfigured_ssl(unsigned int index)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_server_input = test_server_unconfigured_ssl_input;
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_unconfigured_ssl_reply(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch struct _unconfigured_ssl *ctx = (struct _unconfigured_ssl *)context;
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_assert(reply->status == SMTP_CLIENT_COMMAND_ERROR_CONNECT_FAILED);
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_unconfigured_ssl(const struct smtp_client_settings *client_set)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_PROTOCOL_SMTP, "127.0.0.1", bind_ports[0],
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_PROTOCOL_SMTP, "127.0.0.1", bind_ports[0],
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch * Unconfigured SSL abort
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch /* nothing */
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_server_unconfigured_ssl_abort(unsigned int index)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_server_input = test_server_unconfigured_ssl_abort_input;
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_unconfigured_ssl_abort_reply1(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch struct _unconfigured_ssl_abort *ctx ATTR_UNUSED)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_out_quiet("inappropriate callback", FALSE);
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_unconfigured_ssl_abort_reply2(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_assert(reply->status == SMTP_CLIENT_COMMAND_ERROR_CONNECT_FAILED);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch const struct smtp_client_settings *client_set)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch ctx = i_new(struct _unconfigured_ssl_abort, 1);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_PROTOCOL_SMTP, "127.0.0.1", bind_ports[0],
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_connection_connect(sconn, NULL, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_client_unconfigured_ssl_abort_reply1, ctx);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_PROTOCOL_SMTP, "127.0.0.1", bind_ports[0],
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_connection_connect(sconn, NULL, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_client_unconfigured_ssl_abort_reply2, ctx);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch * Host lookup failed
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_host_lookup_failed_reply(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_assert(reply->status == SMTP_CLIENT_COMMAND_ERROR_HOST_LOOKUP_FAILED);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch const struct smtp_client_settings *client_set)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_connection_connect(sconn, NULL, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_connection_connect(sconn, NULL, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch * Connection refused
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_server_connection_refused(unsigned int index ATTR_UNUSED)
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_connection_refused_reply(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_assert(reply->status == SMTP_CLIENT_COMMAND_ERROR_CONNECT_FAILED);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch const struct smtp_client_settings *client_set)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0],
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_connection_connect(sconn, NULL, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0],
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_connection_connect(sconn, NULL, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch * Connection lost prematurely
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_connection_lost_prematurely_input(struct server_connection *conn)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch line = i_stream_read_next_line(conn->conn.input);
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_connection_lost_prematurely_init(struct server_connection *conn)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "220 testserver ESMTP Testfix (Frop/GNU)\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic void test_server_connection_lost_prematurely(unsigned int index)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_server_init = test_connection_lost_prematurely_init;
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_server_input = test_connection_lost_prematurely_input;
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_connection_lost_prematurely_reply(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_assert(reply->status == SMTP_CLIENT_COMMAND_ERROR_CONNECTION_LOST);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch const struct smtp_client_settings *client_set)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch ctx = i_new(struct _connection_lost_prematurely, 1);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0],
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_connection_connect(sconn, NULL, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_client_connection_lost_prematurely_reply, ctx);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0],
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_connection_connect(sconn, NULL, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_client_connection_lost_prematurely_reply, ctx);
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic void test_connection_lost_prematurely(void)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_server_connection_lost_prematurely, 1, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch * Connection timed out
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic void test_server_connection_timed_out(unsigned int index ATTR_UNUSED)
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_connection_timed_out_reply(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_assert(reply->status == SMTP_CLIENT_COMMAND_ERROR_CONNECT_FAILED);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch const struct smtp_client_settings *client_set)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0],
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_connection_connect(sconn, NULL, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0],
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_connection_connect(sconn, NULL, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch * Broken payload
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_broken_payload_input_line(struct server_connection *conn ATTR_UNUSED,
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic void test_server_broken_payload(unsigned int index)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_server_input_line = test_broken_payload_input_line;
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch struct server_connection *conn, const char *line ATTR_UNUSED)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch if (conn->state == SERVER_CONNECTION_STATE_EHLO) {
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "250-testserver\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "250-PIPELINING\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "250-CHUNKING\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "250-ENHANCEDSTATUSCODES\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "250 DSN\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic void test_server_broken_payload_chunking(unsigned int index)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_server_input_line = test_broken_payload_chunking_input_line;
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_broken_payload_rcpt_to_cb(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_broken_payload_rcpt_data_cb(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_assert(reply->status == SMTP_CLIENT_COMMAND_ERROR_BROKEN_PAYLOAD);
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_broken_payload_data_cb(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_assert(reply->status == SMTP_CLIENT_COMMAND_ERROR_BROKEN_PAYLOAD);
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_broken_payload_finished(void *context ATTR_UNUSED)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch const struct smtp_client_settings *client_set)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch input = i_stream_create_error_str(EIO, "Moehahahaha!!");
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0],
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch strans = smtp_client_transaction_create(sconn,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_ADDRESS_LITERAL("sender", "example.com"), NULL,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_ADDRESS_LITERAL("rcpt", "example.com"), NULL,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_client_broken_payload_rcpt_data_cb, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch const struct smtp_client_settings *client_set)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "From: lucifer@example.com\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "To: lostsoul@example.com\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "Subject: Moehahaha!\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "Moehahahahahahahahahahahahahahahahahahahahahaha!!\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "Moehahahahahahahahahahahahahahahahahahahahahaha!!\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "Moehahahahahahahahahahahahahahahahahahahahahaha!!\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "Moehahahahahahahahahahahahahahahahahahahahahaha!!\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "Moehahahahahahahahahahahahahahahahahahahahahaha!!\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "Moehahahahahahahahahahahahahahahahahahahahahaha!!\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "Moehahahahahahahahahahahahahahahahahahahahahaha!!\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "Moehahahahahahahahahahahahahahahahahahahahahaha!!\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "Moehahahahahahahahahahahahahahahahahahahahahaha!!\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "Moehahahahahahahahahahahahahahahahahahahahahaha!!\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "Moehahahahahahahahahahahahahahahahahahahahahaha!!\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "Moehahahahahahahahahahahahahahahahahahahahahaha!!\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "Moehahahahahahahahahahahahahahahahahahahahahaha!!\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "Moehahahahahahahahahahahahahahahahahahahahahaha!!\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "Moehahahahahahahahahahahahahahahahahahahahahaha!!\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "Moehahahahahahahahahahahahahahahahahahahahahaha!!\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "Moehahahahahahahahahahahahahahahahahahahahahaha!!\r\n";
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch msg_input = i_stream_create_from_data(message, strlen(message));
a4985564b81d51caaddd38376792432428fd449bStephan Bosch input = i_stream_create_failure_at(msg_input, 666,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0],
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch strans = smtp_client_transaction_create(sconn,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_ADDRESS_LITERAL("sender", "example.com"), NULL,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_ADDRESS_LITERAL("rcpt", "example.com"), NULL,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_client_broken_payload_rcpt_data_cb, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch (strans, input, test_client_broken_payload_data_cb, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_begin("broken payload (later, chunking)");
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_server_broken_payload_chunking, 1, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch * Connection lost
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_connection_lost_input_line(struct server_connection *conn,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch conn->state = SERVER_CONNECTION_STATE_MAIL_FROM;
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch conn->state = SERVER_CONNECTION_STATE_RCPT_TO;
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_connection_lost_input_data(struct server_connection *conn,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch const unsigned char *data ATTR_UNUSED, size_t size ATTR_UNUSED)
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic void test_server_connection_lost(unsigned int index)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_server_input_line = test_connection_lost_input_line;
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_server_input_data = test_connection_lost_input_data;
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_connection_lost_rcpt_to_cb(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_connection_lost_rcpt_data_cb(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_assert(reply->status == SMTP_CLIENT_COMMAND_ERROR_CONNECTION_LOST);
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_connection_lost_data_cb(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_assert(reply->status == SMTP_CLIENT_COMMAND_ERROR_CONNECTION_LOST);
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_connection_lost_finished(struct _connection_lost_peer *pctx)
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_connection_lost_submit(struct _connection_lost *ctx,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch unsigned int index)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "From: stephan@example.com\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "To: timo@example.com\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "Subject: Frop!\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch pctx = i_new(struct _connection_lost_peer, 1);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch input = i_stream_create_from_data(message, strlen(message));
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[index],
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch strans = smtp_client_transaction_create(sconn,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_ADDRESS_LITERAL("sender", "example.com"), NULL,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_ADDRESS_LITERAL("rcpt", "example.com"), NULL,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_client_connection_lost_rcpt_data_cb, pctx);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch (strans, input, test_client_connection_lost_data_cb, pctx);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch const struct smtp_client_settings *client_set)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch unsigned int i;
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch * Unexpected reply
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_unexpected_reply_init(struct server_connection *conn)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "220 testserver ESMTP Testfix (Debian/GNU)\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "421 testserver Server shutting down for maintenance\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_unexpected_reply_input_line(struct server_connection *conn,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "250-testserver\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "250-PIPELINING\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "250-ENHANCEDSTATUSCODES\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "250 DSN\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "421 testserver Server shutting down for maintenance\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "250 2.1.0 Ok\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "421 testserver Server shutting down for maintenance\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "250 2.1.5 Ok\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "421 testserver Server shutting down for maintenance\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "354 End data with <CR><LF>.<CR><LF>\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "421 testserver Server shutting down for maintenance\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic void test_server_unexpected_reply(unsigned int index)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_server_init = test_unexpected_reply_init;
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_server_input_line = test_unexpected_reply_input_line;
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_unexpected_reply_login_cb(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch i_debug("LOGIN REPLY[%u]: %s", pctx->index, smtp_reply_log(reply));
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_unexpected_reply_mail_from_cb(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch i_debug("MAIL FROM REPLY[%u]: %s", pctx->index, smtp_reply_log(reply));
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_unexpected_reply_rcpt_to_cb(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch i_debug("RCPT TO REPLY[%u]: %s", pctx->index, smtp_reply_log(reply));
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_unexpected_reply_rcpt_data_cb(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch i_debug("RCPT DATA REPLY[%u]: %s", pctx->index, smtp_reply_log(reply));
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_unexpected_reply_data_cb(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch i_debug("DATA REPLY[%u]: %s", pctx->index, smtp_reply_log(reply));
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_unexpected_reply_finished(struct _unexpected_reply_peer *pctx)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch struct _unexpected_reply *ctx = pctx->context;
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_unexpected_reply_submit2(struct _unexpected_reply_peer *pctx)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch struct smtp_client_transaction *strans = pctx->trans;
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "From: stephan@example.com\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "To: timo@example.com\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "Subject: Frop!\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch input = i_stream_create_from_data(message, strlen(message));
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch (strans, input, test_client_unexpected_reply_data_cb, pctx);
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_unexpected_reply_submit1(struct _unexpected_reply_peer *pctx)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_ADDRESS_LITERAL("rcpt", "example.com"), NULL,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_client_unexpected_reply_rcpt_data_cb, pctx);
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_unexpected_reply_submit(struct _unexpected_reply *ctx,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch unsigned int index)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch pctx = i_new(struct _unexpected_reply_peer, 1);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch pctx->conn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[index],
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch pctx->trans = smtp_client_transaction_create(pctx->conn,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_ADDRESS_LITERAL("sender", "example.com"), NULL,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_client_unexpected_reply_login_cb, (void *)pctx);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_client_unexpected_reply_mail_from_cb, pctx);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch const struct smtp_client_settings *client_set)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch unsigned int i;
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch * Partial reply
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_partial_reply_input_line(struct server_connection *conn,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch if (conn->state == SERVER_CONNECTION_STATE_EHLO)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "500 Command not");
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic void test_server_partial_reply(unsigned int index)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_server_input_line = test_partial_reply_input_line;
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_partial_reply_reply(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_assert(reply->status == SMTP_CLIENT_COMMAND_ERROR_CONNECTION_LOST);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch const struct smtp_client_settings *client_set)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0],
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_connection_connect(sconn, NULL, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0],
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_connection_connect(sconn, NULL, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_bad_reply_input_line(struct server_connection *conn,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch if (conn->state == SERVER_CONNECTION_STATE_EHLO)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "666 Really bad reply\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic void test_server_bad_reply(unsigned int index)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_server_input_line = test_bad_reply_input_line;
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_bad_reply_reply(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_assert(reply->status == SMTP_CLIENT_COMMAND_ERROR_BAD_REPLY);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch const struct smtp_client_settings *client_set)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0],
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_connection_connect(sconn, NULL, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0],
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_connection_connect(sconn, NULL, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch * Bad greeting
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_bad_greeting_init(struct server_connection *conn)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "666 Mouhahahaha!!\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "446 Not right now, sorry.\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "233 Gimme all your mail, NOW!!\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic void test_server_bad_greeting(unsigned int index)
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_bad_greeting_reply(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_bad_greeting_submit(struct _bad_greeting *ctx,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch unsigned int index)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[index],
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_connection_connect(sconn, NULL, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch const struct smtp_client_settings *client_set)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch * Command timeout
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_command_timed_out_input_line(struct server_connection *conn,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch if (conn->state == SERVER_CONNECTION_STATE_EHLO)
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic void test_server_command_timed_out(unsigned int index)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_server_input_line = test_command_timed_out_input_line;
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_command_timed_out_reply(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_assert(reply->status == SMTP_CLIENT_COMMAND_ERROR_TIMED_OUT);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch const struct smtp_client_settings *client_set)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0],
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_connection_connect(sconn, NULL, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch * Command aborted early
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_command_aborted_early_input_line(struct server_connection *conn,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch if (conn->state == SERVER_CONNECTION_STATE_EHLO)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch o_stream_nsend_str(conn->conn.output, "200 OK\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic void test_server_command_aborted_early(unsigned int index)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_server_input_line = test_command_aborted_early_input_line;
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_command_aborted_early_reply(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch struct _command_aborted_early *ctx ATTR_UNUSED)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch /* abort does not trigger callback */
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch /* abort early */
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch /* wait a little for server to actually respond to an
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch already aborted request */
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_client_command_aborted_early_timeout, ctx);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch /* all done */
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch const struct smtp_client_settings *client_set)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch ctx = i_new(struct _command_aborted_early, 1);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0],
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_connection_connect(sconn, NULL, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_client_command_aborted_early_reply, ctx);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_client_command_aborted_early_timeout, ctx);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch * Client deinit early
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_deinit_early_input_line(struct server_connection *conn,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch if (conn->state == SERVER_CONNECTION_STATE_EHLO)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch o_stream_nsend_str(conn->conn.output, "200 OK\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic void test_server_client_deinit_early(unsigned int index)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_server_input_line = test_client_deinit_early_input_line;
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_client_deinit_early_reply(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch /* abort does not trigger callback */
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch /* deinit early */
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch /* all done */
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch const struct smtp_client_settings *client_set)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0],
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_connection_connect(sconn, NULL, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_client_client_deinit_early_timeout, ctx);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch * DNS service failure
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_dns_service_failure_reply(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_assert(reply->status == SMTP_CLIENT_COMMAND_ERROR_HOST_LOOKUP_FAILED);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch const struct smtp_client_settings *client_set)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_connection_connect(sconn, NULL, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_connection_connect(sconn, NULL, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_set.dns_client_socket_path = "./frop";
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch * DNS timeout
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_dns_timeout_input(struct server_connection *conn ATTR_UNUSED)
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_dns_timeout_reply(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_assert(reply->status == SMTP_CLIENT_COMMAND_ERROR_HOST_LOOKUP_FAILED);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch const struct smtp_client_settings *client_set)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_connection_connect(sconn, NULL, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_connection_connect(sconn, NULL, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_set.dns_client_socket_path = "./dns-test";
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch * DNS lookup failure
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_dns_lookup_failure_input(struct server_connection *conn)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_server_input = test_dns_lookup_failure_input;
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_dns_lookup_failure_reply(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_assert(reply->status == SMTP_CLIENT_COMMAND_ERROR_HOST_LOOKUP_FAILED);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch const struct smtp_client_settings *client_set)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_connection_connect(sconn, NULL, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch sconn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_connection_connect(sconn, NULL, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch smtp_client_set.dns_client_socket_path = "./dns-test";
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch * Authentication failed
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_authentication_failed_input_line(struct server_connection *conn,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "250-testserver\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "250-PIPELINING\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "250-ENHANCEDSTATUSCODES\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "250-AUTH PLAIN\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "250 DSN\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch conn->state = SERVER_CONNECTION_STATE_MAIL_FROM;
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "Authentication credentials invalid\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic void test_server_authentication_failed(unsigned int index)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_server_input_line = test_authentication_failed_input_line;
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_authentication_failed_login_cb(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch (struct _authentication_failed_peer *)context;
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_authentication_failed_mail_from_cb(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_authentication_failed_rcpt_to_cb(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_authentication_failed_rcpt_data_cb(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_authentication_failed_data_cb(const struct smtp_reply *reply,
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_authentication_failed_finished(struct _authentication_failed_peer *pctx)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch struct _authentication_failed *ctx = pctx->context;
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_authentication_failed_submit(struct _authentication_failed *ctx,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch unsigned int index)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "From: stephan@example.com\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "To: timo@example.com\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "Subject: Frop!\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch pctx = i_new(struct _authentication_failed_peer, 1);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch pctx->conn = smtp_client_connection_create(smtp_client,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[index],
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch pctx->trans = smtp_client_transaction_create(pctx->conn,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_ADDRESS_LITERAL("sender", "example.com"), NULL,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_client_authentication_failed_finished, pctx);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_client_authentication_failed_login_cb, (void *)pctx);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_client_authentication_failed_mail_from_cb, pctx);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch SMTP_ADDRESS_LITERAL("rcpt", "example.com"), NULL,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_client_authentication_failed_rcpt_data_cb, pctx);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch input = i_stream_create_from_data(message, strlen(message));
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch input, test_client_authentication_failed_data_cb, pctx);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch const struct smtp_client_settings *client_set)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch unsigned int i;
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch ctx = i_new(struct _authentication_failed, 1);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch test_client_authentication_failed_submit(ctx, i);
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic void (*const test_functions[])(void) = {
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch * Test client
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschtest_client_defaults(struct smtp_client_settings *smtp_set)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch /* client settings */
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch * Test server
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch/* client connection */
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschserver_connection_input(struct connection *_conn)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch struct server_connection *conn = (struct server_connection *)_conn;
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch if (conn->state == SERVER_CONNECTION_STATE_FINISH) {
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch conn->dot_input = i_stream_create_dot(conn->conn.input, TRUE);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch while ((ret=i_stream_read_more(conn->dot_input,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch if (test_server_input_data(conn, data, size) < 0)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "250 2.0.0 Ok: queued as 73BDE342129\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch conn->state = SERVER_CONNECTION_STATE_MAIL_FROM;
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch line = i_stream_read_next_line(conn->conn.input);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "250-testserver\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "250-PIPELINING\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "250-ENHANCEDSTATUSCODES\r\n"
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "250 DSN\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch conn->state = SERVER_CONNECTION_STATE_MAIL_FROM;
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "Authentication successful\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "250 2.1.0 Ok\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch conn->state = SERVER_CONNECTION_STATE_RCPT_TO;
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "250 2.1.5 Ok\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "354 End data with <CR><LF>.<CR><LF>\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch pool = pool_alloconly_create("server connection", 256);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch conn = p_new(pool, struct server_connection, 1);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch (server_conn_list, &conn->conn, "server connection", fd, fd);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch "220 testserver ESMTP Testfix (Debian/GNU)\r\n");
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschserver_connection_deinit(struct server_connection **_conn)
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschserver_connection_destroy(struct connection *_conn)
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschserver_connection_accept(void *context ATTR_UNUSED)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch /* accept new client */
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic struct connection_settings server_connection_set = {
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic const struct connection_vfuncs server_connection_vfuncs = {
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic void test_server_run(unsigned int index)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch /* open server socket */
677b75f90d81eafe742896d6570a2f63ce501d05Josef 'Jeff' Sipek IO_READ, server_connection_accept, NULL);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch (&server_connection_set, &server_connection_vfuncs);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch /* close server socket */
9051b704ca26ef833544cf006134f25cddde2525Stephan Boschstatic int test_open_server_fd(in_port_t *bind_port)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch int fd = net_listen(&bind_ip, bind_port, 128);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch i_debug("server listening on %u", *bind_port);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch unsigned int i;
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch for (i = 0; i < server_pids_count; i++) {
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch const struct smtp_client_settings *client_set,
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch unsigned int i;
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch bind_ports = i_new(in_port_t, server_tests_count);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch server_pids = i_new(pid_t, server_tests_count);
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch for (i = 0; i < server_tests_count; i++)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch for (i = 0; i < server_tests_count; i++)
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch for (i = 0; i < server_tests_count; i++) {
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch if (server_pids[i] == 0) {
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch /* child: server */
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch /* wait for it to be killed; this way, valgrind will not
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch object to this process going away inelegantly. */
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch /* child: server */
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch /* wait for it to be killed; this way, valgrind will not
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch object to this process going away inelegantly. */
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch /* parent: client */
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch usleep(100000); /* wait a little for server setup */
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch /* make sure we don't leave any pesky children alive */
9051b704ca26ef833544cf006134f25cddde2525Stephan Bosch /* listen on localhost */