at 23.11-beta 2.0 kB view raw
1import ./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})