1 import ./make-test-python.nix ({ pkgs, ... }: {
2 name = "nginx-status-page";
3 meta = with pkgs.lib.maintainers; {
4 maintainers = [ h7x4 ];
9 virtualisation.vlans = [ 1 ];
14 firewall.enable = false;
17 systemd.network.networks."01-eth1" = {
19 networkConfig.Address = "10.0.0.1/24";
25 virtualHosts."localhost".locations."/index.html".return = "200 'hello world\n'";
28 environment.systemPackages = with pkgs; [ curl ];
32 virtualisation.vlans = [ 1 ];
37 firewall.enable = false;
40 systemd.network.networks."01-eth1" = {
42 networkConfig.Address = "10.0.0.2/24";
45 environment.systemPackages = with pkgs; [ curl ];
49 testScript = { nodes, ... }: ''
52 webserver.wait_for_unit("nginx")
53 webserver.wait_for_open_port(80)
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}"
60 with subtest("localhost can access status page"):
61 expect_http_code(webserver, "200", "http://localhost/nginx_status")
63 with subtest("localhost can access other page"):
64 expect_http_code(webserver, "200", "http://localhost/index.html")
66 with subtest("client can not access status page"):
67 expect_http_code(client, "403", "http://10.0.0.1/nginx_status")
69 with subtest("client can access other page"):
70 expect_http_code(client, "200", "http://10.0.0.1/index.html")