]> source.dussan.org Git - rspamd.git/commitdiff
[Test] Fix email address parsing test
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 30 Mar 2018 08:59:53 +0000 (09:59 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 30 Mar 2018 08:59:53 +0000 (09:59 +0100)
test/lua/unit/addr.lua
test/lua/unit/smtp_addr.lua

index ca9b323efe776f67f71375399219366234a5f57d..6ec058c3fbd5c7a333624d1fe745fa002ad564f2 100644 (file)
@@ -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
index c07d33fda09c492e1cb653ba9c1ffa2a48d70f25..062c509d56c217a554116ce52f777ae4fed38b89 100644 (file)
@@ -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 = ''}},
-      {'<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-b@ex-ample.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 = ''}},
+    {'<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-b@ex-ample.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()
       '<a@example.com',
       'a@example.com>',
       '<a@.example.com>',
-      '<a@example.com.>',
       '<a@example.com>>',
       '<a@example.com><>',
     }
 
-    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