2018-11-11 08:41:11 +00:00
|
|
|
{ system ? builtins.currentSystem,
|
|
|
|
config ? {},
|
|
|
|
pkgs ? import ../.. { inherit system config; }
|
|
|
|
}:
|
|
|
|
|
2019-12-10 23:17:51 +00:00
|
|
|
with import ../lib/testing-python.nix { inherit system pkgs; };
|
2018-02-02 00:35:32 +00:00
|
|
|
with pkgs.lib;
|
2018-11-11 08:41:11 +00:00
|
|
|
|
2018-02-02 00:35:32 +00:00
|
|
|
let
|
|
|
|
initMachine = ''
|
2019-12-10 23:17:51 +00:00
|
|
|
start_all()
|
|
|
|
machine.wait_for_unit("rspamd.service")
|
|
|
|
machine.succeed("id rspamd >/dev/null")
|
2018-02-02 00:35:32 +00:00
|
|
|
'';
|
|
|
|
checkSocket = socket: user: group: mode: ''
|
2020-11-29 11:51:53 +00:00
|
|
|
machine.succeed(
|
|
|
|
"ls ${socket} >/dev/null",
|
|
|
|
'[[ "$(stat -c %U ${socket})" == "${user}" ]]',
|
|
|
|
'[[ "$(stat -c %G ${socket})" == "${group}" ]]',
|
|
|
|
'[[ "$(stat -c %a ${socket})" == "${mode}" ]]',
|
|
|
|
)
|
2018-02-02 00:35:32 +00:00
|
|
|
'';
|
2018-09-28 03:00:24 +01:00
|
|
|
simple = name: enableIPv6: makeTest {
|
2018-02-02 00:35:32 +00:00
|
|
|
name = "rspamd-${name}";
|
|
|
|
machine = {
|
2018-09-28 03:00:24 +01:00
|
|
|
services.rspamd.enable = true;
|
2018-02-02 00:35:32 +00:00
|
|
|
networking.enableIPv6 = enableIPv6;
|
|
|
|
};
|
|
|
|
testScript = ''
|
2019-12-10 23:17:51 +00:00
|
|
|
start_all()
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
machine.wait_for_open_port(11334)
|
|
|
|
machine.wait_for_unit("rspamd.service")
|
|
|
|
machine.succeed("id rspamd >/dev/null")
|
2018-02-02 00:35:32 +00:00
|
|
|
${checkSocket "/run/rspamd/rspamd.sock" "rspamd" "rspamd" "660" }
|
2019-12-10 23:17:51 +00:00
|
|
|
machine.sleep(10)
|
|
|
|
machine.log(machine.succeed("cat /etc/rspamd/rspamd.conf"))
|
|
|
|
machine.log(
|
|
|
|
machine.succeed("grep 'CONFDIR/worker-controller.inc' /etc/rspamd/rspamd.conf")
|
|
|
|
)
|
|
|
|
machine.log(machine.succeed("grep 'CONFDIR/worker-normal.inc' /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"))
|
|
|
|
${optionalString enableIPv6 ''machine.log(machine.succeed("curl http://[::1]:11334/auth"))''}
|
|
|
|
# would not reformat
|
2018-02-02 00:35:32 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
2018-09-28 03:00:24 +01:00
|
|
|
simple = simple "simple" true;
|
|
|
|
ipv4only = simple "ipv4only" false;
|
2018-02-03 18:04:31 +00:00
|
|
|
deprecated = makeTest {
|
|
|
|
name = "rspamd-deprecated";
|
2018-02-02 00:35:32 +00:00
|
|
|
machine = {
|
|
|
|
services.rspamd = {
|
|
|
|
enable = true;
|
2019-02-11 01:59:55 +00:00
|
|
|
workers.normal.bindSockets = [{
|
2020-11-29 11:51:53 +00:00
|
|
|
socket = "/run/rspamd/rspamd.sock";
|
2019-02-11 01:59:55 +00:00
|
|
|
mode = "0600";
|
2020-11-29 11:51:53 +00:00
|
|
|
owner = "rspamd";
|
|
|
|
group = "rspamd";
|
2019-02-11 01:59:55 +00:00
|
|
|
}];
|
|
|
|
workers.controller.bindSockets = [{
|
2020-11-29 11:51:53 +00:00
|
|
|
socket = "/run/rspamd/rspamd-worker.sock";
|
2019-02-11 01:59:55 +00:00
|
|
|
mode = "0666";
|
2020-11-29 11:51:53 +00:00
|
|
|
owner = "rspamd";
|
|
|
|
group = "rspamd";
|
2019-02-11 01:59:55 +00:00
|
|
|
}];
|
2018-02-02 00:35:32 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
${initMachine}
|
2020-11-29 11:51:53 +00:00
|
|
|
machine.wait_for_file("/run/rspamd/rspamd.sock")
|
|
|
|
${checkSocket "/run/rspamd/rspamd.sock" "rspamd" "rspamd" "600" }
|
|
|
|
${checkSocket "/run/rspamd/rspamd-worker.sock" "rspamd" "rspamd" "666" }
|
2019-12-10 23:17:51 +00:00
|
|
|
machine.log(machine.succeed("cat /etc/rspamd/rspamd.conf"))
|
|
|
|
machine.log(
|
|
|
|
machine.succeed("grep 'CONFDIR/worker-controller.inc' /etc/rspamd/rspamd.conf")
|
|
|
|
)
|
|
|
|
machine.log(machine.succeed("grep 'CONFDIR/worker-normal.inc' /etc/rspamd/rspamd.conf"))
|
2020-11-29 11:51:53 +00:00
|
|
|
machine.log(machine.succeed("rspamc -h /run/rspamd/rspamd-worker.sock stat"))
|
2019-12-10 23:17:51 +00:00
|
|
|
machine.log(
|
2020-11-29 11:51:53 +00:00
|
|
|
machine.succeed(
|
|
|
|
"curl --unix-socket /run/rspamd/rspamd-worker.sock http://localhost/ping"
|
|
|
|
)
|
2019-12-10 23:17:51 +00:00
|
|
|
)
|
2018-02-03 18:04:31 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
bindports = makeTest {
|
|
|
|
name = "rspamd-bindports";
|
|
|
|
machine = {
|
|
|
|
services.rspamd = {
|
|
|
|
enable = true;
|
|
|
|
workers.normal.bindSockets = [{
|
2020-11-29 11:51:53 +00:00
|
|
|
socket = "/run/rspamd/rspamd.sock";
|
2018-02-03 18:04:31 +00:00
|
|
|
mode = "0600";
|
2020-11-29 11:51:53 +00:00
|
|
|
owner = "rspamd";
|
|
|
|
group = "rspamd";
|
2018-02-03 18:04:31 +00:00
|
|
|
}];
|
|
|
|
workers.controller.bindSockets = [{
|
2020-11-29 11:51:53 +00:00
|
|
|
socket = "/run/rspamd/rspamd-worker.sock";
|
2018-02-03 18:04:31 +00:00
|
|
|
mode = "0666";
|
2020-11-29 11:51:53 +00:00
|
|
|
owner = "rspamd";
|
|
|
|
group = "rspamd";
|
2018-02-03 18:04:31 +00:00
|
|
|
}];
|
2018-11-05 23:26:55 +00:00
|
|
|
workers.controller2 = {
|
|
|
|
type = "controller";
|
|
|
|
bindSockets = [ "0.0.0.0:11335" ];
|
|
|
|
extraConfig = ''
|
|
|
|
static_dir = "''${WWWDIR}";
|
|
|
|
secure_ip = null;
|
|
|
|
password = "verysecretpassword";
|
|
|
|
'';
|
|
|
|
};
|
2018-02-03 18:04:31 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
${initMachine}
|
2020-11-29 11:51:53 +00:00
|
|
|
machine.wait_for_file("/run/rspamd/rspamd.sock")
|
|
|
|
${checkSocket "/run/rspamd/rspamd.sock" "rspamd" "rspamd" "600" }
|
|
|
|
${checkSocket "/run/rspamd/rspamd-worker.sock" "rspamd" "rspamd" "666" }
|
2019-12-10 23:17:51 +00:00
|
|
|
machine.log(machine.succeed("cat /etc/rspamd/rspamd.conf"))
|
|
|
|
machine.log(
|
|
|
|
machine.succeed("grep 'CONFDIR/worker-controller.inc' /etc/rspamd/rspamd.conf")
|
|
|
|
)
|
|
|
|
machine.log(machine.succeed("grep 'CONFDIR/worker-normal.inc' /etc/rspamd/rspamd.conf"))
|
|
|
|
machine.log(
|
|
|
|
machine.succeed(
|
|
|
|
"grep 'LOCAL_CONFDIR/override.d/worker-controller2.inc' /etc/rspamd/rspamd.conf"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
machine.log(
|
|
|
|
machine.succeed(
|
|
|
|
"grep 'verysecretpassword' /etc/rspamd/override.d/worker-controller2.inc"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
machine.wait_until_succeeds(
|
|
|
|
"journalctl -u rspamd | grep -i 'starting controller process' >&2"
|
|
|
|
)
|
2020-11-29 11:51:53 +00:00
|
|
|
machine.log(machine.succeed("rspamc -h /run/rspamd/rspamd-worker.sock stat"))
|
2019-12-10 23:17:51 +00:00
|
|
|
machine.log(
|
2020-11-29 11:51:53 +00:00
|
|
|
machine.succeed(
|
|
|
|
"curl --unix-socket /run/rspamd/rspamd-worker.sock http://localhost/ping"
|
|
|
|
)
|
2019-12-10 23:17:51 +00:00
|
|
|
)
|
|
|
|
machine.log(machine.succeed("curl http://localhost:11335/ping"))
|
2018-02-02 00:35:32 +00:00
|
|
|
'';
|
|
|
|
};
|
2018-11-01 22:55:44 +00:00
|
|
|
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;
|
2018-11-05 16:50:34 +00:00
|
|
|
locals = {
|
|
|
|
"antivirus.conf" = mkIf false { text = ''
|
|
|
|
clamav {
|
|
|
|
action = "reject";
|
|
|
|
symbol = "CLAM_VIRUS";
|
|
|
|
type = "clamav";
|
|
|
|
log_clean = true;
|
|
|
|
servers = "/run/clamav/clamd.ctl";
|
|
|
|
}
|
|
|
|
'';};
|
|
|
|
"redis.conf" = {
|
|
|
|
enable = false;
|
|
|
|
text = ''
|
|
|
|
servers = "127.0.0.1";
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
"groups.conf".text = ''
|
|
|
|
group "cows" {
|
|
|
|
symbol {
|
|
|
|
NO_MUH = {
|
|
|
|
weight = 1.0;
|
|
|
|
description = "Mails should not muh";
|
|
|
|
}
|
2018-11-01 22:55:44 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-05 16:50:34 +00:00
|
|
|
'';
|
|
|
|
};
|
2018-11-01 22:55:44 +00:00
|
|
|
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,
|
2020-11-22 07:23:53 +00:00
|
|
|
description = 'Allow no cows',
|
2018-11-01 22:55:44 +00:00
|
|
|
group = "cows",
|
|
|
|
}
|
|
|
|
rspamd_logger.infox(rspamd_config, 'Work dammit!!!')
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
testScript = ''
|
|
|
|
${initMachine}
|
2019-12-10 23:17:51 +00:00
|
|
|
machine.wait_for_open_port(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"))
|
2018-11-05 16:50:34 +00:00
|
|
|
# Verify that redis.conf was not written
|
2019-12-10 23:17:51 +00:00
|
|
|
machine.fail("cat /etc/rspamd/local.d/redis.conf >&2")
|
2018-11-05 16:50:34 +00:00
|
|
|
# Verify that antivirus.conf was not written
|
2019-12-10 23:17:51 +00:00
|
|
|
machine.fail("cat /etc/rspamd/local.d/antivirus.conf >&2")
|
2018-11-01 22:55:44 +00:00
|
|
|
${checkSocket "/run/rspamd/rspamd.sock" "rspamd" "rspamd" "660" }
|
2019-12-10 23:17:51 +00:00
|
|
|
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.wait_until_succeeds("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"
|
|
|
|
)
|
|
|
|
)
|
2018-11-01 22:55:44 +00:00
|
|
|
'';
|
|
|
|
};
|
2018-11-05 23:40:52 +00:00
|
|
|
postfixIntegration = makeTest {
|
|
|
|
name = "rspamd-postfix-integration";
|
|
|
|
machine = {
|
|
|
|
environment.systemPackages = with pkgs; [ msmtp ];
|
|
|
|
environment.etc."tests/gtube.eml".text = ''
|
|
|
|
From: Sheep1<bah@example.com>
|
|
|
|
To: Sheep2<tester@example.com>
|
|
|
|
Subject: Evil cows
|
|
|
|
|
|
|
|
I find cows to be evil don't you?
|
|
|
|
|
|
|
|
XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X
|
|
|
|
'';
|
|
|
|
environment.etc."tests/example.eml".text = ''
|
|
|
|
From: Sheep1<bah@example.com>
|
|
|
|
To: Sheep2<tester@example.com>
|
|
|
|
Subject: Evil cows
|
|
|
|
|
|
|
|
I find cows to be evil don't you?
|
|
|
|
'';
|
2021-03-07 13:54:00 +00:00
|
|
|
users.users.tester = {
|
|
|
|
isNormalUser = true;
|
|
|
|
password = "test";
|
|
|
|
};
|
2018-11-05 23:40:52 +00:00
|
|
|
services.postfix = {
|
|
|
|
enable = true;
|
|
|
|
destination = ["example.com"];
|
|
|
|
};
|
|
|
|
services.rspamd = {
|
|
|
|
enable = true;
|
|
|
|
postfix.enable = true;
|
2019-02-11 01:59:55 +00:00
|
|
|
workers.rspamd_proxy.type = "rspamd_proxy";
|
2018-11-05 23:40:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
testScript = ''
|
|
|
|
${initMachine}
|
2019-12-10 23:17:51 +00:00
|
|
|
machine.wait_for_open_port(11334)
|
|
|
|
machine.wait_for_open_port(25)
|
2018-11-05 23:40:52 +00:00
|
|
|
${checkSocket "/run/rspamd/rspamd-milter.sock" "rspamd" "postfix" "660" }
|
2019-12-10 23:17:51 +00:00
|
|
|
machine.log(machine.succeed("rspamc -h 127.0.0.1:11334 stat"))
|
|
|
|
machine.log(
|
|
|
|
machine.succeed(
|
|
|
|
"msmtp --host=localhost -t --read-envelope-from < /etc/tests/example.eml"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
machine.log(
|
|
|
|
machine.fail(
|
|
|
|
"msmtp --host=localhost -t --read-envelope-from < /etc/tests/gtube.eml"
|
|
|
|
)
|
|
|
|
)
|
2018-11-05 23:40:52 +00:00
|
|
|
|
2019-12-10 23:17:51 +00:00
|
|
|
machine.wait_until_fails('[ "$(postqueue -p)" != "Mail queue is empty" ]')
|
|
|
|
machine.fail("journalctl -u postfix | grep -i error >&2")
|
|
|
|
machine.fail("journalctl -u postfix | grep -i warning >&2")
|
2018-11-05 23:40:52 +00:00
|
|
|
'';
|
|
|
|
};
|
2018-02-02 00:35:32 +00:00
|
|
|
}
|