1 { system ? builtins.currentSystem,
3 pkgs ? import ../.. { inherit system config; }
6 with import ../lib/testing-python.nix { inherit system pkgs; };
12 machine.wait_for_unit("rspamd.service")
13 machine.succeed("id rspamd >/dev/null")
15 checkSocket = socket: user: group: mode: ''
17 "ls ${socket} >/dev/null",
18 '[[ "$(stat -c %U ${socket})" == "${user}" ]]',
19 '[[ "$(stat -c %G ${socket})" == "${group}" ]]',
20 '[[ "$(stat -c %a ${socket})" == "${mode}" ]]',
23 simple = name: enableIPv6: makeTest {
24 name = "rspamd-${name}";
26 services.rspamd.enable = true;
27 networking.enableIPv6 = enableIPv6;
31 machine.wait_for_unit("multi-user.target")
32 machine.wait_for_open_port(11334)
33 machine.wait_for_unit("rspamd.service")
34 machine.succeed("id rspamd >/dev/null")
35 ${checkSocket "/run/rspamd/rspamd.sock" "rspamd" "rspamd" "660" }
37 machine.log(machine.succeed("cat /etc/rspamd/rspamd.conf"))
39 machine.succeed("grep 'CONFDIR/worker-controller.inc' /etc/rspamd/rspamd.conf")
41 machine.log(machine.succeed("grep 'CONFDIR/worker-normal.inc' /etc/rspamd/rspamd.conf"))
42 machine.log(machine.succeed("systemctl cat rspamd.service"))
43 machine.log(machine.succeed("curl http://localhost:11334/auth"))
44 machine.log(machine.succeed("curl http://127.0.0.1:11334/auth"))
45 ${optionalString enableIPv6 ''machine.log(machine.succeed("curl http://[::1]:11334/auth"))''}
51 simple = simple "simple" true;
52 ipv4only = simple "ipv4only" false;
53 deprecated = makeTest {
54 name = "rspamd-deprecated";
58 workers.normal.bindSockets = [{
59 socket = "/run/rspamd/rspamd.sock";
64 workers.controller.bindSockets = [{
65 socket = "/run/rspamd/rspamd-worker.sock";
75 machine.wait_for_file("/run/rspamd/rspamd.sock")
76 ${checkSocket "/run/rspamd/rspamd.sock" "rspamd" "rspamd" "600" }
77 ${checkSocket "/run/rspamd/rspamd-worker.sock" "rspamd" "rspamd" "666" }
78 machine.log(machine.succeed("cat /etc/rspamd/rspamd.conf"))
80 machine.succeed("grep 'CONFDIR/worker-controller.inc' /etc/rspamd/rspamd.conf")
82 machine.log(machine.succeed("grep 'CONFDIR/worker-normal.inc' /etc/rspamd/rspamd.conf"))
83 machine.log(machine.succeed("rspamc -h /run/rspamd/rspamd-worker.sock stat"))
86 "curl --unix-socket /run/rspamd/rspamd-worker.sock http://localhost/ping"
92 bindports = makeTest {
93 name = "rspamd-bindports";
97 workers.normal.bindSockets = [{
98 socket = "/run/rspamd/rspamd.sock";
103 workers.controller.bindSockets = [{
104 socket = "/run/rspamd/rspamd-worker.sock";
109 workers.controller2 = {
111 bindSockets = [ "0.0.0.0:11335" ];
113 static_dir = "''${WWWDIR}";
115 password = "verysecretpassword";
123 machine.wait_for_file("/run/rspamd/rspamd.sock")
124 ${checkSocket "/run/rspamd/rspamd.sock" "rspamd" "rspamd" "600" }
125 ${checkSocket "/run/rspamd/rspamd-worker.sock" "rspamd" "rspamd" "666" }
126 machine.log(machine.succeed("cat /etc/rspamd/rspamd.conf"))
128 machine.succeed("grep 'CONFDIR/worker-controller.inc' /etc/rspamd/rspamd.conf")
130 machine.log(machine.succeed("grep 'CONFDIR/worker-normal.inc' /etc/rspamd/rspamd.conf"))
133 "grep 'LOCAL_CONFDIR/override.d/worker-controller2.inc' /etc/rspamd/rspamd.conf"
138 "grep 'verysecretpassword' /etc/rspamd/override.d/worker-controller2.inc"
141 machine.wait_until_succeeds(
142 "journalctl -u rspamd | grep -i 'starting controller process' >&2"
144 machine.log(machine.succeed("rspamc -h /run/rspamd/rspamd-worker.sock stat"))
147 "curl --unix-socket /run/rspamd/rspamd-worker.sock http://localhost/ping"
150 machine.log(machine.succeed("curl http://localhost:11335/ping"))
153 customLuaRules = makeTest {
154 name = "rspamd-custom-lua-rules";
156 environment.etc."tests/no-muh.eml".text = ''
157 From: Sheep1<bah@example.com>
158 To: Sheep2<mah@example.com>
161 I find cows to be evil don't you?
163 environment.etc."tests/muh.eml".text = ''
164 From: Cow<cow@example.com>
165 To: Sheep2<mah@example.com>
168 Cows are majestic creatures don't Muh agree?
173 "antivirus.conf" = mkIf false { text = ''
176 symbol = "CLAM_VIRUS";
179 servers = "/run/clamav/clamd.ctl";
185 servers = "127.0.0.1";
188 "groups.conf".text = ''
193 description = "Mails should not muh";
199 localLuaRules = pkgs.writeText "rspamd.local.lua" ''
200 local rspamd_logger = require "rspamd_logger"
201 rspamd_config.NO_MUH = {
202 callback = function (task)
203 local parts = task:get_text_parts()
205 for _,part in ipairs(parts) do
206 local content = tostring(part:get_content())
207 rspamd_logger.infox(rspamd_config, 'Found content %s', content)
208 local found = string.find(content, "Muh");
209 rspamd_logger.infox(rspamd_config, 'Found muh %s', tostring(found))
218 description = 'Allow no cows',
221 rspamd_logger.infox(rspamd_config, 'Work dammit!!!')
227 machine.wait_for_open_port(11334)
228 machine.log(machine.succeed("cat /etc/rspamd/rspamd.conf"))
229 machine.log(machine.succeed("cat /etc/rspamd/rspamd.local.lua"))
230 machine.log(machine.succeed("cat /etc/rspamd/local.d/groups.conf"))
231 # Verify that redis.conf was not written
232 machine.fail("cat /etc/rspamd/local.d/redis.conf >&2")
233 # Verify that antivirus.conf was not written
234 machine.fail("cat /etc/rspamd/local.d/antivirus.conf >&2")
235 ${checkSocket "/run/rspamd/rspamd.sock" "rspamd" "rspamd" "660" }
237 machine.succeed("curl --unix-socket /run/rspamd/rspamd.sock http://localhost/ping")
239 machine.log(machine.succeed("rspamc -h 127.0.0.1:11334 stat"))
240 machine.log(machine.succeed("cat /etc/tests/no-muh.eml | rspamc -h 127.0.0.1:11334"))
242 machine.succeed("cat /etc/tests/muh.eml | rspamc -h 127.0.0.1:11334 symbols")
244 machine.wait_until_succeeds("journalctl -u rspamd | grep -i muh >&2")
247 "cat /etc/tests/no-muh.eml | rspamc -h 127.0.0.1:11334 symbols | grep NO_MUH"
252 "cat /etc/tests/muh.eml | rspamc -h 127.0.0.1:11334 symbols | grep NO_MUH"
257 postfixIntegration = makeTest {
258 name = "rspamd-postfix-integration";
260 environment.systemPackages = with pkgs; [ msmtp ];
261 environment.etc."tests/gtube.eml".text = ''
262 From: Sheep1<bah@example.com>
263 To: Sheep2<tester@example.com>
266 I find cows to be evil don't you?
268 XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X
270 environment.etc."tests/example.eml".text = ''
271 From: Sheep1<bah@example.com>
272 To: Sheep2<tester@example.com>
275 I find cows to be evil don't you?
277 users.users.tester = {
283 destination = ["example.com"];
287 postfix.enable = true;
288 workers.rspamd_proxy.type = "rspamd_proxy";
293 machine.wait_for_open_port(11334)
294 machine.wait_for_open_port(25)
295 ${checkSocket "/run/rspamd/rspamd-milter.sock" "rspamd" "postfix" "660" }
296 machine.log(machine.succeed("rspamc -h 127.0.0.1:11334 stat"))
299 "msmtp --host=localhost -t --read-envelope-from < /etc/tests/example.eml"
304 "msmtp --host=localhost -t --read-envelope-from < /etc/tests/gtube.eml"
308 machine.wait_until_fails('[ "$(postqueue -p)" != "Mail queue is empty" ]')
309 machine.fail("journalctl -u postfix | grep -i error >&2")
310 machine.fail("journalctl -u postfix | grep -i warning >&2")