diff options
author | h7x4 <h7x4@nani.wtf> | 2023-07-28 19:36:55 +0200 |
---|---|---|
committer | h7x4 <h7x4@nani.wtf> | 2023-07-28 20:29:09 +0200 |
commit | 25b7b82ee08c4422d53f2acb69753774a0fd74ca (patch) | |
tree | 5d59133b7f11ce6b69a51024e1d76eab2199ac58 /nixos/tests/nginx-status-page.nix | |
parent | d803f78e7c97efa63eedf21229ca3adf51b6fd2f (diff) |
nixos/nginx: add test for status page
Diffstat (limited to 'nixos/tests/nginx-status-page.nix')
-rw-r--r-- | nixos/tests/nginx-status-page.nix | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/nixos/tests/nginx-status-page.nix b/nixos/tests/nginx-status-page.nix new file mode 100644 index 0000000000000..ff2c0940379c7 --- /dev/null +++ b/nixos/tests/nginx-status-page.nix @@ -0,0 +1,72 @@ +import ./make-test-python.nix ({ pkgs, ... }: { + name = "nginx-status-page"; + meta = with pkgs.lib.maintainers; { + maintainers = [ h7x4 ]; + }; + + nodes = { + webserver = { ... }: { + virtualisation.vlans = [ 1 ]; + + networking = { + useNetworkd = true; + useDHCP = false; + firewall.enable = false; + }; + + systemd.network.networks."01-eth1" = { + name = "eth1"; + networkConfig.Address = "10.0.0.1/24"; + }; + + services.nginx = { + enable = true; + statusPage = true; + virtualHosts."localhost".locations."/index.html".return = "200 'hello world\n'"; + }; + + environment.systemPackages = with pkgs; [ curl ]; + }; + + client = { ... }: { + virtualisation.vlans = [ 1 ]; + + networking = { + useNetworkd = true; + useDHCP = false; + firewall.enable = false; + }; + + systemd.network.networks."01-eth1" = { + name = "eth1"; + networkConfig.Address = "10.0.0.2/24"; + }; + + environment.systemPackages = with pkgs; [ curl ]; + }; + }; + + testScript = { nodes, ... }: '' + start_all() + + webserver.wait_for_unit("nginx") + webserver.wait_for_open_port(80) + + def expect_http_code(node, code, url): + http_code = node.succeed(f"curl -w '%{{http_code}}' '{url}'") + assert http_code.split("\n")[-1].strip() == code, \ + f"expected {code} but got following response:\n{http_code}" + + with subtest("localhost can access status page"): + expect_http_code(webserver, "200", "http://localhost/nginx_status") + + with subtest("localhost can access other page"): + expect_http_code(webserver, "200", "http://localhost/index.html") + + with subtest("client can not access status page"): + expect_http_code(client, "403", "http://10.0.0.1/nginx_status") + + with subtest("client can access other page"): + expect_http_code(client, "200", "http://10.0.0.1/index.html") + ''; +}) |