Skip to content

Commit cb89189

Browse files
committed
nixos/tests/h2o: use client to check + start_all() machines
1 parent 9ab2c76 commit cb89189

File tree

3 files changed

+52
-21
lines changed

3 files changed

+52
-21
lines changed

nixos/tests/web-servers/h2o/basic.nix

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,8 @@ in
3636

3737
nodes = {
3838
server =
39-
{ pkgs, config, ... }:
39+
{ config, ... }:
4040
{
41-
environment.systemPackages = [
42-
pkgs.curl
43-
];
44-
4541
services.h2o = {
4642
enable = true;
4743
defaultHTTPListenPort = 8080;
@@ -111,12 +107,30 @@ in
111107
];
112108
};
113109
extraHosts = ''
114-
127.0.0.1 ${domain.HTTP}
115-
127.0.0.1 ${domain.TLS}
110+
${config.networking.primaryIPAddress} ${domain.HTTP}
111+
${config.networking.primaryIPAddress} ${domain.TLS}
116112
'';
117113
};
118114
};
115+
116+
client =
117+
{ nodes, pkgs, ... }:
118+
{
119+
environment.systemPackages = [
120+
pkgs.curl
121+
];
122+
123+
security.pki.certificates = [
124+
(builtins.readFile ../../common/acme/server/ca.cert.pem)
125+
];
126+
127+
networking.extraHosts = ''
128+
${nodes.server.networking.primaryIPAddress} ${domain.HTTP}
129+
${nodes.server.networking.primaryIPAddress} ${domain.TLS}
130+
'';
131+
};
119132
};
133+
120134
testScript =
121135
{ nodes, ... }:
122136
let
@@ -126,30 +140,32 @@ in
126140
in
127141
# python
128142
''
143+
start_all()
144+
129145
server.wait_for_unit("h2o.service")
130146
server.wait_for_open_port(${portStrHTTP})
131147
server.wait_for_open_port(${portStrTLS})
132148
133-
assert "${sawatdi_chao_lok}" in server.succeed("curl --fail-with-body 'http://${domain.HTTP}:${portStrHTTP}/hello_world.txt'")
149+
assert "${sawatdi_chao_lok}" in client.succeed("curl --fail-with-body 'http://${domain.HTTP}:${portStrHTTP}/hello_world.txt'")
134150
135-
tls_hello_world_head = server.succeed("curl -v --head --compressed --http2 --tlsv1.3 --fail-with-body 'https://${domain.TLS}:${portStrTLS}/hello_world.rst'").lower()
151+
tls_hello_world_head = client.succeed("curl -v --head --compressed --http2 --tlsv1.3 --fail-with-body 'https://${domain.TLS}:${portStrTLS}/hello_world.rst'").lower()
136152
assert "http/2 200" in tls_hello_world_head
137153
assert "server: h2o" in tls_hello_world_head
138154
assert "content-type: text/x-rst" in tls_hello_world_head
139155
140-
assert "${sawatdi_chao_lok}" in server.succeed("curl -v --http2 --tlsv1.3 --compressed --fail-with-body 'https://${domain.TLS}:${portStrTLS}/hello_world.rst'")
156+
assert "${sawatdi_chao_lok}" in client.succeed("curl -v --http2 --tlsv1.3 --compressed --fail-with-body 'https://${domain.TLS}:${portStrTLS}/hello_world.rst'")
141157
142-
quic_hello_world_head = server.succeed("curl -v --head --compressed --http3-only --fail-with-body 'https://${domain.TLS}:${portStrTLS}/hello_world.rst'").lower()
158+
quic_hello_world_head = client.succeed("curl -v --head --compressed --http3-only --fail-with-body 'https://${domain.TLS}:${portStrTLS}/hello_world.rst'").lower()
143159
assert "http/3 200" in quic_hello_world_head
144160
assert "server: h2o" in quic_hello_world_head
145161
assert "content-type: text/x-rst" in quic_hello_world_head
146162
147-
assert "${sawatdi_chao_lok}" in server.succeed("curl -v --http3-only --compressed --fail-with-body 'https://${domain.TLS}:${portStrTLS}/hello_world.rst'")
163+
assert "${sawatdi_chao_lok}" in client.succeed("curl -v --http3-only --compressed --fail-with-body 'https://${domain.TLS}:${portStrTLS}/hello_world.rst'")
148164
149-
assert "redirected" in server.succeed("curl -v --head --fail-with-body 'http://${domain.TLS}:${portStrHTTP}/hello_world.rst'").lower()
165+
assert "redirected" in client.succeed("curl -v --head --fail-with-body 'http://${domain.TLS}:${portStrHTTP}/hello_world.rst'").lower()
150166
151-
server.fail("curl --location --max-redirs 0 'http://${domain.TLS}:${portStrHTTP}/hello_world.rst'")
167+
client.fail("curl --location --max-redirs 0 'http://${domain.TLS}:${portStrHTTP}/hello_world.rst'")
152168
153-
assert "${sawatdi_chao_lok}" in server.succeed("curl -v --location --fail-with-body 'http://${domain.TLS}:${portStrHTTP}/hello_world.rst'")
169+
assert "${sawatdi_chao_lok}" in client.succeed("curl -v --location --fail-with-body 'http://${domain.TLS}:${portStrHTTP}/hello_world.rst'")
154170
'';
155171
}

nixos/tests/web-servers/h2o/mruby.nix

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ in
1414

1515
nodes = {
1616
server =
17-
{ pkgs, ... }:
17+
{ pkgs, config, ... }:
1818
{
1919
services.h2o = {
2020
enable = true;
@@ -41,9 +41,17 @@ in
4141
};
4242
};
4343

44-
networking.extraHosts = ''
45-
127.0.0.1 ${domain}
46-
'';
44+
networking.firewall.allowedTCPPorts = [
45+
config.services.h2o.settings.listen
46+
];
47+
};
48+
49+
client =
50+
{ pkgs, ... }:
51+
{
52+
environment.systemPackages = [
53+
pkgs.curl
54+
];
4755
};
4856
};
4957

@@ -52,14 +60,17 @@ in
5260
let
5361
inherit (nodes) server;
5462
portStr = builtins.toString server.services.h2o.settings.listen;
63+
origin = "http://server:${portStr}";
5564
in
5665
# python
5766
''
67+
start_all()
68+
5869
server.wait_for_unit("h2o.service")
5970
server.wait_for_open_port(${portStr})
6071
61-
assert "${sawatdi_chao_lok}" in server.succeed("curl --fail-with-body http://${domain}:${portStr}/hello_world")
72+
assert "${sawatdi_chao_lok}" in client.succeed("curl --fail-with-body ${origin}/hello_world")
6273
63-
assert "FILE_HANDLER" in server.succeed("curl --fail-with-body http://${domain}:${portStr}/file_handler")
74+
assert "FILE_HANDLER" in client.succeed("curl --fail-with-body ${origin}/file_handler")
6475
'';
6576
}

nixos/tests/web-servers/h2o/tls-recommendations.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ in
7878
maintainers = with lib.maintainers; [ toastal ];
7979
};
8080

81+
# not using a `client` since it’s easiest to test with acme.test pointing at
82+
# localhost for these machines
8183
nodes = {
8284
server_modern = mkH2OServer "modern";
8385
server_intermediate = mkH2OServer "intermediate";
@@ -100,6 +102,8 @@ in
100102
curl_max_tls1_2_intermediate_cipher ="curl -v --tlsv1.0 --tls-max 1.2 --ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256' 'https://${domain}:{port}/'"
101103
curl_max_tls1_2_old_cipher ="curl -v --tlsv1.0 --tls-max 1.2 --ciphers 'ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256' 'https://${domain}:{port}/'"
102104
105+
start_all()
106+
103107
server_modern.wait_for_unit("h2o.service")
104108
server_modern.wait_for_open_port(${modernPortStr})
105109
modern_response = server_modern.succeed(curl_basic.format(port="${modernPortStr}"))

0 commit comments

Comments
 (0)