aboutsummaryrefslogtreecommitdiff
path: root/nixos/tests/rspamd.nix
diff options
context:
space:
mode:
authorBrian Olsen <brian@maven-group.org>2018-11-01 23:55:44 +0100
committerBrian Olsen <brian@maven-group.org>2018-11-02 01:46:57 +0100
commit0810d631a489fcd819eafc530c45e768570ace8d (patch)
tree906f74dc13ef7837e1d94b9dc5cb737e80f36d27 /nixos/tests/rspamd.nix
parent89ede978a0614fd7215e0aa2c483df142cc79af9 (diff)
nixos/rspamd: Add support for included files
By default rspamd will look for multiple files in /etc/rspamd/local.d and /etc/rspamd/override.d to be included in subsections of the merged final config for rspamd. Most of the config snippets in the official rspamd documentation are made to these files and so it makes sense for NixOS to support them and this is what this commit does. As part of rspamd 1.8.1 support was added for having custom Lua rules stored in $LOCAL_CONFDIR/rspamd.local.lua which means that it is now possible for NixOS to support such rules and so this commit also adds support for this to the rspamd module.
Diffstat (limited to 'nixos/tests/rspamd.nix')
-rw-r--r--nixos/tests/rspamd.nix77
1 files changed, 74 insertions, 3 deletions
diff --git a/nixos/tests/rspamd.nix b/nixos/tests/rspamd.nix
index a12622b6aa0b..af765f37b91b 100644
--- a/nixos/tests/rspamd.nix
+++ b/nixos/tests/rspamd.nix
@@ -27,7 +27,7 @@ let
$machine->succeed("id \"rspamd\" >/dev/null");
${checkSocket "/run/rspamd/rspamd.sock" "rspamd" "rspamd" "660" }
sleep 10;
- $machine->log($machine->succeed("cat /etc/rspamd.conf"));
+ $machine->log($machine->succeed("cat /etc/rspamd/rspamd.conf"));
$machine->log($machine->succeed("systemctl cat rspamd.service"));
$machine->log($machine->succeed("curl http://localhost:11334/auth"));
$machine->log($machine->succeed("curl http://127.0.0.1:11334/auth"));
@@ -55,7 +55,7 @@ in
$machine->waitForFile("/run/rspamd.sock");
${checkSocket "/run/rspamd.sock" "root" "root" "600" }
${checkSocket "/run/rspamd-worker.sock" "root" "root" "666" }
- $machine->log($machine->succeed("cat /etc/rspamd.conf"));
+ $machine->log($machine->succeed("cat /etc/rspamd/rspamd.conf"));
$machine->log($machine->succeed("rspamc -h /run/rspamd-worker.sock stat"));
$machine->log($machine->succeed("curl --unix-socket /run/rspamd-worker.sock http://localhost/ping"));
'';
@@ -86,9 +86,80 @@ in
$machine->waitForFile("/run/rspamd.sock");
${checkSocket "/run/rspamd.sock" "root" "root" "600" }
${checkSocket "/run/rspamd-worker.sock" "root" "root" "666" }
- $machine->log($machine->succeed("cat /etc/rspamd.conf"));
+ $machine->log($machine->succeed("cat /etc/rspamd/rspamd.conf"));
$machine->log($machine->succeed("rspamc -h /run/rspamd-worker.sock stat"));
$machine->log($machine->succeed("curl --unix-socket /run/rspamd-worker.sock http://localhost/ping"));
'';
};
+ customLuaRules = makeTest {
+ name = "rspamd-custom-lua-rules";
+ machine = {
+ environment.etc."tests/no-muh.eml".text = ''
+ From: Sheep1<bah@example.com>
+ To: Sheep2<mah@example.com>
+ Subject: Evil cows
+
+ I find cows to be evil don't you?
+ '';
+ environment.etc."tests/muh.eml".text = ''
+ From: Cow<cow@example.com>
+ To: Sheep2<mah@example.com>
+ Subject: Evil cows
+
+ Cows are majestic creatures don't Muh agree?
+ '';
+ services.rspamd = {
+ enable = true;
+ locals."groups.conf".text = ''
+ group "cows" {
+ symbol {
+ NO_MUH = {
+ weight = 1.0;
+ description = "Mails should not muh";
+ }
+ }
+ }
+ '';
+ localLuaRules = pkgs.writeText "rspamd.local.lua" ''
+ local rspamd_logger = require "rspamd_logger"
+ rspamd_config.NO_MUH = {
+ callback = function (task)
+ local parts = task:get_text_parts()
+ if parts then
+ for _,part in ipairs(parts) do
+ local content = tostring(part:get_content())
+ rspamd_logger.infox(rspamd_config, 'Found content %s', content)
+ local found = string.find(content, "Muh");
+ rspamd_logger.infox(rspamd_config, 'Found muh %s', tostring(found))
+ if found then
+ return true
+ end
+ end
+ end
+ return false
+ end,
+ score = 5.0,
+ description = 'Allow no cows',
+ group = "cows",
+ }
+ rspamd_logger.infox(rspamd_config, 'Work dammit!!!')
+ '';
+ };
+ };
+ testScript = ''
+ ${initMachine}
+ $machine->waitForOpenPort(11334);
+ $machine->log($machine->succeed("cat /etc/rspamd/rspamd.conf"));
+ $machine->log($machine->succeed("cat /etc/rspamd/rspamd.local.lua"));
+ $machine->log($machine->succeed("cat /etc/rspamd/local.d/groups.conf"));
+ ${checkSocket "/run/rspamd/rspamd.sock" "rspamd" "rspamd" "660" }
+ $machine->log($machine->succeed("curl --unix-socket /run/rspamd/rspamd.sock http://localhost/ping"));
+ $machine->log($machine->succeed("rspamc -h 127.0.0.1:11334 stat"));
+ $machine->log($machine->succeed("cat /etc/tests/no-muh.eml | rspamc -h 127.0.0.1:11334"));
+ $machine->log($machine->succeed("cat /etc/tests/muh.eml | rspamc -h 127.0.0.1:11334 symbols"));
+ $machine->waitUntilSucceeds("journalctl -u rspamd | grep -i muh >&2");
+ $machine->log($machine->fail("cat /etc/tests/no-muh.eml | rspamc -h 127.0.0.1:11334 symbols | grep NO_MUH"));
+ $machine->log($machine->succeed("cat /etc/tests/muh.eml | rspamc -h 127.0.0.1:11334 symbols | grep NO_MUH"));
+ '';
+ };
}