Merge pull request #160042 from stigtsp/test/nginx-modsecurity

This commit is contained in:
Martin Weinelt 2022-02-23 12:02:20 +01:00 committed by GitHub
commit d778e18366
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 0 deletions

View File

@ -348,6 +348,7 @@ in
nginx = handleTest ./nginx.nix {};
nginx-auth = handleTest ./nginx-auth.nix {};
nginx-etag = handleTest ./nginx-etag.nix {};
nginx-modsecurity = handleTest ./nginx-modsecurity.nix {};
nginx-pubhtml = handleTest ./nginx-pubhtml.nix {};
nginx-sandbox = handleTestOn ["x86_64-linux"] ./nginx-sandbox.nix {};
nginx-sso = handleTest ./nginx-sso.nix {};

View File

@ -0,0 +1,39 @@
import ./make-test-python.nix ({ pkgs, lib, ... }: {
name = "nginx-modsecurity";
machine = { config, lib, pkgs, ... }: {
services.nginx = {
enable = true;
additionalModules = [ pkgs.nginxModules.modsecurity-nginx ];
virtualHosts.localhost =
let modsecurity_conf = pkgs.writeText "modsecurity.conf" ''
SecRuleEngine On
SecDefaultAction "phase:1,log,auditlog,deny,status:403"
SecDefaultAction "phase:2,log,auditlog,deny,status:403"
SecRule REQUEST_METHOD "HEAD" "id:100, phase:1, block"
SecRule REQUEST_FILENAME "secret.html" "id:101, phase:2, block"
'';
testroot = pkgs.runCommand "testroot" {} ''
mkdir -p $out
echo "<html><body>Hello World!</body></html>" > $out/index.html
echo "s3cret" > $out/secret.html
'';
in {
root = testroot;
extraConfig = ''
modsecurity on;
modsecurity_rules_file ${modsecurity_conf};
'';
};
};
};
testScript = ''
machine.wait_for_unit("nginx")
response = machine.wait_until_succeeds("curl -fvvv -s http://127.0.0.1/")
assert "Hello World!" in response
machine.fail("curl -fvvv -X HEAD -s http://127.0.0.1/")
machine.fail("curl -fvvv -s http://127.0.0.1/secret.html")
'';
})

View File

@ -2,6 +2,7 @@
, autoreconfHook, bison, flex, pkg-config
, curl, geoip, libmaxminddb, libxml2, lmdb, lua, pcre
, ssdeep, valgrind, yajl
, nixosTests
}:
stdenv.mkDerivation rec {
@ -50,6 +51,10 @@ stdenv.mkDerivation rec {
enableParallelBuilding = true;
passthru.tests = {
nginx-modsecurity = nixosTests.nginx-modsecurity;
};
meta = with lib; {
homepage = "https://github.com/SpiderLabs/ModSecurity";
description = ''