aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-23 12:28:26 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-23 14:45:27 +0100
commit49267b5a003e9145283c043bd523a037d7b38370 (patch)
tree90bdc0866e0e96209101258c8c2fc99961633d10 /test
parent6d57fbfa112799366447775d5a52974e29bf887d (diff)
downloadrspamd-49267b5a003e9145283c043bd523a037d7b38370.tar.gz
rspamd-49267b5a003e9145283c043bd523a037d7b38370.zip
[Test] Add smtp addr unit test
Diffstat (limited to 'test')
-rw-r--r--test/lua/unit/smtp_addr.lua56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/lua/unit/smtp_addr.lua b/test/lua/unit/smtp_addr.lua
new file mode 100644
index 000000000..fab197dc9
--- /dev/null
+++ b/test/lua/unit/smtp_addr.lua
@@ -0,0 +1,56 @@
+-- SMTP address parser tests
+
+context("SMTP address check functions", function()
+ local logger = require("rspamd_logger")
+ local ffi = require("ffi")
+ require "fun" ()
+ ffi.cdef[[
+ struct rspamd_email_address {
+ const char *raw;
+ const char *addr;
+ const char *user;
+ const char *domain;
+ const char *name;
+
+ unsigned raw_len;
+ unsigned addr_len;
+ unsigned user_len;
+ unsigned domain_len;
+ unsigned name_len;
+ int flags;
+ };
+ struct rspamd_email_address * rspamd_email_address_from_smtp (const char *str, unsigned len);
+ void rspamd_email_address_unref (struct rspamd_email_address *addr);
+ ]]
+
+ test("Parse addrs", function()
+ local cases_valid = {
+ {'<>', {addr = ''}},
+ {'<a@example.com>', {user = 'a', domain = 'example.com', addr = 'a@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'}},
+ {'"a"@example.com', {user = 'a', domain = 'example.com', addr = '"a"@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])
+
+ each(function(k, ex)
+ if k == 'user' then
+ local str = ffi.string(st.user, st.user_len)
+ assert_equal(str, ex)
+ elseif k == 'domain' then
+ local str = ffi.string(st.domain, st.domain_len)
+ assert_equal(str, ex)
+ elseif k == 'addr' then
+ local str = ffi.string(st.addr, st.addr_len)
+ assert_equal(str, ex)
+ end
+ end, case[1])
+ ffi.C.rspamd_email_address_unref(st)
+ end, cases_valid)
+ end)
+
+end)