tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
0
fork
atom
lol
0
fork
atom
overview
issues
pulls
pipelines
nixos/nginx: add test for status page
h7x4
2 years ago
25b7b82e
d803f78e
+74
-1
3 changed files
expand all
collapse all
unified
split
nixos
tests
all-tests.nix
nginx-status-page.nix
pkgs
servers
http
nginx
generic.nix
+1
nixos/tests/all-tests.nix
···
538
538
nginx-pubhtml = handleTest ./nginx-pubhtml.nix {};
539
539
nginx-sandbox = handleTestOn ["x86_64-linux"] ./nginx-sandbox.nix {};
540
540
nginx-sso = handleTest ./nginx-sso.nix {};
541
541
+
nginx-status-page = handleTest ./nginx-status-page.nix {};
541
542
nginx-variants = handleTest ./nginx-variants.nix {};
542
543
nginx-proxyprotocol = handleTest ./nginx-proxyprotocol {};
543
544
nifi = handleTestOn ["x86_64-linux"] ./web-apps/nifi.nix {};
+72
nixos/tests/nginx-status-page.nix
···
1
1
+
import ./make-test-python.nix ({ pkgs, ... }: {
2
2
+
name = "nginx-status-page";
3
3
+
meta = with pkgs.lib.maintainers; {
4
4
+
maintainers = [ h7x4 ];
5
5
+
};
6
6
+
7
7
+
nodes = {
8
8
+
webserver = { ... }: {
9
9
+
virtualisation.vlans = [ 1 ];
10
10
+
11
11
+
networking = {
12
12
+
useNetworkd = true;
13
13
+
useDHCP = false;
14
14
+
firewall.enable = false;
15
15
+
};
16
16
+
17
17
+
systemd.network.networks."01-eth1" = {
18
18
+
name = "eth1";
19
19
+
networkConfig.Address = "10.0.0.1/24";
20
20
+
};
21
21
+
22
22
+
services.nginx = {
23
23
+
enable = true;
24
24
+
statusPage = true;
25
25
+
virtualHosts."localhost".locations."/index.html".return = "200 'hello world\n'";
26
26
+
};
27
27
+
28
28
+
environment.systemPackages = with pkgs; [ curl ];
29
29
+
};
30
30
+
31
31
+
client = { ... }: {
32
32
+
virtualisation.vlans = [ 1 ];
33
33
+
34
34
+
networking = {
35
35
+
useNetworkd = true;
36
36
+
useDHCP = false;
37
37
+
firewall.enable = false;
38
38
+
};
39
39
+
40
40
+
systemd.network.networks."01-eth1" = {
41
41
+
name = "eth1";
42
42
+
networkConfig.Address = "10.0.0.2/24";
43
43
+
};
44
44
+
45
45
+
environment.systemPackages = with pkgs; [ curl ];
46
46
+
};
47
47
+
};
48
48
+
49
49
+
testScript = { nodes, ... }: ''
50
50
+
start_all()
51
51
+
52
52
+
webserver.wait_for_unit("nginx")
53
53
+
webserver.wait_for_open_port(80)
54
54
+
55
55
+
def expect_http_code(node, code, url):
56
56
+
http_code = node.succeed(f"curl -w '%{{http_code}}' '{url}'")
57
57
+
assert http_code.split("\n")[-1].strip() == code, \
58
58
+
f"expected {code} but got following response:\n{http_code}"
59
59
+
60
60
+
with subtest("localhost can access status page"):
61
61
+
expect_http_code(webserver, "200", "http://localhost/nginx_status")
62
62
+
63
63
+
with subtest("localhost can access other page"):
64
64
+
expect_http_code(webserver, "200", "http://localhost/index.html")
65
65
+
66
66
+
with subtest("client can not access status page"):
67
67
+
expect_http_code(client, "403", "http://10.0.0.1/nginx_status")
68
68
+
69
69
+
with subtest("client can access other page"):
70
70
+
expect_http_code(client, "200", "http://10.0.0.1/index.html")
71
71
+
'';
72
72
+
})
+1
-1
pkgs/servers/http/nginx/generic.nix
···
178
178
passthru = {
179
179
inherit modules;
180
180
tests = {
181
181
-
inherit (nixosTests) nginx nginx-auth nginx-etag nginx-globalredirect nginx-http3 nginx-pubhtml nginx-sandbox nginx-sso nginx-proxyprotocol;
181
181
+
inherit (nixosTests) nginx nginx-auth nginx-etag nginx-globalredirect nginx-http3 nginx-pubhtml nginx-sandbox nginx-sso nginx-proxyprotocol nginx-status-page;
182
182
variants = lib.recurseIntoAttrs nixosTests.nginx-variants;
183
183
acme-integration = nixosTests.acme;
184
184
} // passthru.tests;