From a8ed49768138129c1d4f92e1adae5803219b21cb Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 25 Apr 2016 10:09:56 +0100 Subject: [PATCH] [Test] Add more tests for smtp address --- test/lua/unit/smtp_addr.lua | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/test/lua/unit/smtp_addr.lua b/test/lua/unit/smtp_addr.lua index c221950c5..32b67afe1 100644 --- a/test/lua/unit/smtp_addr.lua +++ b/test/lua/unit/smtp_addr.lua @@ -31,12 +31,17 @@ context("SMTP address check functions", function() {'a+b@example.com', {user = 'a+b', domain = 'example.com', addr = 'a+b@example.com'}}, {'"a"@example.com', {user = 'a', domain = 'example.com', addr = 'a@example.com'}}, {'"a+b"@example.com', {user = 'a+b', domain = 'example.com', addr = 'a+b@example.com'}}, + {'"<>"@example.com', {user = '<>', domain = 'example.com', addr = '<>@example.com'}}, + {'<"<>"@example.com>', {user = '<>', domain = 'example.com', addr = '<>@example.com'}}, + {'"\\""@example.com', {user = '"', domain = 'example.com', addr = '"@example.com'}}, + {'"\\"abc"@example.com', {user = '"abc', domain = 'example.com', addr = '"abc@example.com'}}, + } each(function(case) local st = ffi.C.rspamd_email_address_from_smtp(case[1], #case[1]) - assert_not_nil(st, "cannot parse " .. case[1]) + assert_not_nil(st, "should be able to parse " .. case[1]) each(function(k, ex) if k == 'user' then @@ -52,5 +57,24 @@ context("SMTP address check functions", function() end, case[2]) ffi.C.rspamd_email_address_unref(st) end, cases_valid) + + local cases_invalid = { + 'a', + 'a"b"@example.com', + 'a"@example.com', + '"a@example.com', + '', + '', + '', + '>', + '<>', + } + + each(function(case) + local st = ffi.C.rspamd_email_address_from_smtp(case, #case) + + assert_nil(st, "should not be able to parse " .. case) + end, cases_invalid) end) end) -- 2.39.5