]> source.dussan.org Git - rspamd.git/commitdiff
[Test] Add more tests for smtp address
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 25 Apr 2016 09:09:56 +0000 (10:09 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 25 Apr 2016 09:09:56 +0000 (10:09 +0100)
test/lua/unit/smtp_addr.lua

index c221950c53e6a4e370f37405bf2cea0075e04215..32b67afe1a7487b7ef014f05678f31b08d7b5881 100644 (file)
@@ -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',
+      '<a@example.com',
+      'a@example.com>',
+      '<a@.example.com>',
+      '<a@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)