From: Vsevolod Stakhov Date: Sat, 4 Oct 2025 18:41:27 +0000 (+0100) Subject: [Test] Add functional tests for HTML fuzzy hashing X-Git-Tag: 3.14.0~87^2~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=505420e53a90fab8bf625edb84821d8156179e9a;p=thirdparty%2Frspamd.git [Test] Add functional tests for HTML fuzzy hashing Add Robot Framework tests for HTML fuzzy matching: - html_template_1.eml: legitimate newsletter template - html_template_1_variation.eml: same structure, different text - html_phishing.eml: same structure, phishing CTA domains - html-fuzzy.robot: test suite with add/check/phishing scenarios Tests verify: - HTML fuzzy hash generation and matching - Template variation detection (same structure, different content) - Phishing detection (same structure, different CTA domains) - Integration with fuzzy storage backend --- diff --git a/test/functional/cases/120_fuzzy/html-fuzzy.robot b/test/functional/cases/120_fuzzy/html-fuzzy.robot new file mode 100644 index 0000000000..3cdc1c4e54 --- /dev/null +++ b/test/functional/cases/120_fuzzy/html-fuzzy.robot @@ -0,0 +1,49 @@ +*** Settings *** +Suite Setup HTML Fuzzy Setup +Suite Teardown Rspamd Redis Teardown +Resource lib.robot + +*** Variables *** +${HTML_TEMPLATE_1} ${RSPAMD_TESTDIR}/messages/html_template_1.eml +${HTML_TEMPLATE_1_VAR} ${RSPAMD_TESTDIR}/messages/html_template_1_variation.eml +${HTML_PHISHING} ${RSPAMD_TESTDIR}/messages/html_phishing.eml +${FLAG_HTML_WHITE} 100 +${FLAG_HTML_SPAM} 101 + +*** Keywords *** +HTML Fuzzy Setup + Set Suite Variable ${RSPAMD_FUZZY_ALGORITHM} mumhash + Set Suite Variable ${RSPAMD_FUZZY_SERVER_MODE} servers + Set Suite Variable ${SETTINGS_FUZZY_CHECK} servers = "${RSPAMD_LOCAL_ADDR}:${RSPAMD_PORT_FUZZY}"; html_shingles = true; min_html_tags = 5; + Rspamd Redis Setup + +HTML Fuzzy Add Whitelist + [Documentation] Learn legitimate HTML template + ${result} = Run Rspamc -h ${RSPAMD_LOCAL_ADDR}:${RSPAMD_PORT_CONTROLLER} -w 10 -f ${FLAG_HTML_WHITE} fuzzy_add ${HTML_TEMPLATE_1} + Check Rspamc ${result} + Sync Fuzzy Storage + +HTML Fuzzy Check Variation + [Documentation] Check variation of same template (different text, same structure) + Scan File ${HTML_TEMPLATE_1_VAR} + Expect Symbol R_TEST_FUZZY_DENIED + ${symbols} = Get Rspamd Symbols + Log Fuzzy symbols: ${symbols} + +HTML Fuzzy Check Phishing + [Documentation] Check phishing email (same structure, different CTA domains) + Scan File ${HTML_PHISHING} + # Should match structure but CTA differs + # Depending on CTA weight, might have lower score or specific handling + ${symbols} = Get Rspamd Symbols + Log Phishing check symbols: ${symbols} + +*** Test Cases *** +HTML Fuzzy Add Whitelist Test + HTML Fuzzy Add Whitelist + +HTML Fuzzy Variation Match Test + HTML Fuzzy Check Variation + +HTML Fuzzy Phishing Detection Test + HTML Fuzzy Check Phishing diff --git a/test/functional/messages/html_phishing.eml b/test/functional/messages/html_phishing.eml new file mode 100644 index 0000000000..e328c218e4 --- /dev/null +++ b/test/functional/messages/html_phishing.eml @@ -0,0 +1,28 @@ +From: notification@example.com +To: user@test.com +Subject: Your weekly newsletter +Content-Type: text/html; charset=utf-8 + + + + + Newsletter + + +
+ Logo +
+
+

Weekly Newsletter

+

URGENT: Verify your account now!

+
+

Security Alert

+

Your account has been compromised click here immediately

+ Verify Now +
+
+ + + diff --git a/test/functional/messages/html_template_1.eml b/test/functional/messages/html_template_1.eml new file mode 100644 index 0000000000..4956a9c63c --- /dev/null +++ b/test/functional/messages/html_template_1.eml @@ -0,0 +1,28 @@ +From: notification@example.com +To: user@test.com +Subject: Your weekly newsletter +Content-Type: text/html; charset=utf-8 + + + + + Newsletter + + +
+ Logo +
+
+

Weekly Newsletter

+

Here are your top stories this week

+
+

Article Title

+

Article content goes here with some text

+ Read More +
+
+ + + diff --git a/test/functional/messages/html_template_1_variation.eml b/test/functional/messages/html_template_1_variation.eml new file mode 100644 index 0000000000..21e109f8c7 --- /dev/null +++ b/test/functional/messages/html_template_1_variation.eml @@ -0,0 +1,28 @@ +From: notification@example.com +To: user@test.com +Subject: Your weekly newsletter +Content-Type: text/html; charset=utf-8 + + + + + Newsletter + + +
+ Logo +
+
+

Weekly Newsletter

+

Different stories for different week

+
+

Different Article Title

+

Completely different article content with other text here

+ Read More +
+
+ + +