From f3b286c60f4f88509947be71d5d5cb8750f276b5 Mon Sep 17 00:00:00 2001 From: Andrew Lewis Date: Mon, 15 Aug 2016 10:43:46 +0100 Subject: [PATCH] [Test] Add test for multimap URL maps & filters --- test/functional/cases/102_multimap.robot | 59 ++++++++++++++++++++++++ test/functional/configs/multimap.conf | 30 ++++++++++++ test/functional/messages/url1.eml | 3 ++ test/functional/messages/url2.eml | 3 ++ test/functional/messages/url3.eml | 3 ++ test/functional/messages/url4.eml | 4 ++ 6 files changed, 102 insertions(+) create mode 100644 test/functional/messages/url1.eml create mode 100644 test/functional/messages/url2.eml create mode 100644 test/functional/messages/url3.eml create mode 100644 test/functional/messages/url4.eml diff --git a/test/functional/cases/102_multimap.robot b/test/functional/cases/102_multimap.robot index 03db8c854..36fdb0166 100644 --- a/test/functional/cases/102_multimap.robot +++ b/test/functional/cases/102_multimap.robot @@ -11,6 +11,11 @@ ${MESSAGE} ${TESTDIR}/messages/spam_message.eml ${UTF_MESSAGE} ${TESTDIR}/messages/utf.eml ${REDIS_SCOPE} Suite ${RSPAMD_SCOPE} Suite +${URL1} ${TESTDIR}/messages/url1.eml +${URL2} ${TESTDIR}/messages/url2.eml +${URL3} ${TESTDIR}/messages/url3.eml +${URL4} ${TESTDIR}/messages/url4.eml +${URL5} ${TESTDIR}/messages/url5.eml *** Test Cases *** MAP - DNSBL HIT @@ -142,6 +147,60 @@ MAP - REDIS - FROM MISS ${result} = Scan Message With Rspamc ${MESSAGE} --from user@other.com Check Rspamc ${result} REDIS_FROMADDR inverse=1 +MAP - REDIS - URL TLD - HIT + Redis HSET hostname example.com ${EMPTY} + ${result} = Scan Message With Rspamc ${URL1} + Check Rspamc ${result} REDIS_URL_TLD + +MAP - REDIS - URL TLD - MISS + ${result} = Scan Message With Rspamc ${URL2} + Check Rspamc ${result} REDIS_URL_TLD inverse=1 + +MAP - REDIS - URL RE FULL - HIT + Redis HSET fullurlre html ${EMPTY} + ${result} = Scan Message With Rspamc ${URL2} + Check Rspamc ${result} REDIS_URL_RE_FULL + +MAP - REDIS - URL RE FULL - MISS + ${result} = Scan Message With Rspamc ${URL1} + Check Rspamc ${result} REDIS_URL_RE_FULL inverse=1 + +MAP - REDIS - URL FULL - HIT + Redis HSET fullurl https://www.example.com/foo?a=b ${EMPTY} + ${result} = Scan Message With Rspamc ${URL1} + Check Rspamc ${result} REDIS_URL_FULL + +MAP - REDIS - URL FULL - MISS + ${result} = Scan Message With Rspamc ${URL2} + Check Rspamc ${result} REDIS_URL_FULL inverse=1 + +MAP - REDIS - URL PHISHED - HIT + Redis HSET phishedurl www.rspamd.com ${EMPTY} + ${result} = Scan Message With Rspamc ${URL3} + Check Rspamc ${result} REDIS_URL_PHISHED + +MAP - REDIS - URL PHISHED - MISS + ${result} = Scan Message With Rspamc ${URL4} + Check Rspamc ${result} REDIS_URL_PHISHED inverse=1 + +MAP - REDIS - URL PLAIN REGEX - HIT + Redis HSET urlre www ${EMPTY} + ${result} = Scan Message With Rspamc ${URL3} + Check Rspamc ${result} REDIS_URL_RE_PLAIN + +MAP - REDIS - URL PLAIN REGEX - MISS + ${result} = Scan Message With Rspamc ${URL4} + Check Rspamc ${result} REDIS_URL_RE_PLAIN inverse=1 + +MAP - REDIS - URL TLD REGEX - HIT + Redis HSET tldre net ${EMPTY} + ${result} = Scan Message With Rspamc ${URL5} + Check Rspamc ${result} REDIS_URL_RE_TLD + +MAP - REDIS - URL TLD REGEX - MISS + ${result} = Scan Message With Rspamc ${URL4} + Check Rspamc ${result} REDIS_URL_RE_TLD inverse=1 + *** Keywords *** Multimap Setup ${PLUGIN_CONFIG} = Get File ${TESTDIR}/configs/multimap.conf diff --git a/test/functional/configs/multimap.conf b/test/functional/configs/multimap.conf index 7c75c7a91..e993b1f7d 100644 --- a/test/functional/configs/multimap.conf +++ b/test/functional/configs/multimap.conf @@ -62,4 +62,34 @@ multimap { filter = "email:addr"; map = "redis://emailaddr"; } + REDIS_URL_TLD { + type = "url"; + map = "redis://hostname"; + filter = "tld"; + } + REDIS_URL_RE_FULL { + type = "url"; + map = "redis://fullurlre"; + filter = "full:regexp:/(html)$/"; + } + REDIS_URL_FULL { + type = "url"; + map = "redis://fullurl"; + filter = "full"; + } + REDIS_URL_PHISHED { + type = "url"; + map = "redis://phishedurl"; + filter = "is_phished"; + } + REDIS_URL_RE_TLD { + type = "url"; + map = "redis://tldre"; + filter = "tld:regexp:/(net)$/"; + } + REDIS_URL_RE_PLAIN { + type = "url"; + map = "redis://urlre"; + filter = "regexp:/^(www)/"; + } } diff --git a/test/functional/messages/url1.eml b/test/functional/messages/url1.eml new file mode 100644 index 000000000..42361ae2d --- /dev/null +++ b/test/functional/messages/url1.eml @@ -0,0 +1,3 @@ +Content-Type: text/plain + +hello https://www.example.com/foo?a=b hello diff --git a/test/functional/messages/url2.eml b/test/functional/messages/url2.eml new file mode 100644 index 000000000..bfa72535f --- /dev/null +++ b/test/functional/messages/url2.eml @@ -0,0 +1,3 @@ +Content-Type: text/plain + +hello https://www.rspamd.com/doc/modules/multimap.html hello diff --git a/test/functional/messages/url3.eml b/test/functional/messages/url3.eml new file mode 100644 index 000000000..eabfd983b --- /dev/null +++ b/test/functional/messages/url3.eml @@ -0,0 +1,3 @@ +Content-Type: text/html + +hello https://www.bank.com hello diff --git a/test/functional/messages/url4.eml b/test/functional/messages/url4.eml new file mode 100644 index 000000000..eba4f873e --- /dev/null +++ b/test/functional/messages/url4.eml @@ -0,0 +1,4 @@ +Content-Type: text/html + +hello https://rspamd.tk hello +hello https://rspamd.com hello -- 2.39.5