Browse Source

[Test] Add composites test

tags/1.8.2
Alexander Moisseev 5 years ago
parent
commit
046e1b263a

+ 57
- 0
test/functional/cases/109_composites.robot View File

@@ -0,0 +1,57 @@
*** Settings ***
Suite Setup Generic Setup
Suite Teardown Simple Teardown
Library ${TESTDIR}/lib/rspamd.py
Resource ${TESTDIR}/lib/rspamd.robot
Variables ${TESTDIR}/lib/vars.py

*** Variables ***
${CONFIG} ${TESTDIR}/configs/composites.conf
${LUA_SCRIPT} ${TESTDIR}/lua/composites.lua
${MESSAGE} ${TESTDIR}/messages/spam_message.eml
${RSPAMD_SCOPE} Suite

*** Test Cases ***
Composites - Score
${result} = Scan Message With Rspamc ${MESSAGE}
Check Rspamc ${result} ${SPACE}46.00 / 0.00

Composites - Expressions
${result} = Scan Message With Rspamc ${MESSAGE}
Check Rspamc ${result} EXPRESSIONS (5.00)
Should Contain ${result.stdout} EXPRESSIONS_B (0.00)

Composites - Policy: remove_weight
${result} = Scan Message With Rspamc ${MESSAGE}
Check Rspamc ${result} ${SPACE}POLICY_REMOVE_WEIGHT (5.00)
Should Not Contain ${result.stdout} ${SPACE}POLICY_REMOVE_WEIGHT_A (1.00)
Should Contain ${result.stdout} ${SPACE}POLICY_REMOVE_WEIGHT_B (0.00)

Composites - Policy: force removing
${result} = Scan Message With Rspamc ${MESSAGE}
Check Rspamc ${result} ${SPACE}POLICY_FORCE_REMOVE (5.00)
Should Contain ${result.stdout} ${SPACE}POLICY_FORCE_REMOVE_A (1.00)
Should Not Contain ${result.stdout} ${SPACE}POLICY_FORCE_REMOVE_B

Composites - Policy: leave
${result} = Scan Message With Rspamc ${MESSAGE}
Check Rspamc ${result} ${SPACE}POLICY_LEAVE (5.00)
Should Not Contain ${result.stdout} ${SPACE}POLICY_LEAVE_A
Should Contain ${result.stdout} ${SPACE}POLICY_LEAVE_B (1.00)

Composites - Default policy: remove_weight
${result} = Scan Message With Rspamc ${MESSAGE}
Check Rspamc ${result} DEFAULT_POLICY_REMOVE_WEIGHT (5.00)
Should Contain ${result.stdout} DEFAULT_POLICY_REMOVE_WEIGHT_A (0.00)
Should Contain ${result.stdout} DEFAULT_POLICY_REMOVE_WEIGHT_B (0.00)

Composites - Default policy: remove_symbol
${result} = Scan Message With Rspamc ${MESSAGE}
Check Rspamc ${result} DEFAULT_POLICY_REMOVE_SYMBOL (5.00)
Should Not Contain ${result.stdout} DEFAULT_POLICY_REMOVE_SYMBOL_

Composites - Default policy: leave
${result} = Scan Message With Rspamc ${MESSAGE}
Check Rspamc ${result} DEFAULT_POLICY_LEAVE (5.00)
Should Contain ${result.stdout} DEFAULT_POLICY_LEAVE_A (1.00)
Should Contain ${result.stdout} DEFAULT_POLICY_LEAVE_B (1.00)

+ 64
- 0
test/functional/configs/composites.conf View File

@@ -0,0 +1,64 @@
options = {
pidfile = "${TMPDIR}/rspamd.pid"
}
logging = {
type = "file",
level = "debug"
filename = "${TMPDIR}/rspamd.log"
}

worker {
type = normal
bind_socket = ${LOCAL_ADDR}:${PORT_NORMAL}
count = 1
task_timeout = 60s;
}
worker {
type = controller
bind_socket = ${LOCAL_ADDR}:${PORT_CONTROLLER}
count = 1
secure_ip = ["127.0.0.1", "::1"];
stats_path = "${TMPDIR}/stats.ucl"
}
lua = "${TESTDIR}/lua/test_coverage.lua";
lua = ${LUA_SCRIPT};

composites {
EXPRESSIONS {
expression = "(EXPRESSIONS_A | ~EXPRESSIONS_B) & !EXPRESSIONS_C";
score = 5.0;
}

POLICY_REMOVE_WEIGHT {
expression = "POLICY_REMOVE_WEIGHT_A and ~POLICY_REMOVE_WEIGHT_B";
score = 5.0;
}
POLICY_FORCE_REMOVE {
expression = "POLICY_FORCE_REMOVE_A & ^POLICY_FORCE_REMOVE_B";
score = 5.0;
}
POLICY_FORCE_REMOVE_LEAVE {
expression = "-POLICY_FORCE_REMOVE_A and -POLICY_FORCE_REMOVE_B";
score = 5.0;
}
POLICY_LEAVE {
expression = "POLICY_LEAVE_A & -POLICY_LEAVE_B";
score = 5.0;
}

DEFAULT_POLICY_REMOVE_WEIGHT {
expression = "DEFAULT_POLICY_REMOVE_WEIGHT_A and DEFAULT_POLICY_REMOVE_WEIGHT_B";
score = 5.0;
policy = "remove_weight";
}
DEFAULT_POLICY_REMOVE_SYMBOL {
expression = "DEFAULT_POLICY_REMOVE_SYMBOL_A & DEFAULT_POLICY_REMOVE_SYMBOL_B";
score = 5.0;
policy = "remove_symbol";
}
DEFAULT_POLICY_LEAVE {
expression = "DEFAULT_POLICY_LEAVE_A & DEFAULT_POLICY_LEAVE_B";
score = 5.0;
policy = "leave";
}
}

+ 93
- 0
test/functional/lua/composites.lua View File

@@ -0,0 +1,93 @@
rspamd_config:register_symbol({
name = 'EXPRESSIONS_B',
score = 1.0,
callback = function()
return true, 'Fires always'
end
})

rspamd_config:register_symbol({
name = 'POLICY_REMOVE_WEIGHT_A',
score = 1.0,
callback = function()
return true, 'Fires always'
end
})
rspamd_config:register_symbol({
name = 'POLICY_REMOVE_WEIGHT_B',
score = 1.0,
callback = function()
return true, 'Fires always'
end
})
rspamd_config:register_symbol({
name = 'POLICY_FORCE_REMOVE_A',
score = 1.0,
callback = function()
return true, 'Fires always'
end
})
rspamd_config:register_symbol({
name = 'POLICY_FORCE_REMOVE_B',
score = 1.0,
callback = function()
return true, 'Fires always'
end
})
rspamd_config:register_symbol({
name = 'POLICY_LEAVE_A',
score = 1.0,
callback = function()
return true, 'Fires always'
end
})
rspamd_config:register_symbol({
name = 'POLICY_LEAVE_B',
score = 1.0,
callback = function()
return true, 'Fires always'
end
})

rspamd_config:register_symbol({
name = 'DEFAULT_POLICY_REMOVE_WEIGHT_A',
score = 1.0,
callback = function()
return true, 'Fires always'
end
})
rspamd_config:register_symbol({
name = 'DEFAULT_POLICY_REMOVE_WEIGHT_B',
score = 1.0,
callback = function()
return true, 'Fires always'
end
})
rspamd_config:register_symbol({
name = 'DEFAULT_POLICY_REMOVE_SYMBOL_A',
score = 1.0,
callback = function()
return true, 'Fires always'
end
})
rspamd_config:register_symbol({
name = 'DEFAULT_POLICY_REMOVE_SYMBOL_B',
score = 1.0,
callback = function()
return true, 'Fires always'
end
})
rspamd_config:register_symbol({
name = 'DEFAULT_POLICY_LEAVE_A',
score = 1.0,
callback = function()
return true, 'Fires always'
end
})
rspamd_config:register_symbol({
name = 'DEFAULT_POLICY_LEAVE_B',
score = 1.0,
callback = function()
return true, 'Fires always'
end
})

Loading…
Cancel
Save