/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
#include "test-lib.h"
#include "str.h"
#include "test-common.h"
#include "smtp-address.h"
/*
* Valid mailbox parse tests
*/
struct valid_mailbox_parse_test {
};
static const struct valid_mailbox_parse_test
{
.input = "",
},{
.input = "user",
},{
.input = "user@domain.tld",
},{
.input = "1234567890@domain.tld",
.address = {
.localpart = "1234567890",
},{
.input = "_______@domain.tld",
.address = {
.localpart = "_______",
},{
.input = "firstname.lastname@domain.tld",
.address = {
.localpart = "firstname.lastname",
},{
.input = "firstname+lastname@domain.tld",
.address = {
.localpart = "firstname+lastname",
},{
.input = "firstname-lastname@domain.tld",
.address = {
.localpart = "firstname-lastname",
},{
.output = "user@domain.tld"
},{
},{
.input = "user@127.0.0.1",
},{
.input = "user@[127.0.0.1]",
},{
.input = "user@[IPv6:::1]",
},{
.input = "user@[IPv6:::127.0.0.1]",
/* Japanese deviations */
}, {
.input = "email@-example.com",
}, {
.input = ".email@example.com",
}, {
.input = "email.@example.com",
}, {
.input = "email..email@example.com",
}, {
.input = "Abc..123@example.com",
}
};
unsigned int valid_mailbox_parse_test_count =
static void test_smtp_mailbox_parse_valid(void)
{
unsigned int i;
for (i = 0; i < valid_mailbox_parse_test_count; i++) T_BEGIN {
int ret;
test = &valid_mailbox_parse_tests[i];
if (ret > 0) {
} else {
}
} else {
}
}
test_end();
} T_END;
}
/*
* Valid path parse tests
*/
struct valid_path_parse_test {
};
static const struct valid_path_parse_test
valid_path_parse_tests[] = {
{
.input = "<>",
},{
.input = "<user>",
},{
.input = "<user@domain.tld>",
},{
.input = "<@otherdomain.tld,@yetanotherdomain.tld:user@domain.tld>",
.output = "<user@domain.tld>"
}
};
unsigned int valid_path_parse_test_count =
static void test_smtp_path_parse_valid(void)
{
unsigned int i;
for (i = 0; i < valid_path_parse_test_count; i++) T_BEGIN {
int ret;
test = &valid_path_parse_tests[i];
if (ret > 0) {
if (smtp_address_isnull(address) ||
test_out("address = <>",
} else {
}
if (smtp_address_isnull(address)) {
/* nothing */
} else {
}
}
test_end();
} T_END;
}
/*
* Valid username parse tests
*/
struct valid_username_parse_test {
};
static const struct valid_username_parse_test
{
.input = "user",
.address = {
.localpart = "user",
},{
.input = "user@domain.tld",
.address = {
.localpart = "user",
},{
.input = "user@domain.tld",
.address = {
.localpart = "user",
},{
.input = "1234567890@domain.tld",
.address = {
.localpart = "1234567890",
},{
.input = "_______@domain.tld",
.address = {
.localpart = "_______",
},{
.input = "firstname.lastname@domain.tld",
.address = {
.localpart = "firstname.lastname",
},{
.input = "firstname+lastname@domain.tld",
.address = {
.localpart = "firstname+lastname",
},{
.input = "firstname-lastname@domain.tld",
.address = {
.localpart = "firstname-lastname",
},{
.output = "user@domain.tld"
},{
},{
.input = "user@frop@domain.tld",
},{
.input = "user@127.0.0.1",
},{
.input = "user@[127.0.0.1]",
},{
.input = "user@[IPv6:::1]",
},{
.input = "user@[IPv6:::127.0.0.1]",
}
};
unsigned int valid_username_parse_test_count =
static void test_smtp_username_parse_valid(void)
{
unsigned int i;
for (i = 0; i < valid_username_parse_test_count; i++) T_BEGIN {
int ret;
test = &valid_username_parse_tests[i];
if (ret > 0) {
if (smtp_address_isnull(address) ||
test_out("address = <>",
} else {
}
if (smtp_address_isnull(address)) {
/* nothing */
} else {
}
}
test_end();
} T_END;
}
/*
* Invalid mailbox parse tests
*/
struct invalid_mailbox_parse_test {
const char *input;
};
static const struct invalid_mailbox_parse_test
{
.input = "",
}, {
.input = "user",
}, {
.input = "\"user@domain.tld",
}, {
.input = "us\"er@domain.tld",
}, {
.input = "user@frop@domain.tld",
}, {
.input = "user@.tld",
}, {
.input = "user@a$.tld",
}, {
.input = "user@a..tld",
}, {
.input = "user@[]",
}, {
.input = "user@[",
}, {
.input = "user@[AA]",
}, {
.input = "user@[AA",
}, {
.input = "user@[127.0.0]",
}, {
.input = "user@[256.256.256.256]",
}, {
.input = "user@[127.0.0.1",
}, {
.input = "user@[::1]",
}, {
.input = "user@[IPv6:flierp]",
}, {
.input = "user@[IPv6:aa:bb::cc::dd]",
}, {
.input = "user@[IPv6::1]",
}, {
.input = "user@[IPv6:::1",
}, {
.input = "user@[Gen:]",
}, {
.input = "user@[Gen:Hopsa",
}, {
.input = "user@[Gen-:Hopsa]",
}, {
.input = "#@%^%#$@#$@#.com",
}, {
}, {
.input = "Eric Mail <email@example.com>",
}, {
.input = "email.example.com",
}, {
.input = "email@example@example.com",
}, {
}, {
.input = "email@example.com (Eric Mail)",
}, {
.input = "email@example..com",
#if 0 /* These deviations are allowed (maybe implement strict mode) */
}, {
.input = "email@-example.com",
}, {
.input = ".email@example.com",
}, {
.input = "email.@example.com",
}, {
.input = "email..email@example.com",
}, {
.input = "Abc..123@example.com"
#endif
}
};
unsigned int invalid_mailbox_parse_test_count =
static void test_smtp_mailbox_parse_invalid(void)
{
unsigned int i;
for (i = 0; i < invalid_mailbox_parse_test_count; i++) T_BEGIN {
int ret;
test = &invalid_mailbox_parse_tests[i];
test_end();
} T_END;
}
/*
* Invalid path parse tests
*/
struct invalid_path_parse_test {
const char *input;
};
static const struct invalid_path_parse_test
invalid_path_parse_tests[] = {
{
.input = "",
}, {
.input = "user",
}, {
.input = "\"user@domain.tld",
}, {
.input = "us\"er@domain.tld",
}, {
.input = "user@frop@domain.tld",
}, {
.input = "user@.tld",
}, {
.input = "user@a$.tld",
}, {
.input = "user@a..tld",
}, {
.input = "user@[]",
}, {
.input = "user@[",
}, {
.input = "user@[AA]",
}, {
.input = "user@[AA",
}, {
.input = "user@[127.0.0]",
}, {
.input = "user@[256.256.256.256]",
}, {
.input = "user@[127.0.0.1",
}, {
.input = "user@[::1]",
}, {
.input = "user@[IPv6:flierp]",
}, {
.input = "user@[IPv6:aa:bb::cc::dd]",
}, {
.input = "user@[IPv6::1]",
}, {
.input = "user@[IPv6:::1",
}, {
.input = "user@[Gen:]",
}, {
.input = "user@[Gen:Hopsa",
}, {
.input = "user@[Gen-:Hopsa]",
}, {
.input = "#@%^%#$@#$@#.com",
}, {
}, {
.input = "Eric Mail <email@example.com>",
}, {
.input = "email.example.com",
}, {
.input = "email@example@example.com",
}, {
}, {
.input = "email@example.com (Eric Mail)",
}, {
.input = "email@example..com",
}, {
.input = "<>",
}, {
.input = "<user>",
}, {
.input = "<\"user@domain.tld>",
}, {
.input = "<us\"er@domain.tld>",
}, {
.input = "<user@frop@domain.tld>",
}, {
.input = "<user@.tld>",
}, {
.input = "<user@a$.tld>",
}, {
.input = "<user@a..tld>",
}, {
.input = "<user@[]>",
}, {
.input = "<user@[>",
}, {
.input = "<user@[AA]>",
}, {
.input = "<user@[AA>",
}, {
.input = "<user@[127.0.0]>",
}, {
.input = "<user@[256.256.256.256]>",
}, {
.input = "<user@[127.0.0.1>",
}, {
.input = "<user@[::1]>",
}, {
.input = "<user@[IPv6:flierp]>",
}, {
.input = "<user@[IPv6:aa:bb::cc::dd]>",
}, {
.input = "<user@[IPv6::1]>",
}, {
.input = "<user@[IPv6:::1>",
}, {
.input = "<user@[Gen:]>",
}, {
.input = "<user@[Gen:Hopsa>",
}, {
.input = "<user@[Gen-:Hopsa]>",
}, {
.input = "<#@%^%#$@#$@#.com>",
}, {
}, {
.input = "Eric Mail <email@example.com>",
}, {
.input = "<email.example.com>",
}, {
.input = "<email@example@example.com>",
}, {
}, {
.input = "<email@example.com> (Eric Mail)",
}, {
.input = "<email@example..com>",
}, {
.input = "<email@example.com",
}, {
.input = "email@example.com>",
}, {
.input = "email@example.com>",
}, {
.input = "<",
},{
.input = "<user",
},{
.input = "<@otherdomain.tld,@yetanotherdomain.tld.user@domain.tld>",
},{
}
};
unsigned int invalid_path_parse_test_count =
static void test_smtp_path_parse_invalid(void)
{
unsigned int i;
for (i = 0; i < invalid_path_parse_test_count; i++) T_BEGIN {
int ret;
test = &invalid_path_parse_tests[i];
test_end();
} T_END;
}
/*
* Invalid username parse tests
*/
struct invalid_username_parse_test {
const char *input;
};
static const struct invalid_username_parse_test
{
.input = "frop@$%^$%^.tld",
}, {
.input = "fr op@domain.tld",
}, {
.input = "f r o p@domain.tld",
}
};
unsigned int invalid_username_parse_test_count =
static void test_smtp_username_parse_invalid(void)
{
unsigned int i;
for (i = 0; i < invalid_username_parse_test_count; i++) T_BEGIN {
int ret;
test = &invalid_username_parse_tests[i];
test_end();
} T_END;
}
/*
* Address detail parsing
*/
struct address_detail_parse_test {
const char *delimiters;
const char *address;
const char *username;
const char *detail;
char delim;
};
static const struct address_detail_parse_test
{ "", "test", "test", "", '\0' },
{ "", "test+address", "test+address", "", '\0' },
{ "", "\"test:address\"", "test:address", "", '\0' },
{ "", "\"test-address:another+delim\"", "test-address:another+delim", "", '\0' },
{ "", "test@domain", "test@domain", "", '\0' },
{ "", "test+address@domain", "test+address@domain", "", '\0' },
{ "", "\"test:address\"@domain", "test:address@domain", "", '\0' },
{ "", "\"test-address:another+delim\"@domain", "test-address:another+delim@domain", "", '\0' },
{ "+-:", "test", "test", "", '\0' },
{ "+-:", "test+address", "test", "address", '+' },
{ "+-:", "\"test:address\"", "test", "address", ':' },
{ "+-:", "\"test-address:another+delim\"", "test", "address:another+delim", '-' },
{ "+-:", "test@domain", "test@domain", "", '\0' },
{ "+-:", "test+address@domain", "test@domain", "address", '+' },
{ "+-:", "\"test:address\"@domain", "test@domain", "address", ':' },
{ "+-:", "\"test-address:another+delim\"@domain", "test@domain", "address:another+delim", '-' }
};
unsigned int addresss_detail_parse_test_count =
static void test_smtp_address_detail_parse(void)
{
unsigned int i;
char delim;
int ret;
"smtp address detail parsing [%d]", i));
if (!test_has_failed()) {
}
test_end();
} T_END;
}
/*
* Tests
*/
int main(void)
{
static void (*test_functions[])(void) = {
};
return test_run(test_functions);
}