mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-13 21:50:33 +03:00
nixos/h2o: move to runTest
This commit is contained in:
parent
b828ba3247
commit
1905cd89f8
5 changed files with 276 additions and 292 deletions
|
@ -1,144 +1,142 @@
|
|||
import ../../make-test-python.nix (
|
||||
{ lib, pkgs, ... }:
|
||||
{ hostPkgs, lib, ... }:
|
||||
|
||||
# Tests basics such as TLS, creating a mime-type & serving Unicode characters.
|
||||
# Tests basics such as TLS, creating a mime-type & serving Unicode characters.
|
||||
|
||||
let
|
||||
domain = {
|
||||
HTTP = "h2o.local";
|
||||
TLS = "acme.test";
|
||||
};
|
||||
let
|
||||
domain = {
|
||||
HTTP = "h2o.local";
|
||||
TLS = "acme.test";
|
||||
};
|
||||
|
||||
port = {
|
||||
HTTP = 8080;
|
||||
TLS = 8443;
|
||||
};
|
||||
port = {
|
||||
HTTP = 8080;
|
||||
TLS = 8443;
|
||||
};
|
||||
|
||||
sawatdi_chao_lok = "สวัสดีชาวโลก";
|
||||
sawatdi_chao_lok = "สวัสดีชาวโลก";
|
||||
|
||||
hello_world_txt = pkgs.writeTextFile {
|
||||
name = "/hello_world.txt";
|
||||
text = sawatdi_chao_lok;
|
||||
};
|
||||
hello_world_txt = hostPkgs.writeTextFile {
|
||||
name = "/hello_world.txt";
|
||||
text = sawatdi_chao_lok;
|
||||
};
|
||||
|
||||
hello_world_rst = pkgs.writeTextFile {
|
||||
name = "/hello_world.rst";
|
||||
text = # rst
|
||||
''
|
||||
====================
|
||||
Thaiger Sprint 2025‼
|
||||
====================
|
||||
hello_world_rst = hostPkgs.writeTextFile {
|
||||
name = "/hello_world.rst";
|
||||
text = # rst
|
||||
''
|
||||
====================
|
||||
Thaiger Sprint 2025‼
|
||||
====================
|
||||
|
||||
${sawatdi_chao_lok}
|
||||
'';
|
||||
};
|
||||
in
|
||||
{
|
||||
name = "h2o-basic";
|
||||
${sawatdi_chao_lok}
|
||||
'';
|
||||
};
|
||||
in
|
||||
{
|
||||
name = "h2o-basic";
|
||||
|
||||
meta = {
|
||||
maintainers = with lib.maintainers; [ toastal ];
|
||||
};
|
||||
meta = {
|
||||
maintainers = with lib.maintainers; [ toastal ];
|
||||
};
|
||||
|
||||
nodes = {
|
||||
server =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
services.h2o = {
|
||||
enable = true;
|
||||
defaultHTTPListenPort = port.HTTP;
|
||||
defaultTLSListenPort = port.TLS;
|
||||
hosts = {
|
||||
"${domain.HTTP}" = {
|
||||
settings = {
|
||||
paths = {
|
||||
"/hello_world.txt" = {
|
||||
"file.file" = "${hello_world_txt}";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
"${domain.TLS}" = {
|
||||
tls = {
|
||||
policy = "force";
|
||||
identity = [
|
||||
{
|
||||
key-file = ../../common/acme/server/acme.test.key.pem;
|
||||
certificate-file = ../../common/acme/server/acme.test.cert.pem;
|
||||
}
|
||||
];
|
||||
extraSettings = {
|
||||
minimum-version = "TLSv1.3";
|
||||
};
|
||||
};
|
||||
settings = {
|
||||
paths = {
|
||||
"/hello_world.rst" = {
|
||||
"file.file" = "${hello_world_rst}";
|
||||
};
|
||||
nodes = {
|
||||
server =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
services.h2o = {
|
||||
enable = true;
|
||||
defaultHTTPListenPort = port.HTTP;
|
||||
defaultTLSListenPort = port.TLS;
|
||||
hosts = {
|
||||
"${domain.HTTP}" = {
|
||||
settings = {
|
||||
paths = {
|
||||
"/hello_world.txt" = {
|
||||
"file.file" = "${hello_world_txt}";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
settings = {
|
||||
compress = "ON";
|
||||
compress-minimum-size = 32;
|
||||
"file.mime.addtypes" = {
|
||||
"text/x-rst" = {
|
||||
extensions = [ ".rst" ];
|
||||
is_compressible = "YES";
|
||||
"${domain.TLS}" = {
|
||||
tls = {
|
||||
policy = "force";
|
||||
identity = [
|
||||
{
|
||||
key-file = ../../common/acme/server/acme.test.key.pem;
|
||||
certificate-file = ../../common/acme/server/acme.test.cert.pem;
|
||||
}
|
||||
];
|
||||
extraSettings = {
|
||||
minimum-version = "TLSv1.3";
|
||||
};
|
||||
};
|
||||
settings = {
|
||||
paths = {
|
||||
"/hello_world.rst" = {
|
||||
"file.file" = "${hello_world_rst}";
|
||||
};
|
||||
};
|
||||
};
|
||||
ssl-offload = "kernel";
|
||||
};
|
||||
};
|
||||
|
||||
security.pki.certificates = [
|
||||
(builtins.readFile ../../common/acme/server/ca.cert.pem)
|
||||
];
|
||||
|
||||
networking = {
|
||||
firewall.allowedTCPPorts = with port; [
|
||||
HTTP
|
||||
TLS
|
||||
];
|
||||
extraHosts = ''
|
||||
127.0.0.1 ${domain.HTTP}
|
||||
127.0.0.1 ${domain.TLS}
|
||||
'';
|
||||
settings = {
|
||||
compress = "ON";
|
||||
compress-minimum-size = 32;
|
||||
"file.mime.addtypes" = {
|
||||
"text/x-rst" = {
|
||||
extensions = [ ".rst" ];
|
||||
is_compressible = "YES";
|
||||
};
|
||||
};
|
||||
ssl-offload = "kernel";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
testScript =
|
||||
let
|
||||
portStrHTTP = builtins.toString port.HTTP;
|
||||
portStrTLS = builtins.toString port.TLS;
|
||||
in
|
||||
# python
|
||||
''
|
||||
server.wait_for_unit("h2o.service")
|
||||
server.wait_for_open_port(${portStrHTTP})
|
||||
server.wait_for_open_port(${portStrTLS})
|
||||
security.pki.certificates = [
|
||||
(builtins.readFile ../../common/acme/server/ca.cert.pem)
|
||||
];
|
||||
|
||||
http_hello_world_body = server.succeed("curl --fail-with-body 'http://${domain.HTTP}:${portStrHTTP}/hello_world.txt'")
|
||||
assert "${sawatdi_chao_lok}" in http_hello_world_body
|
||||
networking = {
|
||||
firewall.allowedTCPPorts = with port; [
|
||||
HTTP
|
||||
TLS
|
||||
];
|
||||
extraHosts = ''
|
||||
127.0.0.1 ${domain.HTTP}
|
||||
127.0.0.1 ${domain.TLS}
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
tls_hello_world_head = server.succeed("curl -v --head --compressed --http2 --tlsv1.3 --fail-with-body 'https://${domain.TLS}:${portStrTLS}/hello_world.rst'").lower()
|
||||
assert "http/2 200" in tls_hello_world_head
|
||||
assert "server: h2o" in tls_hello_world_head
|
||||
assert "content-type: text/x-rst" in tls_hello_world_head
|
||||
testScript =
|
||||
let
|
||||
portStrHTTP = builtins.toString port.HTTP;
|
||||
portStrTLS = builtins.toString port.TLS;
|
||||
in
|
||||
# python
|
||||
''
|
||||
server.wait_for_unit("h2o.service")
|
||||
server.wait_for_open_port(${portStrHTTP})
|
||||
server.wait_for_open_port(${portStrTLS})
|
||||
|
||||
tls_hello_world_body = server.succeed("curl -v --http2 --tlsv1.3 --compressed --fail-with-body 'https://${domain.TLS}:${portStrTLS}/hello_world.rst'")
|
||||
assert "${sawatdi_chao_lok}" in tls_hello_world_body
|
||||
http_hello_world_body = server.succeed("curl --fail-with-body 'http://${domain.HTTP}:${portStrHTTP}/hello_world.txt'")
|
||||
assert "${sawatdi_chao_lok}" in http_hello_world_body
|
||||
|
||||
tls_hello_world_head_redirected = server.succeed("curl -v --head --fail-with-body 'http://${domain.TLS}:${builtins.toString port.HTTP}/hello_world.rst'").lower()
|
||||
assert "redirected" in tls_hello_world_head_redirected
|
||||
tls_hello_world_head = server.succeed("curl -v --head --compressed --http2 --tlsv1.3 --fail-with-body 'https://${domain.TLS}:${portStrTLS}/hello_world.rst'").lower()
|
||||
assert "http/2 200" in tls_hello_world_head
|
||||
assert "server: h2o" in tls_hello_world_head
|
||||
assert "content-type: text/x-rst" in tls_hello_world_head
|
||||
|
||||
server.fail("curl --location --max-redirs 0 'http://${domain.TLS}:${portStrHTTP}/hello_world.rst'")
|
||||
tls_hello_world_body = server.succeed("curl -v --http2 --tlsv1.3 --compressed --fail-with-body 'https://${domain.TLS}:${portStrTLS}/hello_world.rst'")
|
||||
assert "${sawatdi_chao_lok}" in tls_hello_world_body
|
||||
|
||||
tls_hello_world_body_redirected = server.succeed("curl -v --location --fail-with-body 'http://${domain.TLS}:${portStrHTTP}/hello_world.rst'")
|
||||
assert "${sawatdi_chao_lok}" in tls_hello_world_body_redirected
|
||||
'';
|
||||
}
|
||||
)
|
||||
tls_hello_world_head_redirected = server.succeed("curl -v --head --fail-with-body 'http://${domain.TLS}:${builtins.toString port.HTTP}/hello_world.rst'").lower()
|
||||
assert "redirected" in tls_hello_world_head_redirected
|
||||
|
||||
server.fail("curl --location --max-redirs 0 'http://${domain.TLS}:${portStrHTTP}/hello_world.rst'")
|
||||
|
||||
tls_hello_world_body_redirected = server.succeed("curl -v --location --fail-with-body 'http://${domain.TLS}:${portStrHTTP}/hello_world.rst'")
|
||||
assert "${sawatdi_chao_lok}" in tls_hello_world_body_redirected
|
||||
'';
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue