git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/tests/nginx-modsecurity: init
commit21f5ce0bd9a1503fc41f09bcbfb4770ab37c3925 authorStig Palmquist <stig@stig.io> dateTue 15 Feb 2022, 00:10 (5 years ago) parentc8fce94
2 files changed+40
nixos/tests/all-tests.nix+1 nixos/tests/nginx-modsecurity.nix+39
nixos/tests/all-tests.nix+1
@@ -345,6 +345,7 @@ in
345345 nginx = handleTest ./nginx.nix {};
346346 nginx-auth = handleTest ./nginx-auth.nix {};
347347 nginx-etag = handleTest ./nginx-etag.nix {};
348+ nginx-modsecurity = handleTest ./nginx-modsecurity.nix {};
348349 nginx-pubhtml = handleTest ./nginx-pubhtml.nix {};
349350 nginx-sandbox = handleTestOn ["x86_64-linux"] ./nginx-sandbox.nix {};
350351 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+})