From 814691082a5a06e054d9523c0cd46be2a052737b Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 30 Mar 2018 09:59:53 +0100 Subject: [PATCH] [Test] Fix email address parsing test --- test/lua/unit/addr.lua | 27 ++++++++-------- test/lua/unit/smtp_addr.lua | 64 +++++++++++++++++++------------------ 2 files changed, 47 insertions(+), 44 deletions(-) diff --git a/test/lua/unit/addr.lua b/test/lua/unit/addr.lua index ca9b323ef..6ec058c3f 100644 --- a/test/lua/unit/addr.lua +++ b/test/lua/unit/addr.lua @@ -9,23 +9,24 @@ context("Inet addr check functions", function() const char *src); void rspamd_inet_address_free (rspamd_inet_addr_t *addr); ]] - - test("Create inet addr from string", function() - local cases = { - {'192.168.1.1', true}, - {'2a01:4f8:190:43b5::99', true}, - {'256.1.1.1', false}, - {'/tmp/socket', true}, - {'./socket', true}, - } - - for _,c in ipairs(cases) do + + local cases = { + {'192.168.1.1', true}, + {'2a01:4f8:190:43b5::99', true}, + {'256.1.1.1', false}, + {'/tmp/socket', true}, + {'./socket', true}, + } + + for i,c in ipairs(cases) do + test("Create inet addr from string " .. i, function() local ip = ffi.new("rspamd_inet_addr_t* [1]"); local res = ffi.C.rspamd_parse_inet_address(ip, c[1]) assert_equal(res, c[2], "Expect " .. tostring(c[2]) .. " while parsing " .. c[1]) if res then ffi.C.rspamd_inet_address_free(ip[0]) end - end - end) + end) + + end end) \ No newline at end of file diff --git a/test/lua/unit/smtp_addr.lua b/test/lua/unit/smtp_addr.lua index c07d33fda..062c509d5 100644 --- a/test/lua/unit/smtp_addr.lua +++ b/test/lua/unit/smtp_addr.lua @@ -15,40 +15,40 @@ context("SMTP address check functions", function() unsigned raw_len; unsigned addr_len; - unsigned user_len; unsigned domain_len; - unsigned name_len; - int flags; + uint16_t user_len; + unsigned char flags; }; struct rspamd_email_address * rspamd_email_address_from_smtp (const char *str, unsigned len); void rspamd_email_address_free (struct rspamd_email_address *addr); ]] - test("Parse addrs", function() - local cases_valid = { - {'<>', {addr = ''}}, - {'', {user = 'a', domain = 'example.com', addr = 'a@example.com'}}, - {'', {user = 'a-b', domain = 'example.com', addr = 'a-b@example.com'}}, - {'', {user = 'a-b', domain = 'ex-ample.com', addr = 'a-b@ex-ample.com'}}, - {'1367=dec2a6ce-81bd-4fa9-ad02-ec5956466c04=9=1655370@example.220-volt.ru', - {user = '1367=dec2a6ce-81bd-4fa9-ad02-ec5956466c04=9=1655370', - domain = 'example.220-volt.ru', - addr = '1367=dec2a6ce-81bd-4fa9-ad02-ec5956466c04=9=1655370@example.220-volt.ru'}}, - {'notification+kjdm---m7wwd@facebookmail.com', {user = 'notification+kjdm---m7wwd'}}, - {'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'}}, - {'"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'}}, - {'<@domain1,@domain2,@domain3:abc@example.com>', - {user = 'abc', domain = 'example.com', addr = 'abc@example.com'}}, + local cases_valid = { + {'<>', {addr = ''}}, + {'', {user = 'a', domain = 'example.com', addr = 'a@example.com'}}, + {'', {user = 'a-b', domain = 'example.com', addr = 'a-b@example.com'}}, + {'', {user = 'a-b', domain = 'ex-ample.com', addr = 'a-b@ex-ample.com'}}, + {'1367=dec2a6ce-81bd-4fa9-ad02-ec5956466c04=9=1655370@example.220-volt.ru', + {user = '1367=dec2a6ce-81bd-4fa9-ad02-ec5956466c04=9=1655370', + domain = 'example.220-volt.ru', + addr = '1367=dec2a6ce-81bd-4fa9-ad02-ec5956466c04=9=1655370@example.220-volt.ru'}}, + {'notification+kjdm---m7wwd@facebookmail.com', {user = 'notification+kjdm---m7wwd'}}, + {'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'}}, + {'"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'}}, + {'<@domain1,@domain2,@domain3:abc@example.com>', + {user = 'abc', domain = 'example.com', addr = 'abc@example.com'}}, + + } - } - each(function(case) + each(function(case) + test("Parse valid smtp addr: " .. case[1], function() local st = ffi.C.rspamd_email_address_from_smtp(case[1], #case[1]) assert_not_nil(st, "should be able to parse " .. case[1]) @@ -66,7 +66,8 @@ context("SMTP address check functions", function() end end, case[2]) ffi.C.rspamd_email_address_free(st) - end, cases_valid) + end) + end, cases_valid) local cases_invalid = { 'a', @@ -76,17 +77,18 @@ context("SMTP address check functions", function() '', '', - '', '>', '<>', } - each(function(case) + each(function(case) + test("Parse invalid smtp addr: " .. case, function() 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) + end, cases_invalid) + test("Speed test", function() local case = '<@domain1,@domain2,@domain3:abc%d@example.com>' local niter = 100000 -- 2.39.5