nixos/tests/firewalld: init

This commit is contained in:
Sizhe Zhao
2025-04-15 16:40:15 +08:00
parent 2051b59942
commit 9ca60dbb79
3 changed files with 54 additions and 0 deletions

View File

@@ -579,6 +579,7 @@ in
imports = [ ./firewall.nix ];
_module.args.backend = "nftables";
};
firewalld = runTest ./firewalld.nix;
firezone = runTest ./firezone/firezone.nix;
fish = runTest ./fish.nix;
flannel = runTestOn [ "x86_64-linux" ] ./flannel.nix;

52
nixos/tests/firewalld.nix Normal file
View File

@@ -0,0 +1,52 @@
{ lib, pkgs, ... }:
{
name = "firewalld";
meta.maintainers = with pkgs.lib.maintainers; [
prince213
];
nodes = {
walled = {
networking.nftables.enable = true;
services.firewalld.enable = true;
services.httpd.enable = true;
services.httpd.adminAddr = "foo@example.org";
};
open = {
networking.nftables.enable = true;
services.firewalld = {
enable = true;
settings.DefaultZone = "trusted";
};
services.httpd.enable = true;
services.httpd.adminAddr = "foo@example.org";
};
};
testScript = ''
start_all()
walled.wait_for_unit("firewalld")
walled.wait_for_unit("httpd")
open.wait_for_unit("network.target")
with subtest("walled local httpd works"):
walled.succeed("curl -v http://localhost/ >&2")
with subtest("incoming connections are blocked"):
open.fail("curl --fail --connect-timeout 2 http://walled/ >&2")
with subtest("outgoing connections are allowed"):
walled.succeed("curl -v http://open/ >&2")
with subtest("runtime configuration can be changed"):
walled.succeed("firewall-cmd --add-service=http")
open.succeed("curl -v http://walled/ >&2")
with subtest("runtime configuration are not permanent"):
walled.succeed("firewall-cmd --complete-reload")
open.fail("curl --fail --connect-timeout 2 http://walled/ >&2")
'';
}

View File

@@ -155,6 +155,7 @@ stdenv.mkDerivation rec {
'';
passthru.tests = {
firewalld = nixosTests.firewalld;
firewall-firewalld = nixosTests.firewall-firewalld;
};