@@ -811,7 +811,7 @@ in {
|
|||||||
nginx-pubhtml = runTest ./nginx-pubhtml.nix;
|
nginx-pubhtml = runTest ./nginx-pubhtml.nix;
|
||||||
nginx-redirectcode = runTest ./nginx-redirectcode.nix;
|
nginx-redirectcode = runTest ./nginx-redirectcode.nix;
|
||||||
nginx-sso = runTest ./nginx-sso.nix;
|
nginx-sso = runTest ./nginx-sso.nix;
|
||||||
nginx-status-page = handleTest ./nginx-status-page.nix {};
|
nginx-status-page = runTest ./nginx-status-page.nix;
|
||||||
nginx-tmpdir = handleTest ./nginx-tmpdir.nix {};
|
nginx-tmpdir = handleTest ./nginx-tmpdir.nix {};
|
||||||
nginx-unix-socket = handleTest ./nginx-unix-socket.nix {};
|
nginx-unix-socket = handleTest ./nginx-unix-socket.nix {};
|
||||||
nginx-variants = handleTest ./nginx-variants.nix {};
|
nginx-variants = handleTest ./nginx-variants.nix {};
|
||||||
|
|||||||
@@ -1,81 +1,79 @@
|
|||||||
import ./make-test-python.nix (
|
{ pkgs, ... }:
|
||||||
{ pkgs, ... }:
|
{
|
||||||
{
|
name = "nginx-status-page";
|
||||||
name = "nginx-status-page";
|
meta = with pkgs.lib.maintainers; {
|
||||||
meta = with pkgs.lib.maintainers; {
|
maintainers = [ h7x4 ];
|
||||||
maintainers = [ h7x4 ];
|
};
|
||||||
};
|
|
||||||
|
|
||||||
nodes = {
|
nodes = {
|
||||||
webserver =
|
webserver =
|
||||||
{ ... }:
|
{ ... }:
|
||||||
{
|
{
|
||||||
virtualisation.vlans = [ 1 ];
|
virtualisation.vlans = [ 1 ];
|
||||||
|
|
||||||
networking = {
|
networking = {
|
||||||
useNetworkd = true;
|
useNetworkd = true;
|
||||||
useDHCP = false;
|
useDHCP = false;
|
||||||
firewall.enable = 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 =
|
systemd.network.networks."01-eth1" = {
|
||||||
{ ... }:
|
name = "eth1";
|
||||||
{
|
networkConfig.Address = "10.0.0.1/24";
|
||||||
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 =
|
services.nginx = {
|
||||||
{ nodes, ... }:
|
enable = true;
|
||||||
''
|
statusPage = true;
|
||||||
start_all()
|
virtualHosts."localhost".locations."/index.html".return = "200 'hello world\n'";
|
||||||
|
};
|
||||||
|
|
||||||
webserver.wait_for_unit("nginx")
|
environment.systemPackages = with pkgs; [ curl ];
|
||||||
webserver.wait_for_open_port(80)
|
};
|
||||||
|
|
||||||
def expect_http_code(node, code, url):
|
client =
|
||||||
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}"
|
virtualisation.vlans = [ 1 ];
|
||||||
|
|
||||||
with subtest("localhost can access status page"):
|
networking = {
|
||||||
expect_http_code(webserver, "200", "http://localhost/nginx_status")
|
useNetworkd = true;
|
||||||
|
useDHCP = false;
|
||||||
|
firewall.enable = false;
|
||||||
|
};
|
||||||
|
|
||||||
with subtest("localhost can access other page"):
|
systemd.network.networks."01-eth1" = {
|
||||||
expect_http_code(webserver, "200", "http://localhost/index.html")
|
name = "eth1";
|
||||||
|
networkConfig.Address = "10.0.0.2/24";
|
||||||
|
};
|
||||||
|
|
||||||
with subtest("client can not access status page"):
|
environment.systemPackages = with pkgs; [ curl ];
|
||||||
expect_http_code(client, "403", "http://10.0.0.1/nginx_status")
|
};
|
||||||
|
};
|
||||||
|
|
||||||
with subtest("client can access other page"):
|
testScript =
|
||||||
expect_http_code(client, "200", "http://10.0.0.1/index.html")
|
{ 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")
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user