1 import ./make-test-python.nix ({ pkgs, lib, ... }: {
2 name = "nginx-modsecurity";
4 nodes.machine = { config, lib, pkgs, ... }: {
7 additionalModules = [ pkgs.nginxModules.modsecurity-nginx ];
8 virtualHosts.localhost =
9 let modsecurity_conf = pkgs.writeText "modsecurity.conf" ''
11 SecDefaultAction "phase:1,log,auditlog,deny,status:403"
12 SecDefaultAction "phase:2,log,auditlog,deny,status:403"
13 SecRule REQUEST_METHOD "HEAD" "id:100, phase:1, block"
14 SecRule REQUEST_FILENAME "secret.html" "id:101, phase:2, block"
16 testroot = pkgs.runCommand "testroot" {} ''
18 echo "<html><body>Hello World!</body></html>" > $out/index.html
19 echo "s3cret" > $out/secret.html
25 modsecurity_rules_file ${modsecurity_conf};
31 machine.wait_for_unit("nginx")
33 response = machine.wait_until_succeeds("curl -fvvv -s http://127.0.0.1/")
34 assert "Hello World!" in response
36 machine.fail("curl -fvvv -X HEAD -s http://127.0.0.1/")
37 machine.fail("curl -fvvv -s http://127.0.0.1/secret.html")