at master 2.1 kB view raw
1{ pkgs, ... }: 2{ 3 name = "nginx-status-page"; 4 meta = with pkgs.lib.maintainers; { 5 maintainers = [ h7x4 ]; 6 }; 7 8 nodes = { 9 webserver = 10 { ... }: 11 { 12 virtualisation.vlans = [ 1 ]; 13 14 networking = { 15 useNetworkd = true; 16 useDHCP = false; 17 firewall.enable = false; 18 }; 19 20 systemd.network.networks."01-eth1" = { 21 name = "eth1"; 22 networkConfig.Address = "10.0.0.1/24"; 23 }; 24 25 services.nginx = { 26 enable = true; 27 statusPage = true; 28 virtualHosts."localhost".locations."/index.html".return = "200 'hello world\n'"; 29 }; 30 31 environment.systemPackages = with pkgs; [ curl ]; 32 }; 33 34 client = 35 { ... }: 36 { 37 virtualisation.vlans = [ 1 ]; 38 39 networking = { 40 useNetworkd = true; 41 useDHCP = false; 42 firewall.enable = false; 43 }; 44 45 systemd.network.networks."01-eth1" = { 46 name = "eth1"; 47 networkConfig.Address = "10.0.0.2/24"; 48 }; 49 50 environment.systemPackages = with pkgs; [ curl ]; 51 }; 52 }; 53 54 testScript = 55 { nodes, ... }: 56 '' 57 start_all() 58 59 webserver.wait_for_unit("nginx") 60 webserver.wait_for_open_port(80) 61 62 def expect_http_code(node, code, url): 63 http_code = node.succeed(f"curl -w '%{{http_code}}' '{url}'") 64 assert http_code.split("\n")[-1].strip() == code, \ 65 f"expected {code} but got following response:\n{http_code}" 66 67 with subtest("localhost can access status page"): 68 expect_http_code(webserver, "200", "http://localhost/nginx_status") 69 70 with subtest("localhost can access other page"): 71 expect_http_code(webserver, "200", "http://localhost/index.html") 72 73 with subtest("client can not access status page"): 74 expect_http_code(client, "403", "http://10.0.0.1/nginx_status") 75 76 with subtest("client can access other page"): 77 expect_http_code(client, "200", "http://10.0.0.1/index.html") 78 ''; 79}