]> source.dussan.org Git - rspamd.git/commitdiff
[Test] Add tests for pct=0 case
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 28 Nov 2018 12:39:48 +0000 (12:39 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 28 Nov 2018 12:39:48 +0000 (12:39 +0000)
src/plugins/lua/dmarc.lua
test/functional/cases/115_dmarc.robot
test/functional/configs/plugins.conf
test/functional/messages/dmarc/pct_none.eml [new file with mode: 0644]

index b55c5d41f68e3945b1bb4f730c22b1915e7c7976..af43a5b8ce441c163467f5f7b4001ddbc0f8a627 100644 (file)
@@ -415,12 +415,15 @@ local function dmarc_validate_policy(task, policy, hdrfromdom, dmarc_esld)
           policy.domain .. ' : ' .. reason_str, policy.dmarc_policy)
       disposition = what
     else
-      if (math.random(100) > policy.pct) then
+      local coin = math.random(100)
+      if (coin > policy.pct) then
         if (not no_sampling_domains or
             not no_sampling_domains:get_key(policy.domain)) then
           task:insert_result(dmarc_symbols['softfail'], 1.0,
               policy.domain .. ' : ' .. reason_str, policy.dmarc_policy, "sampled_out")
           sampled_out = true
+          lua_util.debugm(N, task, 'changed dmarc policy from %s to %s, sampled out: %s < %s',
+              what, 'softfail', coin, policy.pct)
         else
           task:insert_result(dmarc_symbols[what], 1.0,
               policy.domain .. ' : ' .. reason_str, policy.dmarc_policy, "local_policy")
index c68927115f941b519939c21945411105e1888de3..93bce71dafc79127731c964a6ab34c2bb29ea760 100644 (file)
@@ -77,6 +77,11 @@ DMARC NA NXDOMAIN
   ...  -i  37.48.67.26  --from  foo@mom.za.org
   Check Rspamc  ${result}  DMARC_NA
 
+DMARC PCT ZERO
+  ${result} =  Scan Message With Rspamc  ${TESTDIR}/messages/dmarc/pct_none.eml
+  ...  -i  37.48.67.26  --from  foo@mom.za.org
+  Check Rspamc  ${result}  DMARC_POLICY_SOFTFAIL
+
 DKIM PERMFAIL NXDOMAIN
   ${result} =  Scan Message With Rspamc  ${TESTDIR}/messages/dmarc/bad_dkim2.eml
   ...  -i  37.48.67.26
index ecff3eabf0908814bd649d8fa29b98d53439382f..b34f662085f7ffce8b07e43b6ece21b227feea42 100644 (file)
@@ -242,6 +242,11 @@ options = {
           type = "txt";
           rcode = 'nxdomain';
         },
+        {
+          name = "_dmarc.zero_pct.com",
+          type = "txt";
+          replies = ["v=DMARC1; p=reject; sp=quarantine; pct=0"];
+        },
         {
           name = "example.com",
           type = "txt";
diff --git a/test/functional/messages/dmarc/pct_none.eml b/test/functional/messages/dmarc/pct_none.eml
new file mode 100644 (file)
index 0000000..50fe331
--- /dev/null
@@ -0,0 +1,17 @@
+Date: Tue, 09 Aug 2016 10:01:27 +0200
+Message-ID: <20160809100128@rspamd.tk>
+From: Rspamd <foo@zero_pct.com>
+To: foo@rspamd.tk
+Subject: hello
+Content-Type: text/plain; charset=utf-8; format=flowed; DelSp=Yes
+MIME-Version: 1.0
+Content-Disposition: inline
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rspamd.tk; s=testdkim;
+       t=1470729879; h=from:subject:date:message-id:to:mime-version:content-type;
+       bh=7HkRgYnNru3SR2EWfgWU8yhM0MOH6ZZrPoEIgNIh8wc=;
+       b=kTIV4jcgv9sWFh2JFrS/+PcNxiloituqjmHHqeJOTfa+/9C+Er8BjnMysTJyYVq36Gnv0OZDgLr3Yy4YP5Lzbt1M9ZdN5cJqO7yn1N7wyaGfkt++b09rIYBy5Dkk7OWyP3cDThqDzv8C9heSvqBSEsirFsbt3Wx2g/hWiJlnjew=
+
+
+hello
+
+