nixos/opensnitch: add test

Changed files
+70 -3
nixos
pkgs
tools
networking
opensnitch
+1
nixos/tests/all-tests.nix
···
openresty-lua = handleTest ./openresty-lua.nix {};
opensmtpd = handleTest ./opensmtpd.nix {};
opensmtpd-rspamd = handleTest ./opensmtpd-rspamd.nix {};
openssh = handleTest ./openssh.nix {};
octoprint = handleTest ./octoprint.nix {};
openstack-image-metadata = (handleTestOn ["x86_64-linux"] ./openstack-image.nix {}).metadata or {};
···
openresty-lua = handleTest ./openresty-lua.nix {};
opensmtpd = handleTest ./opensmtpd.nix {};
opensmtpd-rspamd = handleTest ./opensmtpd-rspamd.nix {};
+
opensnitch = handleTest ./opensnitch.nix {};
openssh = handleTest ./openssh.nix {};
octoprint = handleTest ./octoprint.nix {};
openstack-image-metadata = (handleTestOn ["x86_64-linux"] ./openstack-image.nix {}).metadata or {};
+62
nixos/tests/opensnitch.nix
···
···
+
import ./make-test-python.nix ({ pkgs, ... }: {
+
name = "opensnitch";
+
+
meta = with pkgs.lib.maintainers; {
+
maintainers = [ onny ];
+
};
+
+
nodes = {
+
server =
+
{ ... }: {
+
networking.firewall.allowedTCPPorts = [ 80 ];
+
services.caddy = {
+
enable = true;
+
virtualHosts."localhost".extraConfig = ''
+
respond "Hello, world!"
+
'';
+
};
+
};
+
+
clientBlocked =
+
{ ... }: {
+
services.opensnitch = {
+
enable = true;
+
settings.DefaultAction = "deny";
+
};
+
};
+
+
clientAllowed =
+
{ ... }: {
+
services.opensnitch = {
+
enable = true;
+
settings.DefaultAction = "deny";
+
rules = {
+
opensnitch = {
+
name = "curl";
+
enabled = true;
+
action = "allow";
+
duration = "always";
+
operator = {
+
type ="simple";
+
sensitive = false;
+
operand = "process.path";
+
data = "${pkgs.curl}/bin/curl";
+
};
+
};
+
};
+
};
+
};
+
};
+
+
testScript = ''
+
start_all()
+
server.wait_for_unit("caddy.service")
+
server.wait_for_open_port(80)
+
+
clientBlocked.wait_for_unit("opensnitchd.service")
+
clientBlocked.fail("curl http://server")
+
+
clientAllowed.wait_for_unit("opensnitchd.service")
+
clientAllowed.succeed("curl http://server")
+
'';
+
})
+7 -3
pkgs/tools/networking/opensnitch/daemon.nix
···
, protoc-gen-go-grpc
, testers
, opensnitch
}:
buildGoModule rec {
···
--prefix PATH : ${lib.makeBinPath [ iptables ]}
'';
-
passthru.tests.version = testers.testVersion {
-
package = opensnitch;
-
command = "opensnitchd -version";
};
meta = with lib; {
···
, protoc-gen-go-grpc
, testers
, opensnitch
+
, nixosTests
}:
buildGoModule rec {
···
--prefix PATH : ${lib.makeBinPath [ iptables ]}
'';
+
passthru.tests = {
+
inherit (nixosTests) opensnitch;
+
version = testers.testVersion {
+
package = opensnitch;
+
command = "opensnitchd -version";
+
};
};
meta = with lib; {