/* Copyright (c) 2017-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-command-parser.h"
#include <time.h>
/*
* Valid command tests
*/
struct smtp_command_parse_valid_test {
const char *command;
const char *cmd_name;
const char *cmd_params;
};
static const struct smtp_command_parse_valid_test
{
.command = "RSET\r\n",
.cmd_name = "RSET",
.cmd_params = ""
}, {
.command = "RSET \r\n",
.cmd_name = "RSET",
.cmd_params = ""
}, {
.cmd_name = "EHLO",
.cmd_params = "example.com"
}, {
.cmd_name = "EHLO",
.cmd_params = "example.com"
}, {
.command = "MAIL FROM:<sender@example.com> ENVID=frop\r\n",
.cmd_name = "MAIL",
.cmd_params = "FROM:<sender@example.com> ENVID=frop"
}, {
.command = "VRFY \"Sherlock Holmes\"\r\n",
.cmd_name = "VRFY",
.cmd_params = "\"Sherlock Holmes\""
}, {
.command = "RCPT TO:<recipient@example.com> NOTIFY=NEVER\r\n",
.cmd_name = "RCPT",
.cmd_params = "TO:<recipient@example.com> NOTIFY=NEVER"
}
};
unsigned int valid_command_parse_test_count =
static void test_smtp_command_parse_valid(void)
{
unsigned int i;
for (i = 0; i < valid_command_parse_test_count; i++) T_BEGIN {
int ret;
test = &valid_command_parse_tests[i];
if (ret == 0) {
/* verify last response only */
}
test_end();
} T_END;
}
/*
* Invalid command tests
*/
struct smtp_command_parse_invalid_test {
const char *command;
};
static const struct smtp_command_parse_invalid_test
{
.command = "B52\r\n",
}, {
.command = "BELL\x08\r\n",
}, {
}, {
.command = "NOOP \"\x01\x02\x03\"\r\n",
}, {
.command = "RSET\rQUIT\r\n",
}, {
.command = "INSANELYREDICULOUSLYLONGCOMMANDNAME\r\n",
}, {
.command = "RCPT TO:<recipient@example.com> NOTIFY=NEVER\r\n",
}
};
unsigned int invalid_command_parse_test_count =
static void test_smtp_command_parse_invalid(void)
{
unsigned int i;
for (i = 0; i < invalid_command_parse_test_count; i++) T_BEGIN {
int ret;
test = &invalid_command_parse_tests[i];
test_out_quiet("error code",
test_end();
} T_END;
}
/*
* Valid auth response tests
*/
struct smtp_auth_response_parse_valid_test {
const char *auth_response;
const char *line;
};
static const struct smtp_auth_response_parse_valid_test
{
.auth_response = "U3R1cGlkIEJhc2U2NCB0ZXN0\r\n",
.line = "U3R1cGlkIEJhc2U2NCB0ZXN0"
}, {
.auth_response = "U3R1cGlkIEJhc2U2NCB0ZXN0 \r\n",
.line = "U3R1cGlkIEJhc2U2NCB0ZXN0"
}, {
"U3R1cGlkIHZlcnkgdmVyeSB2ZXJ5IHZlcnkgdmVyeS"
"B2ZXJ5IHZlcnkgdmVyeSBsb25nIEJhc2U2NCB0ZXN0\r\n",
.line = "U3R1cGlkIHZlcnkgdmVyeSB2ZXJ5IHZlcnkgdmVyeS"
"B2ZXJ5IHZlcnkgdmVyeSBsb25nIEJhc2U2NCB0ZXN0"
}
};
unsigned int valid_auth_response_parse_test_count =
static void test_smtp_auth_response_parse_valid(void)
{
unsigned int i;
for (i = 0; i < valid_auth_response_parse_test_count; i++) T_BEGIN {
int ret;
if (ret == 0) {
/* verify last response only */
}
test_end();
} T_END;
}
/*
* Invalid auth response tests
*/
const char *auth_response;
};
static const struct smtp_auth_response_parse_invalid_test
{
.auth_response = "\x01\x02\x03\r\n",
}, {
.auth_response = "U3R1cGlkIEJhc\r2U2NCB0ZXN0\r\n",
}, {
"U3R1cGlkIHZlcnkgdmVyeSB2ZXJ5IHZlcnkgdmVyeS"
"B2ZXJ5IHZlcnkgdmVyeSBsb25nIEJhc2U2NCB0ZXN0\r\n",
}
};
unsigned int invalid_auth_response_parse_test_count =
static void test_smtp_auth_response_parse_invalid(void)
{
unsigned int i;
for (i = 0; i < invalid_auth_response_parse_test_count; i++) T_BEGIN {
int ret;
"smtp auth response invalid [%d]", i));
test_out_quiet("error code",
test_end();
} T_END;
}
/*
* Tests
*/
int main(void)
{
static void (*test_functions[])(void) = {
};
return test_run(test_functions);
}