summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-05-26 16:04:22 +0100
committerGitHub <noreply@github.com>2017-05-26 16:04:22 +0100
commitd7fc829253b35f2aabc2b229ba94b08bb27288a3 (patch)
tree16ad902f80374a3af61e7f38324a9421f0534807
parent32c08dba621410ac0694c89455003fdba05d2c35 (diff)
parente7c48b947fdba28117516a19a5af622f6f484690 (diff)
downloadrspamd-d7fc829253b35f2aabc2b229ba94b08bb27288a3.tar.gz
rspamd-d7fc829253b35f2aabc2b229ba94b08bb27288a3.zip
Merge pull request #1652 from fatalbanana/phishing
Phishing: fix strict_domains
-rw-r--r--src/plugins/lua/phishing.lua8
-rw-r--r--test/functional/cases/114_phishing.robot33
-rw-r--r--test/functional/configs/maps/strict.phishing1
-rw-r--r--test/functional/configs/maps/stricter.phishing1
-rw-r--r--test/functional/configs/phishing.conf7
-rw-r--r--test/functional/messages/phishing1.eml3
-rw-r--r--test/functional/messages/phishing2.eml3
-rw-r--r--test/functional/messages/phishing3.eml3
8 files changed, 56 insertions, 3 deletions
diff --git a/src/plugins/lua/phishing.lua b/src/plugins/lua/phishing.lua
index 880b85b8f..cd2288067 100644
--- a/src/plugins/lua/phishing.lua
+++ b/src/plugins/lua/phishing.lua
@@ -182,12 +182,14 @@ local function phishing_cb(task)
rspamd_logger.debugm(N, task, "distance: %1 -> %2: %3", tld, ptld, dist)
end
- local function found_in_map(map)
+ local function found_in_map(map, furl, sweight)
+ if not furl then furl = url end
+ if not sweight then sweight = weight end
if #map > 0 then
for _,rule in ipairs(map) do
- for _,dn in ipairs({url:get_tld(), url:get_host()}) do
+ for _,dn in ipairs({furl:get_tld(), furl:get_host()}) do
if rule['map']:get_key(dn) then
- task:insert_result(rule['symbol'], weight, ptld .. '->' .. dn)
+ task:insert_result(rule['symbol'], sweight, ptld .. '->' .. dn)
return true
end
end
diff --git a/test/functional/cases/114_phishing.robot b/test/functional/cases/114_phishing.robot
new file mode 100644
index 000000000..dd2d3c806
--- /dev/null
+++ b/test/functional/cases/114_phishing.robot
@@ -0,0 +1,33 @@
+*** Settings ***
+Suite Setup Phishing Setup
+Suite Teardown Simple Teardown
+Library ${TESTDIR}/lib/rspamd.py
+Resource ${TESTDIR}/lib/rspamd.robot
+Variables ${TESTDIR}/lib/vars.py
+
+*** Variables ***
+${CONFIG} ${TESTDIR}/configs/plugins.conf
+${MESSAGE1} ${TESTDIR}/messages/phishing1.eml
+${MESSAGE2} ${TESTDIR}/messages/phishing2.eml
+${MESSAGE3} ${TESTDIR}/messages/phishing3.eml
+${RSPAMD_SCOPE} Suite
+${URL_TLD} ${TESTDIR}/../../contrib/publicsuffix/effective_tld_names.dat
+
+*** Test Cases ***
+TEST PHISHING
+ ${result} = Scan Message With Rspamc ${MESSAGE1}
+ Check Rspamc ${result} ${SPACE}PHISHING
+
+TEST PHISHING STRICT ONE
+ ${result} = Scan Message With Rspamc ${MESSAGE2}
+ Check Rspamc ${result} STRICT_PHISHING
+
+TEST PHISHING STRICT TWO
+ ${result} = Scan Message With Rspamc ${MESSAGE3}
+ Check Rspamc ${result} STRICTER_PHISHING
+
+*** Keywords ***
+Phishing Setup
+ ${PLUGIN_CONFIG} = Get File ${TESTDIR}/configs/phishing.conf
+ Set Suite Variable ${PLUGIN_CONFIG}
+ Generic Setup PLUGIN_CONFIG
diff --git a/test/functional/configs/maps/strict.phishing b/test/functional/configs/maps/strict.phishing
new file mode 100644
index 000000000..af2de57b1
--- /dev/null
+++ b/test/functional/configs/maps/strict.phishing
@@ -0,0 +1 @@
+myspace.com
diff --git a/test/functional/configs/maps/stricter.phishing b/test/functional/configs/maps/stricter.phishing
new file mode 100644
index 000000000..a1240eaff
--- /dev/null
+++ b/test/functional/configs/maps/stricter.phishing
@@ -0,0 +1 @@
+bank.com
diff --git a/test/functional/configs/phishing.conf b/test/functional/configs/phishing.conf
new file mode 100644
index 000000000..3ea53a0d1
--- /dev/null
+++ b/test/functional/configs/phishing.conf
@@ -0,0 +1,7 @@
+phishing {
+ symbol = "PHISHING";
+ strict_domains = [
+ "${TESTDIR}/configs/maps/strict.phishing:STRICT_PHISHING",
+ "${TESTDIR}/configs/maps/stricter.phishing:STRICTER_PHISHING"
+ ];
+}
diff --git a/test/functional/messages/phishing1.eml b/test/functional/messages/phishing1.eml
new file mode 100644
index 000000000..d168068b4
--- /dev/null
+++ b/test/functional/messages/phishing1.eml
@@ -0,0 +1,3 @@
+Content-type: text/html
+
+lol <a href="http://www.example.net">http://www.cnn.com</a>
diff --git a/test/functional/messages/phishing2.eml b/test/functional/messages/phishing2.eml
new file mode 100644
index 000000000..575dd0b87
--- /dev/null
+++ b/test/functional/messages/phishing2.eml
@@ -0,0 +1,3 @@
+Content-type: text/html
+
+lol <a href="http://www.example.net">http://www.myspace.com</a>
diff --git a/test/functional/messages/phishing3.eml b/test/functional/messages/phishing3.eml
new file mode 100644
index 000000000..8ec9af550
--- /dev/null
+++ b/test/functional/messages/phishing3.eml
@@ -0,0 +1,3 @@
+Content-type: text/html
+
+lol <a href="http://www.example.net">http://www.bank.com</a>