From 745bc065bb4ad94296bb61c2d1338fb9f433025f Mon Sep 17 00:00:00 2001 From: Andrew Lewis Date: Tue, 5 Sep 2017 15:08:51 +0200 Subject: [PATCH] [Test] Some tests for whitelist module --- test/functional/cases/123_whitelist.robot | 52 +++++++++++ test/functional/configs/maps/domains.list | 3 +- test/functional/configs/whitelist.conf | 101 ++++++++++++++++++++++ 3 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 test/functional/cases/123_whitelist.robot create mode 100644 test/functional/configs/whitelist.conf diff --git a/test/functional/cases/123_whitelist.robot b/test/functional/cases/123_whitelist.robot new file mode 100644 index 000000000..9ca57b9ec --- /dev/null +++ b/test/functional/cases/123_whitelist.robot @@ -0,0 +1,52 @@ +*** Settings *** +Suite Setup Whitelist Setup +Suite Teardown Normal Teardown +Library ${TESTDIR}/lib/rspamd.py +Resource ${TESTDIR}/lib/rspamd.robot +Variables ${TESTDIR}/lib/vars.py + +*** Variables *** +${CONFIG} ${TESTDIR}/configs/plugins.conf +${M_DMARC_OK} ${TESTDIR}/messages/dmarc/pass_none.eml +${M_DMARC_BAD} ${TESTDIR}/messages/dmarc/fail_none.eml +${UTF_MESSAGE} ${TESTDIR}/messages/utf.eml +${RSPAMD_SCOPE} Suite +${URL_TLD} ${TESTDIR}/../lua/unit/test_tld.dat + +*** Test Cases *** +WHITELISTS + ${result} = Scan Message With Rspamc ${M_DMARC_OK} -i 8.8.4.4 -F foo@spf.cacophony.za.org + Check Rspamc ${result} WHITELIST_DKIM (-1 + Should Contain ${result.stdout} STRICT_DMARC (-3 + Should Contain ${result.stdout} WHITELIST_DDS (-3 + Should Contain ${result.stdout} WHITELIST_DMARC (-2 + Should Contain ${result.stdout} WHITELIST_DMARC_DKIM (-2 + Should Contain ${result.stdout} WHITELIST_SPF (-1 + Should Not Contain ${result.stdout} BLACKLIST_SPF ( + Should Not Contain ${result.stdout} BLACKLIST_DKIM ( + Should Not Contain ${result.stdout} BLACKLIST_DMARC ( + +BLACKLIST SHOULD FIRE IF ANY CONSTRAINT FAILED + ${result} = Scan Message With Rspamc ${M_DMARC_OK} -i 9.8.4.4 -F foo@spf.cacophony.za.org + Check Rspamc ${result} BLACKLIST_DDS (3 + Should Not Contain ${result.stdout} WHITELIST_DDS ( + Should Not Contain ${result.stdout} WHITELIST_SPF ( + +BLACKLISTS + ${result} = Scan Message With Rspamc ${M_DMARC_BAD} -i 9.8.4.4 -F foo@cacophony.za.org + Check Rspamc ${result} BLACKLIST_SPF (3 + Should Contain ${result.stdout} BLACKLIST_SPF (3 + Should Contain ${result.stdout} STRICT_DMARC (3 + Should Contain ${result.stdout} BLACKLIST_DDS (3 + Should Contain ${result.stdout} BLACKLIST_DMARC (3 + Should Not Contain ${result.stdout} WHITELIST_DDS ( + Should Not Contain ${result.stdout} WHITELIST_SPF ( + Should Not Contain ${result.stdout} WHITEIST_DKIM ( + Should Not Contain ${result.stdout} WHITELIST_DMARC ( + Should Not Contain ${result.stdout} WHITELIST_DMARC_DKIM ( + +*** Keywords *** +Whitelist Setup + ${PLUGIN_CONFIG} = Get File ${TESTDIR}/configs/whitelist.conf + Set Suite Variable ${PLUGIN_CONFIG} + Generic Setup PLUGIN_CONFIG diff --git a/test/functional/configs/maps/domains.list b/test/functional/configs/maps/domains.list index 2d8e6387d..f0b635852 100644 --- a/test/functional/configs/maps/domains.list +++ b/test/functional/configs/maps/domains.list @@ -1,2 +1,3 @@ example.com -#other.com \ No newline at end of file +cacophony.za.org +#other.com diff --git a/test/functional/configs/whitelist.conf b/test/functional/configs/whitelist.conf new file mode 100644 index 000000000..9b8c3af63 --- /dev/null +++ b/test/functional/configs/whitelist.conf @@ -0,0 +1,101 @@ +dmarc {} + +whitelist { + + rules { + "BLACKLIST_DDS" = { + blacklist = true; + valid_dkim = true; + valid_dmarc = true; + valid_spf = true; + domains = [ + "${TESTDIR}/configs/maps/domains.list", + ]; + score = 3.0 + } + + "WHITELIST_DDS" = { + valid_dkim = true; + valid_dmarc = true; + valid_spf = true; + domains = [ + "${TESTDIR}/configs/maps/domains.list", + ]; + score = -3.0 + } + + "WHITELIST_DKIM" = { + valid_dkim = true; + domains = [ + "${TESTDIR}/configs/maps/domains.list", + ]; + description = "Mail comes from the whitelisted domain and has a valid DKIM signature"; + score = -1.0 + } + + "BLACKLIST_DKIM" = { + blacklist = true; + valid_dkim = true; + domains = [ + "${TESTDIR}/configs/maps/domains.list", + ]; + score = 3.0 + } + + "WHITELIST_SPF" = { + valid_spf = true; + domains = [ + "${TESTDIR}/configs/maps/domains.list", + ]; + score = -1.0 + description = "Mail comes from the whitelisted domain and has a valid SPF policy"; + } + + "BLACKLIST_SPF" = { + blacklist = true; + valid_spf = true; + domains = [ + "${TESTDIR}/configs/maps/domains.list", + ]; + score = 3.0 + } + + "WHITELIST_DMARC_DKIM" = { + valid_dmarc = true; + valid_dkim = true; + domains = [ + "${TESTDIR}/configs/maps/domains.list", + ]; + score = -2.0; + description = "Mail comes from the whitelisted domain and has valid DMARC and DKIM policies"; + } + + "WHITELIST_DMARC" = { + valid_dmarc = true; + domains = [ + "${TESTDIR}/configs/maps/domains.list", + ]; + score = -2.0; + description = "Mail comes from the whitelisted domain and has valid DMARC policy"; + } + + "BLACKLIST_DMARC" = { + blacklist = true; + valid_dmarc = true; + domains = [ + "${TESTDIR}/configs/maps/domains.list", + ]; + score = 3.0; + } + + "STRICT_DMARC" = { + strict = true; + valid_dmarc = true; + domains = [ + "${TESTDIR}/configs/maps/domains.list", + ]; + score = -3.0; + } + + } +} -- 2.39.5