commit bf66ae7: [Test] Add tests for ratelimit module

Andrew Lewis nerf at judo.za.org
Mon Jul 29 17:59:08 UTC 2024


Author: Andrew Lewis
Date: 2024-07-10 14:46:34 +0200
URL: https://github.com/rspamd/rspamd/commit/bf66ae7777fb8d087fe37c0052bdca1b724cb0a1 (refs/pull/5048/head)

[Test] Add tests for ratelimit module

---
 test/functional/cases/500_ratelimit.conf | 44 ++++++++++++++++++++++++++++++++
 test/functional/configs/ratelimit.conf   | 20 +++++++++++++++
 2 files changed, 64 insertions(+)

diff --git a/test/functional/cases/500_ratelimit.conf b/test/functional/cases/500_ratelimit.conf
new file mode 100644
index 000000000..425df34be
--- /dev/null
+++ b/test/functional/cases/500_ratelimit.conf
@@ -0,0 +1,44 @@
+*** Settings ***
+Suite Setup     Rspamd Setup
+Suite Teardown  Rspamd Teardown
+Library         ${RSPAMD_TESTDIR}/lib/rspamd.py
+Resource        ${RSPAMD_TESTDIR}/lib/rspamd.robot
+Variables       ${RSPAMD_TESTDIR}/lib/vars.py
+
+*** Variables ***
+${CONFIG}               ${RSPAMD_TESTDIR}/configs/ratelimit.conf
+${MESSAGE}              ${RSPAMD_TESTDIR}/messages/ham.eml
+${RSPAMD_SCOPE}         Suite
+${SETTINGS_REPLIES}     {symbols_enabled = [RATELIMIT_CHECK, RATELIMIT_UPDATE]}
+
+*** Keywords ***
+Recipient Test
+  [Arguments]  ${from}  ${rcpt}  ${howmany}
+  FOR  ${index}  IN RANGE  ${howmany}
+    Scan File  ${HAM_MESSAGE}
+    ...  From=${from}
+    ...  IP=1.1.1.1
+    ...  Settings=${SETTINGS_RATELIMIT}
+    ...  Rcpt=${rcpt}
+    Expect Action  no action
+  END
+  Scan File  ${HAM_MESSAGE}
+  ...  From=${from}
+  ...  IP=1.1.1.1
+  ...  Settings=${SETTINGS_RATELIMIT}
+  ...  Rcpt=${rcpt}
+  Expect Action  soft reject
+  Sleep 1s
+  Scan File  ${HAM_MESSAGE}
+  ...  From=${from}
+  ...  IP=1.1.1.1
+  ...  Settings=${SETTINGS_RATELIMIT}
+  ...  Rcpt=${rcpt}
+  Expect Action  no action
+
+*** Test Cases ***
+CHECK BASIC
+  Recipient Test  ${EMPTY}  foobar at example.net  4
+
+CHECK SELECTOR
+  Recipient Test  foo at example.net  special at example.net  2
diff --git a/test/functional/configs/ratelimit.conf b/test/functional/configs/ratelimit.conf
new file mode 100644
index 000000000..ab0c44b42
--- /dev/null
+++ b/test/functional/configs/ratelimit.conf
@@ -0,0 +1,20 @@
+.include(duplicate=append,priority=0) "{= env.TESTDIR =}/configs/plugins.conf"
+
+lua = "{= env.LUA_SCRIPT =}";
+redis {
+  servers = "{= env.REDIS_ADDR =}:{= env.REDIS_PORT =}";
+}
+
+ratelimit {
+  bounce_to_ip {
+    bucket {
+      burst = 4;
+      rate = "1 / 1s";
+    }
+  }
+  to_selector {
+    selector = "to:in{special at example.net}";
+    burst = 2;
+    rate = "1 / 1s";
+  }
+}


More information about the Commits mailing list