lol

nixos/nginx: add test for status page

h7x4 25b7b82e d803f78e

+74 -1
+1
nixos/tests/all-tests.nix
··· 538 538 nginx-pubhtml = handleTest ./nginx-pubhtml.nix {}; 539 539 nginx-sandbox = handleTestOn ["x86_64-linux"] ./nginx-sandbox.nix {}; 540 540 nginx-sso = handleTest ./nginx-sso.nix {}; 541 + nginx-status-page = handleTest ./nginx-status-page.nix {}; 541 542 nginx-variants = handleTest ./nginx-variants.nix {}; 542 543 nginx-proxyprotocol = handleTest ./nginx-proxyprotocol {}; 543 544 nifi = handleTestOn ["x86_64-linux"] ./web-apps/nifi.nix {};
+72
nixos/tests/nginx-status-page.nix
··· 1 + import ./make-test-python.nix ({ pkgs, ... }: { 2 + name = "nginx-status-page"; 3 + meta = with pkgs.lib.maintainers; { 4 + maintainers = [ h7x4 ]; 5 + }; 6 + 7 + nodes = { 8 + webserver = { ... }: { 9 + virtualisation.vlans = [ 1 ]; 10 + 11 + networking = { 12 + useNetworkd = true; 13 + useDHCP = false; 14 + firewall.enable = false; 15 + }; 16 + 17 + systemd.network.networks."01-eth1" = { 18 + name = "eth1"; 19 + networkConfig.Address = "10.0.0.1/24"; 20 + }; 21 + 22 + services.nginx = { 23 + enable = true; 24 + statusPage = true; 25 + virtualHosts."localhost".locations."/index.html".return = "200 'hello world\n'"; 26 + }; 27 + 28 + environment.systemPackages = with pkgs; [ curl ]; 29 + }; 30 + 31 + client = { ... }: { 32 + virtualisation.vlans = [ 1 ]; 33 + 34 + networking = { 35 + useNetworkd = true; 36 + useDHCP = false; 37 + firewall.enable = false; 38 + }; 39 + 40 + systemd.network.networks."01-eth1" = { 41 + name = "eth1"; 42 + networkConfig.Address = "10.0.0.2/24"; 43 + }; 44 + 45 + environment.systemPackages = with pkgs; [ curl ]; 46 + }; 47 + }; 48 + 49 + testScript = { nodes, ... }: '' 50 + start_all() 51 + 52 + webserver.wait_for_unit("nginx") 53 + webserver.wait_for_open_port(80) 54 + 55 + def expect_http_code(node, code, url): 56 + http_code = node.succeed(f"curl -w '%{{http_code}}' '{url}'") 57 + assert http_code.split("\n")[-1].strip() == code, \ 58 + f"expected {code} but got following response:\n{http_code}" 59 + 60 + with subtest("localhost can access status page"): 61 + expect_http_code(webserver, "200", "http://localhost/nginx_status") 62 + 63 + with subtest("localhost can access other page"): 64 + expect_http_code(webserver, "200", "http://localhost/index.html") 65 + 66 + with subtest("client can not access status page"): 67 + expect_http_code(client, "403", "http://10.0.0.1/nginx_status") 68 + 69 + with subtest("client can access other page"): 70 + expect_http_code(client, "200", "http://10.0.0.1/index.html") 71 + ''; 72 + })
+1 -1
pkgs/servers/http/nginx/generic.nix
··· 178 178 passthru = { 179 179 inherit modules; 180 180 tests = { 181 - inherit (nixosTests) nginx nginx-auth nginx-etag nginx-globalredirect nginx-http3 nginx-pubhtml nginx-sandbox nginx-sso nginx-proxyprotocol; 181 + inherit (nixosTests) nginx nginx-auth nginx-etag nginx-globalredirect nginx-http3 nginx-pubhtml nginx-sandbox nginx-sso nginx-proxyprotocol nginx-status-page; 182 182 variants = lib.recurseIntoAttrs nixosTests.nginx-variants; 183 183 acme-integration = nixosTests.acme; 184 184 } // passthru.tests;