diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/cases/001_merged/101_lua.robot | 46 | ||||
-rw-r--r-- | test/functional/cases/550_milter_headers.robot | 39 | ||||
-rw-r--r-- | test/functional/configs/merged-local.conf | 39 | ||||
-rw-r--r-- | test/functional/configs/merged.conf | 1 | ||||
-rw-r--r-- | test/functional/configs/milter_headers.conf | 24 | ||||
-rw-r--r-- | test/functional/lib/rspamd.robot | 43 | ||||
-rw-r--r-- | test/functional/lua/deps.lua | 2 | ||||
-rw-r--r-- | test/functional/lua/limits.lua | 22 |
8 files changed, 214 insertions, 2 deletions
diff --git a/test/functional/cases/001_merged/101_lua.robot b/test/functional/cases/001_merged/101_lua.robot index 2cfc03677..51d5b4b23 100644 --- a/test/functional/cases/001_merged/101_lua.robot +++ b/test/functional/cases/001_merged/101_lua.robot @@ -52,4 +52,48 @@ External Maps Simple Task Inject Url Scan File ${URL_ICS} Settings={symbols_enabled = [TEST_INJECT_URL]} - Expect Symbol TEST_INJECT_URL
\ No newline at end of file + Expect Symbol TEST_INJECT_URL + +Group Score Positive + Scan File ${MESSAGE} Settings={symbols_enabled = [GR_POSITIVE1, GR_POSITIVE2, GR_POSITIVE4, GR_POSITIVE8, GR_POSITIVE16]} + Expect Symbol With Score GR_POSITIVE1 1 + Expect Symbol With Score GR_POSITIVE2 2 + Expect Symbol With Score GR_POSITIVE4 4 + Expect Symbol With Score GR_POSITIVE8 3 + Expect Symbol With Score GR_POSITIVE16 0 + +Group Score Negative + Scan File ${MESSAGE} Settings={symbols_enabled = [GR_NEGATIVE1, GR_NEGATIVE2, GR_NEGATIVE4, GR_NEGATIVE8]} + Expect Symbol With Score GR_NEGATIVE1 -1 + Expect Symbol With Score GR_NEGATIVE2 -2 + Expect Symbol With Score GR_NEGATIVE4 -4 + Expect Symbol With Score GR_NEGATIVE8 -3 + +Group Score Mix 1 + Scan File ${MESSAGE} Settings={symbols_enabled = [GR_POSITIVE1, GR_POSITIVE2, GR_POSITIVE4, GR_POSITIVE8, GR_NEGATIVE1, GR_NEGATIVE2, GR_NEGATIVE4, GR_NEGATIVE8]} + Expect Symbol With Score GR_POSITIVE1 1 + Expect Symbol With Score GR_POSITIVE2 2 + Expect Symbol With Score GR_POSITIVE4 4 + Expect Symbol With Score GR_POSITIVE8 3 + Expect Symbol With Score GR_NEGATIVE1 -1 + Expect Symbol With Score GR_NEGATIVE2 -2 + Expect Symbol With Score GR_NEGATIVE4 -4 + Expect Symbol With Score GR_NEGATIVE8 -8 + +Group Score Mix 2 + Scan File ${MESSAGE} Settings={symbols_enabled = [GR_POSITIVE1, GR_POSITIVE2, GR_POSITIVE4, GR_POSITIVE8, GR_NEGATIVE16]} + Expect Symbol With Score GR_POSITIVE1 1 + Expect Symbol With Score GR_POSITIVE2 2 + Expect Symbol With Score GR_POSITIVE4 4 + Expect Symbol With Score GR_POSITIVE8 3 + Expect Symbol With Score GR_NEGATIVE16 -16 + +Group Score Mix 3 + Scan File ${MESSAGE} Settings={symbols_enabled = [GR_POSITIVE1, GR_NEGATIVE16]} + Expect Symbol With Score GR_POSITIVE1 1 + Expect Symbol With Score GR_NEGATIVE16 -11 + +Group Score Mix 4 + Scan File ${MESSAGE} Settings={symbols_enabled = [GR_POSITIVE16, GR_NEGATIVE16]} + Expect Symbol With Score GR_POSITIVE16 10 + Expect Symbol With Score GR_NEGATIVE16 -16
\ No newline at end of file diff --git a/test/functional/cases/550_milter_headers.robot b/test/functional/cases/550_milter_headers.robot new file mode 100644 index 000000000..80471b83c --- /dev/null +++ b/test/functional/cases/550_milter_headers.robot @@ -0,0 +1,39 @@ +*** 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/milter_headers.conf +${MESSAGE} ${RSPAMD_TESTDIR}/messages/zip.eml +${RSPAMD_SCOPE} Suite +${RSPAMD_URL_TLD} ${RSPAMD_TESTDIR}/../lua/unit/test_tld.dat +${SETTINGS_NOSYMBOLS} {symbols_enabled = []} +${SETTINGS_TEST} {SIMPLE_TEST = 2.0, symbols_enabled = [SIMPLE_TEST]} + +*** Test Cases *** +CHECK HEADERS WITH TEST SYMBOL + Scan File ${MESSAGE} Settings=${SETTINGS_TEST} + # Check X-Virus header + Expect Removed Header X-Virus + Expect Added Header X-Virus Fires always + # Check My-Spamd-Bar header + Expect Added Header My-Spamd-Bar ++ + Do Not Expect Removed Header My-Spamd-Bar + # Check X-Spam-Level header + Expect Added Header X-Spam-Level ** + Expect Removed Header X-Spam-Level + +CHECK HEADERS WITHOUT TEST SYMBOL + Scan File ${MESSAGE} Settings=${SETTINGS_NOSYMBOLS} + # Check X-Virus header + Expect Removed Header X-Virus + Do Not Expect Added Header X-Virus + # Check My-Spamd-Bar header + Expect Added Header My-Spamd-Bar / + Do Not Expect Removed Header My-Spamd-Bar + # Check X-Spam-Level header + Do Not Expect Added Header X-Spam-Level + Expect Removed Header X-Spam-Level diff --git a/test/functional/configs/merged-local.conf b/test/functional/configs/merged-local.conf index 2d914b075..2aef274c2 100644 --- a/test/functional/configs/merged-local.conf +++ b/test/functional/configs/merged-local.conf @@ -965,6 +965,45 @@ symbols { } } +group "test" { + max_score = 10; + min_score = -10; + + symbols = { + "GR_POSITIVE1" = { + score = 1.0; + }, + "GR_POSITIVE2" = { + score = 2.0; + }, + "GR_POSITIVE4" = { + score = 4.0; + }, + "GR_POSITIVE8" = { + score = 8.0; + }, + "GR_POSITIVE16" = { + score = 16.0; + }, + + "GR_NEGATIVE1" = { + score = -1.0; + }, + "GR_NEGATIVE2" = { + score = -2.0; + }, + "GR_NEGATIVE4" = { + score = -4.0; + }, + "GR_NEGATIVE8" = { + score = -8.0; + }, + "GR_NEGATIVE16" = { + score = -16.0; + }, + } +} + worker "controller" { bind_socket = "{= env.LOCAL_ADDR =}:{= env.PORT_CONTROLLER =}"; keypair { diff --git a/test/functional/configs/merged.conf b/test/functional/configs/merged.conf index 0ee224ceb..06a34308d 100644 --- a/test/functional/configs/merged.conf +++ b/test/functional/configs/merged.conf @@ -11,6 +11,7 @@ lua = "{= env.TESTDIR =}/lua/recipients.lua" lua = "{= env.TESTDIR =}/lua/remove_result.lua" lua = "{= env.TESTDIR =}/lua/tlds.lua" lua = "{= env.TESTDIR =}/lua/inject_url.lua" +lua = "{= env.TESTDIR =}/lua/limits.lua" # 104_get_from lua = "{= env.TESTDIR =}/lua/get_from.lua" diff --git a/test/functional/configs/milter_headers.conf b/test/functional/configs/milter_headers.conf new file mode 100644 index 000000000..947bc28dd --- /dev/null +++ b/test/functional/configs/milter_headers.conf @@ -0,0 +1,24 @@ +lua = "{= env.TESTDIR =}/lua/simple.lua" + +.include(duplicate=append,priority=0) "{= env.TESTDIR =}/configs/plugins.conf" + +milter_headers { + + use = ["remove-headers", "x-spam-level", "x-spamd-bar", "x-virus"]; + + routines { + remove-headers { + headers { + "X-Spam-Level" = 0, + } + } + x-spamd-bar { + header = "My-Spamd-Bar"; + remove = null; + } + x-virus { + symbols = ["SIMPLE_TEST"]; + } + } + +} diff --git a/test/functional/lib/rspamd.robot b/test/functional/lib/rspamd.robot index 254a6f3ca..c45a19908 100644 --- a/test/functional/lib/rspamd.robot +++ b/test/functional/lib/rspamd.robot @@ -60,6 +60,28 @@ Check Rspamc Match String Should Not Contain ${subject} ${str} END +Do Not Expect Added Header + [Arguments] ${header_name} + IF 'milter' not in ${SCAN_RESULT} + RETURN + END + IF 'add_headers' not in ${SCAN_RESULT}[milter] + RETURN + END + Dictionary Should Not Contain Key ${SCAN_RESULT}[milter][add_headers] ${header_name} + ... msg=${header_name} was added + +Do Not Expect Removed Header + [Arguments] ${header_name} + IF 'milter' not in ${SCAN_RESULT} + RETURN + END + IF 'remove_headers' not in ${SCAN_RESULT}[milter] + RETURN + END + Dictionary Should Not Contain Key ${SCAN_RESULT}[milter][remove_headers] ${header_name} + ... msg=${header_name} was removed + Do Not Expect Symbol [Arguments] ${symbol} Dictionary Should Not Contain Key ${SCAN_RESULT}[symbols] ${symbol} @@ -76,10 +98,31 @@ Expect Action [Arguments] ${action} Should Be Equal ${SCAN_RESULT}[action] ${action} +Expect Added Header + [Arguments] ${header_name} ${header_value} ${pos}=-1 + Dictionary Should Contain Key ${SCAN_RESULT} milter + ... msg=milter block was not present in protocol response + Dictionary Should Contain Key ${SCAN_RESULT}[milter] add_headers + ... msg=add_headers block was not present in protocol response + Dictionary Should Contain Key ${SCAN_RESULT}[milter][add_headers] ${header_name} + ... msg=${header_name} was not added + Should Be Equal ${SCAN_RESULT}[milter][add_headers][${header_name}][value] ${header_value} + Should Be Equal as Numbers ${SCAN_RESULT}[milter][add_headers][${header_name}][order] ${pos} + Expect Email [Arguments] ${email} List Should Contain Value ${SCAN_RESULT}[emails] ${email} +Expect Removed Header + [Arguments] ${header_name} ${pos}=0 + Dictionary Should Contain Key ${SCAN_RESULT} milter + ... msg=milter block was not present in protocol response + Dictionary Should Contain Key ${SCAN_RESULT}[milter] remove_headers + ... msg=remove_headers block was not present in protocol response + Dictionary Should Contain Key ${SCAN_RESULT}[milter][remove_headers] ${header_name} + ... msg=${header_name} was not removed + Should Be Equal as Numbers ${SCAN_RESULT}[milter][remove_headers][${header_name}] ${pos} + Expect Required Score [Arguments] ${required_score} Should Be Equal As Numbers ${SCAN_RESULT}[required_score] ${required_score} diff --git a/test/functional/lua/deps.lua b/test/functional/lua/deps.lua index 6171db699..b78d3abb7 100644 --- a/test/functional/lua/deps.lua +++ b/test/functional/lua/deps.lua @@ -24,7 +24,7 @@ rspamd_config:register_virtual_symbol('TOP', 1.0, id) rspamd_config:register_symbol('DEP1', 1.0, cb_dep1) rspamd_config:register_dependency('DEP1', 'TOP') -for i = 2,10 do +for i = 2, 10 do rspamd_config:register_symbol('DEP' .. tostring(i), 1.0, cb_gen(i - 1)) rspamd_config:register_dependency('DEP' .. tostring(i), 'DEP' .. tostring(i - 1)) end diff --git a/test/functional/lua/limits.lua b/test/functional/lua/limits.lua new file mode 100644 index 000000000..52fb47fb9 --- /dev/null +++ b/test/functional/lua/limits.lua @@ -0,0 +1,22 @@ +local true_cb_gen = function() + return function() + return true + end +end + +local test_weights = { 1, 2, 4, 8, 16 } +for _, i in ipairs(test_weights) do + rspamd_config:register_symbol('GR_POSITIVE' .. tostring(i), 1.0, true_cb_gen()) + + if i > 1 then + rspamd_config:register_dependency('GR_POSITIVE' .. tostring(i), 'GR_POSITIVE' .. tostring(i / 2)) + end + + rspamd_config:register_symbol('GR_NEGATIVE' .. tostring(i), 1.0, true_cb_gen()) + + if i > 1 then + rspamd_config:register_dependency('GR_NEGATIVE' .. tostring(i), 'GR_NEGATIVE' .. tostring(i / 2)) + end +end + +rspamd_config:register_dependency('GR_NEGATIVE1', 'GR_POSITIVE16')
\ No newline at end of file |