/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
#include "test-lib.h"
#include "array.h"
#include "buffer.h"
#include "str.h"
#include "str-sanitize.h"
#include "istream.h"
#include "ostream.h"
#include "test-common.h"
#include "smtp-reply-parser.h"
#include <time.h>
struct smtp_reply_parse_valid_test {
const char *reply;
unsigned int status;
bool ehlo;
struct {
unsigned int x, y, z;
const char *const *text_lines;
};
/* Valid reply tests */
static const struct smtp_reply_parse_valid_test
valid_reply_parse_tests[] = {
{
.reply = "220\r\n",
.status = 220,
},{
.reply = "220 \r\n",
.status = 220,
},{
.reply = "220 OK\r\n",
.status = 220,
},{
.reply = "550 Requested action not taken: mailbox unavailable\r\n",
.status = 550,
.text_lines = (const char *[])
{ "Requested action not taken: mailbox unavailable", NULL }
},{
.reply =
"250-smtp.example.com Hello client.example.org [10.0.0.1]\r\n"
"250-SIZE 52428800\r\n"
"250-PIPELINING\r\n"
"250-STARTTLS\r\n"
"250 HELP\r\n",
.status = 250,
.text_lines = (const char *[]) {
"smtp.example.com Hello client.example.org [10.0.0.1]",
"SIZE 52428800",
"PIPELINING",
"STARTTLS",
"HELP",
}
},{
.reply =
"250-smtp.example.com We got some nice '\x03' and '\x04'\r\n"
"250 HELP\r\n",
.status = 250,
.text_lines = (const char *[]) {
"smtp.example.com We got some nice ' ' and ' '",
"HELP",
}
},{
.reply =
"250 smtp.example.com We got some nice '\x08'\r\n",
.status = 250,
.text_lines = (const char *[]) {
"smtp.example.com We got some nice ' '",
}
},{
.reply = "250 2.1.0 Originator <frop@example.com> ok\r\n",
.status = 250,
.text_lines = (const char *[]){
"Originator <frop@example.com> ok", NULL
}
},{
.reply =
"551-5.7.1 Forwarding to remote hosts disabled\r\n"
"551 5.7.1 Select another host to act as your forwarder\r\n",
.status = 551,
.text_lines = (const char *[]) {
"Forwarding to remote hosts disabled",
"Select another host to act as your forwarder",
}
}
};
unsigned int valid_reply_parse_test_count =
static void test_smtp_reply_parse_valid(void)
{
unsigned int i;
for (i = 0; i < valid_reply_parse_test_count; i++) T_BEGIN {
const char *error;
int ret;
test = &valid_reply_parse_tests[i];
while ((ret=smtp_reply_parse_ehlo
}
} else {
while ((ret=smtp_reply_parse_next
}
}
if (ret == 0) {
/* verify last response only */
if (test->enhanced_code.x > 0) {
}
unsigned int index = 0;
if (*reply_line == NULL) {
FALSE);
break;
}
line++;
reply_line++;
index++;
}
} else {
}
}
test_end();
} T_END;
}
struct smtp_reply_parse_invalid_test {
const char *reply;
bool ehlo;
};
static const struct smtp_reply_parse_invalid_test
{
.reply = "22X OK\r\n"
},{
.reply = "220OK\r\n"
},{
.reply =
"200-This is\r\n"
"250 inconsistent.\r\n"
},{
.reply = "400 This \r is wrong\r\n"
},{
.reply = "500 This is \x03 worse\r\n"
},{
.reply = "699 Obscure\r\n"
},{
.reply = "100 Invalid\r\n"
},{
.reply = "400 Interrupted\r"
},{
},{
.reply =
"250-example.com Hello\r\n"
"250 We got some '\x08' for you\r\n",
},{
.reply =
"556-This is a very long reply\r\n"
"556 that exceeds the very low limit.\r\n",
.max_size = 50
}
};
unsigned int invalid_reply_parse_test_count =
static void test_smtp_reply_parse_invalid(void)
{
unsigned int i;
for (i = 0; i < invalid_reply_parse_test_count; i++) T_BEGIN {
int ret;
test = &invalid_reply_parse_tests[i];
else
test_end();
} T_END;
}
int main(void)
{
static void (*test_functions[])(void) = {
};
return test_run(test_functions);
}