git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #160042 from stigtsp/test/nginx-modsecurity
commitd778e183660886e01462d4b91ee0760e386fc6e4 authorMartin Weinelt <mweinelt@users.noreply.github.com> dateWed 23 Feb 2022, 12:02 (5 years ago) parentac3478bfb12caf
3 files changed+45
nixos/tests/all-tests.nix+1 nixos/tests/nginx-modsecurity.nix+39 pkgs/tools/security/libmodsecurity/default.nix+5
nixos/tests/all-tests.nix+1
@@ -348,6 +348,7 @@ in
348348 nginx = handleTest ./nginx.nix {};
349349 nginx-auth = handleTest ./nginx-auth.nix {};
350350 nginx-etag = handleTest ./nginx-etag.nix {};
351+ nginx-modsecurity = handleTest ./nginx-modsecurity.nix {};
351352 nginx-pubhtml = handleTest ./nginx-pubhtml.nix {};
352353 nginx-sandbox = handleTestOn ["x86_64-linux"] ./nginx-sandbox.nix {};
353354 nginx-sso = handleTest ./nginx-sso.nix {};
nixos/tests/nginx-modsecurity.nixnew file+39
@@ -0,0 +1,39 @@
1+import ./make-test-python.nix ({ pkgs, lib, ... }: {
2+ name = "nginx-modsecurity";
3+
4+ machine = { config, lib, pkgs, ... }: {
5+ services.nginx = {
6+ enable = true;
7+ additionalModules = [ pkgs.nginxModules.modsecurity-nginx ];
8+ virtualHosts.localhost =
9+ let modsecurity_conf = pkgs.writeText "modsecurity.conf" ''
10+ SecRuleEngine On
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"
15+ '';
16+ testroot = pkgs.runCommand "testroot" {} ''
17+ mkdir -p $out
18+ echo "<html><body>Hello World!</body></html>" > $out/index.html
19+ echo "s3cret" > $out/secret.html
20+ '';
21+ in {
22+ root = testroot;
23+ extraConfig = ''
24+ modsecurity on;
25+ modsecurity_rules_file ${modsecurity_conf};
26+ '';
27+ };
28+ };
29+ };
30+ testScript = ''
31+ machine.wait_for_unit("nginx")
32+
33+ response = machine.wait_until_succeeds("curl -fvvv -s http://127.0.0.1/")
34+ assert "Hello World!" in response
35+
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")
38+ '';
39+})
pkgs/tools/security/libmodsecurity/default.nix+5
@@ -2,6 +2,7 @@
22, autoreconfHook, bison, flex, pkg-config
33, curl, geoip, libmaxminddb, libxml2, lmdb, lua, pcre
44, ssdeep, valgrind, yajl
5+, nixosTests
56}:
67
78stdenv.mkDerivation rec {
@@ -50,6 +51,10 @@ stdenv.mkDerivation rec {
5051
5152 enableParallelBuilding = true;
5253
54+ passthru.tests = {
55+ nginx-modsecurity = nixosTests.nginx-modsecurity;
56+ };
57+
5358 meta = with lib; {
5459 homepage = "https://github.com/SpiderLabs/ModSecurity";
5560 description = ''