]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Test] Fix ratelimit tests
authorAndrew Lewis <nerf@judo.za.org>
Thu, 11 Jul 2024 13:03:25 +0000 (15:03 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Thu, 11 Jul 2024 13:03:25 +0000 (15:03 +0200)
test/functional/cases/500_ratelimit.conf [deleted file]
test/functional/cases/500_ratelimit.robot [new file with mode: 0644]
test/functional/configs/ratelimit.conf

diff --git a/test/functional/cases/500_ratelimit.conf b/test/functional/cases/500_ratelimit.conf
deleted file mode 100644 (file)
index 425df34..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-*** 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@example.net  4
-
-CHECK SELECTOR
-  Recipient Test  foo@example.net  special@example.net  2
diff --git a/test/functional/cases/500_ratelimit.robot b/test/functional/cases/500_ratelimit.robot
new file mode 100644 (file)
index 0000000..9193754
--- /dev/null
@@ -0,0 +1,47 @@
+*** Settings ***
+Suite Setup     Rspamd Redis Setup
+Suite Teardown  Rspamd Redis 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/zip.eml
+${REDIS_SCOPE}          Suite
+${RSPAMD_SCOPE}         Suite
+${SETTINGS_RATELIMIT}   {symbols_enabled = [RATELIMIT_CHECK, RATELIMIT_UPDATE]}
+
+*** Keywords ***
+Basic Test Scan
+  [Arguments]  ${from}  ${rcpt}
+  Scan File  ${MESSAGE}
+  ...  From=${from}
+  ...  IP=1.1.1.1
+  ...  Settings=${SETTINGS_RATELIMIT}
+  ...  Rcpt=${rcpt}
+
+Basic Test
+  [Arguments]  ${from}  ${rcpt}  ${howmany}
+  # Should be able to send up to burst
+  FOR  ${index}  IN RANGE  ${howmany}
+    Basic Test Scan  ${from}  ${rcpt}
+    Expect Action  no action
+  END
+  # Should then be ratelimited
+  Basic Test Scan  ${from}  ${rcpt}
+  Expect Action  soft reject
+  # Should be able to send 1 message 1 second later
+  Sleep  1s
+  Basic Test Scan  ${from}  ${rcpt}
+  Expect Action  no action
+  # Ratelimited again
+  Basic Test Scan  ${from}  ${rcpt}
+  Expect Action  soft reject
+
+*** Test Cases ***
+RATELIMIT CHECK BUILTIN
+  Basic Test  ${EMPTY}  foobar@example.net  4
+
+RATELIMIT CHECK SELECTOR
+  Basic Test  foo@example.net  special@example.net  2
index ab0c44b4224fa304243f001107451b05d49c9e3c..36bae88feeeea1f01aaee95a91822b61bac6d74b 100644 (file)
@@ -1,20 +1,23 @@
 .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";
+  rates {
+    bounce_to_ip {
+      bucket {
+        burst = 4;
+        rate = "1 / 1s";
+      }
+    }
+    to_selector_xxx {
+      selector = "id('special');to.in('special@example.net')";
+      bucket {
+        burst = 2;
+        rate = "1 / 1s";
+      }
     }
-  }
-  to_selector {
-    selector = "to:in{special@example.net}";
-    burst = 2;
-    rate = "1 / 1s";
   }
 }