aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2024-04-11 01:14:37 +0600
committerGitHub <noreply@github.com>2024-04-11 01:14:37 +0600
commit6b23b885eb56be6d3f6717a7c5e39f5da81c2d6d (patch)
tree68b023e1637343e3d00d1831a0a5886745cc2b3b
parent46791dc651c713678f96fbf9456513b3d3c3170c (diff)
parent4f3008f9682d4edb741913b2ee2aa9cd831f7d04 (diff)
downloadrspamd-6b23b885eb56be6d3f6717a7c5e39f5da81c2d6d.tar.gz
rspamd-6b23b885eb56be6d3f6717a7c5e39f5da81c2d6d.zip
Merge pull request #4918 from fatalbanana/grow_factor_tests
Add tests for grow_factor
-rw-r--r--src/libmime/scan_result.c2
-rw-r--r--test/functional/cases/450_grow_factor.robot37
-rw-r--r--test/functional/configs/grow_factor-local.conf8
-rw-r--r--test/functional/configs/grow_factor.conf7
-rw-r--r--test/functional/lua/simple_plus.lua28
5 files changed, 81 insertions, 1 deletions
diff --git a/src/libmime/scan_result.c b/src/libmime/scan_result.c
index 09c3208cf..ad3b5ef24 100644
--- a/src/libmime/scan_result.c
+++ b/src/libmime/scan_result.c
@@ -1101,7 +1101,7 @@ void rspamd_task_result_adjust_grow_factor(struct rspamd_task *task,
/* Adjust factor by selecting all symbols and checking those with positive scores */
kh_foreach(result->symbols, kk, res, {
if (res->score > 0) {
- double mult = 1.0 - grow_factor;
+ double mult = grow_factor - 1.0;
/* We adjust the factor by the ratio of the score to the max limit */
if (max_limit > 0 && !isnan(res->score)) {
mult *= res->score / max_limit;
diff --git a/test/functional/cases/450_grow_factor.robot b/test/functional/cases/450_grow_factor.robot
new file mode 100644
index 000000000..518c3ed82
--- /dev/null
+++ b/test/functional/cases/450_grow_factor.robot
@@ -0,0 +1,37 @@
+*** Settings ***
+Suite Setup Rspamd Setup
+Suite Teardown Rspamd Teardown
+Library ${RSPAMD_TESTDIR}/lib/rspamd.py
+Resource ${RSPAMD_TESTDIR}/lib/rspamd.robot
+Variables ${RSPAMD_TESTDIR}/lib/vars.py
+
+*** Variables ***
+${CONFIG} ${RSPAMD_TESTDIR}/configs/grow_factor.conf
+${HAM_MESSAGE} ${RSPAMD_TESTDIR}/messages/ham.eml
+${RSPAMD_SCOPE} Suite
+&{RESCORED_SYMBOLS}
+... SIMPLE_TEST_001=0.013067
+... SIMPLE_TEST_002=14.374194
+... SIMPLE_TEST_003=6.533724
+... SIMPLE_TEST_004=13.067449
+... SIMPLE_TEST_005=0.013067
+... SIMPLE_TEST_006=0.130674
+... SIMPLE_TEST_007=0.143741
+... SIMPLE_TEST_008=0.156809
+... SIMPLE_TEST_009=0.169876
+... SIMPLE_TEST_010=0.182944
+... SIMPLE_TEST_011=-0.010000
+... SIMPLE_TEST_012=-0.100000
+... SIMPLE_TEST_013=-10.000000
+
+*** Test Cases ***
+CHECK BASIC
+ Scan File ${HAM_MESSAGE}
+ ... Settings={groups_enabled = [simple_tests]}
+ Expect Required Score 15
+ Expect Symbols With Scores &{RESCORED_SYMBOLS}
+
+CHECK NOREJECT
+ Scan File ${HAM_MESSAGE}
+ ... Settings={actions { reject = null, "add header" = 15 }, groups_enabled = [simple_tests]}
+ Expect Symbols With Scores &{RESCORED_SYMBOLS}
diff --git a/test/functional/configs/grow_factor-local.conf b/test/functional/configs/grow_factor-local.conf
new file mode 100644
index 000000000..cdf1bf436
--- /dev/null
+++ b/test/functional/configs/grow_factor-local.conf
@@ -0,0 +1,8 @@
+metric {
+ actions {
+ grow_factor = 1.1;
+ reject = 15;
+ "add header" = 6;
+ greylist = 4;
+ }
+}
diff --git a/test/functional/configs/grow_factor.conf b/test/functional/configs/grow_factor.conf
new file mode 100644
index 000000000..e26faa54b
--- /dev/null
+++ b/test/functional/configs/grow_factor.conf
@@ -0,0 +1,7 @@
+.include "{= env.TESTDIR =}/../../conf/rspamd.conf"
+
+lua = "{= env.TESTDIR =}/lua/simple_plus.lua"
+
+.include(priority=1,duplicate=merge) "{= env.TESTDIR =}/configs/grow_factor-local.conf"
+.include(priority=1,duplicate=merge) "{= env.TESTDIR =}/configs/merged-local.conf"
+.include(priority=2,duplicate=replace) "{= env.TESTDIR =}/configs/merged-override.conf"
diff --git a/test/functional/lua/simple_plus.lua b/test/functional/lua/simple_plus.lua
new file mode 100644
index 000000000..57aee6ae3
--- /dev/null
+++ b/test/functional/lua/simple_plus.lua
@@ -0,0 +1,28 @@
+local test_symbols = {
+ SIMPLE_TEST_001 = 0.01,
+ SIMPLE_TEST_002 = 11,
+ SIMPLE_TEST_003 = 5.0,
+ SIMPLE_TEST_004 = 10.0,
+ SIMPLE_TEST_005 = 0.01,
+ SIMPLE_TEST_006 = 0.10,
+ SIMPLE_TEST_007 = 0.11,
+ SIMPLE_TEST_008 = 0.12,
+ SIMPLE_TEST_009 = 0.13,
+ SIMPLE_TEST_010 = 0.14,
+ SIMPLE_TEST_011 = -0.01,
+ SIMPLE_TEST_012 = -0.1,
+ SIMPLE_TEST_013 = -10.0,
+}
+
+for k, v in pairs(test_symbols) do
+
+ rspamd_config:register_symbol({
+ name = k,
+ group = 'simple_tests',
+ score = v,
+ callback = function()
+ return true
+ end
+ })
+
+end