nixos/nginx: add test for status page

This commit is contained in:
h7x4 2023-07-28 19:36:55 +02:00
parent d803f78e7c
commit 25b7b82ee0
No known key found for this signature in database
GPG Key ID: 9F2F7D8250F35146
3 changed files with 74 additions and 1 deletions

View File

@ -538,6 +538,7 @@ in {
nginx-pubhtml = handleTest ./nginx-pubhtml.nix {};
nginx-sandbox = handleTestOn ["x86_64-linux"] ./nginx-sandbox.nix {};
nginx-sso = handleTest ./nginx-sso.nix {};
nginx-status-page = handleTest ./nginx-status-page.nix {};
nginx-variants = handleTest ./nginx-variants.nix {};
nginx-proxyprotocol = handleTest ./nginx-proxyprotocol {};
nifi = handleTestOn ["x86_64-linux"] ./web-apps/nifi.nix {};

View File

@ -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")
'';
})

View File

@ -178,7 +178,7 @@ stdenv.mkDerivation {
passthru = {
inherit modules;
tests = {
inherit (nixosTests) nginx nginx-auth nginx-etag nginx-globalredirect nginx-http3 nginx-pubhtml nginx-sandbox nginx-sso nginx-proxyprotocol;
inherit (nixosTests) nginx nginx-auth nginx-etag nginx-globalredirect nginx-http3 nginx-pubhtml nginx-sandbox nginx-sso nginx-proxyprotocol nginx-status-page;
variants = lib.recurseIntoAttrs nixosTests.nginx-variants;
acme-integration = nixosTests.acme;
} // passthru.tests;