mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-13 13:40:28 +03:00
nixos/h2o: init module
Co-Authored-By: adisbladis <adis@blad.is>
This commit is contained in:
parent
311d8d0476
commit
2c1a09f1fe
8 changed files with 637 additions and 0 deletions
|
@ -420,6 +420,7 @@ in {
|
|||
guacamole-server = handleTest ./guacamole-server.nix {};
|
||||
guix = handleTest ./guix {};
|
||||
gvisor = handleTest ./gvisor.nix {};
|
||||
h2o = discoverTests (import ./web-servers/h2o { inherit handleTestOn; });
|
||||
hadoop = import ./hadoop { inherit handleTestOn; package=pkgs.hadoop; };
|
||||
hadoop_3_3 = import ./hadoop { inherit handleTestOn; package=pkgs.hadoop_3_3; };
|
||||
hadoop2 = import ./hadoop { inherit handleTestOn; package=pkgs.hadoop2; };
|
||||
|
|
138
nixos/tests/web-servers/h2o/basic.nix
Normal file
138
nixos/tests/web-servers/h2o/basic.nix
Normal file
|
@ -0,0 +1,138 @@
|
|||
import ../../make-test-python.nix (
|
||||
{ lib, pkgs, ... }:
|
||||
|
||||
# Tests basics such as TLS, creating a mime-type & serving Unicode characters.
|
||||
|
||||
let
|
||||
domain = {
|
||||
HTTP = "h2o.local";
|
||||
TLS = "acme.test";
|
||||
};
|
||||
|
||||
port = {
|
||||
HTTP = 8080;
|
||||
TLS = 8443;
|
||||
};
|
||||
|
||||
sawatdi_chao_lok = "สวัสดีชาวโลก";
|
||||
|
||||
hello_world_txt = pkgs.writeTextFile {
|
||||
name = "/hello_world.txt";
|
||||
text = sawatdi_chao_lok;
|
||||
};
|
||||
|
||||
hello_world_rst = pkgs.writeTextFile {
|
||||
name = "/hello_world.rst";
|
||||
text = # rst
|
||||
''
|
||||
====================
|
||||
Thaiger Sprint 2025‼
|
||||
====================
|
||||
|
||||
${sawatdi_chao_lok}
|
||||
'';
|
||||
};
|
||||
in
|
||||
{
|
||||
name = "h2o-basic";
|
||||
|
||||
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}";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
settings = {
|
||||
compress = "ON";
|
||||
compress-minimum-size = 32;
|
||||
"file.mime.addtypes" = {
|
||||
"text/x-rst" = {
|
||||
extensions = [ ".rst" ];
|
||||
is_compressible = "YES";
|
||||
};
|
||||
};
|
||||
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}
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
testScript = # python
|
||||
''
|
||||
server.wait_for_unit("h2o.service")
|
||||
|
||||
http_hello_world_body = server.succeed("curl --fail-with-body 'http://${domain.HTTP}:${builtins.toString port.HTTP}/hello_world.txt'")
|
||||
assert "${sawatdi_chao_lok}" in http_hello_world_body
|
||||
|
||||
tls_hello_world_head = server.succeed("curl -v --head --compressed --http2 --tlsv1.3 --fail-with-body 'https://${domain.TLS}:${builtins.toString port.TLS}/hello_world.rst'").lower()
|
||||
print(tls_hello_world_head)
|
||||
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
|
||||
|
||||
tls_hello_world_body = server.succeed("curl -v --http2 --tlsv1.3 --compressed --fail-with-body 'https://${domain.TLS}:${builtins.toString port.TLS}/hello_world.rst'")
|
||||
assert "${sawatdi_chao_lok}" in tls_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
|
||||
|
||||
server.fail("curl --location --max-redirs 0 'http://${domain.TLS}:${builtins.toString port.HTTP}/hello_world.rst'")
|
||||
|
||||
tls_hello_world_body_redirected = server.succeed("curl -v --location --fail-with-body 'http://${domain.TLS}:${builtins.toString port.HTTP}/hello_world.rst'")
|
||||
assert "${sawatdi_chao_lok}" in tls_hello_world_body_redirected
|
||||
'';
|
||||
}
|
||||
)
|
16
nixos/tests/web-servers/h2o/default.nix
Normal file
16
nixos/tests/web-servers/h2o/default.nix
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
system ? builtins.currentSystem,
|
||||
handleTestOn,
|
||||
}:
|
||||
|
||||
let
|
||||
supportedSystems = [
|
||||
"x86_64-linux"
|
||||
"i686-linux"
|
||||
"aarch64-linux"
|
||||
];
|
||||
in
|
||||
{
|
||||
basic = handleTestOn supportedSystems ./basic.nix { inherit system; };
|
||||
mruby = handleTestOn supportedSystems ./mruby.nix { inherit system; };
|
||||
}
|
3
nixos/tests/web-servers/h2o/file_handler.rb
Normal file
3
nixos/tests/web-servers/h2o/file_handler.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
Proc.new do |env|
|
||||
[200, {'content-type' => 'text/plain'}, ["FILE_HANDLER"]]
|
||||
end
|
64
nixos/tests/web-servers/h2o/mruby.nix
Normal file
64
nixos/tests/web-servers/h2o/mruby.nix
Normal file
|
@ -0,0 +1,64 @@
|
|||
import ../../make-test-python.nix (
|
||||
{ lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
domain = "h2o.local";
|
||||
|
||||
port = 8080;
|
||||
|
||||
sawatdi_chao_lok = "สวัสดีชาวโลก";
|
||||
in
|
||||
{
|
||||
name = "h2o-mruby";
|
||||
|
||||
meta = {
|
||||
maintainers = with lib.maintainers; [ toastal ];
|
||||
};
|
||||
|
||||
nodes = {
|
||||
server =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
services.h2o = {
|
||||
enable = true;
|
||||
package = pkgs.h2o.override { withMruby = true; };
|
||||
settings = {
|
||||
listen = port;
|
||||
hosts = {
|
||||
"${domain}" = {
|
||||
paths = {
|
||||
"/hello_world" = {
|
||||
"mruby.handler" = # ruby
|
||||
''
|
||||
Proc.new do |env|
|
||||
[200, {'content-type' => 'text/plain'}, ["${sawatdi_chao_lok}"]]
|
||||
end
|
||||
'';
|
||||
};
|
||||
"/file_handler" = {
|
||||
"mruby.handler-file" = ./file_handler.rb;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
networking.extraHosts = ''
|
||||
127.0.0.1 ${domain}
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
testScript = # python
|
||||
''
|
||||
server.wait_for_unit("h2o.service")
|
||||
|
||||
hello_world = server.succeed("curl --fail-with-body http://${domain}:${builtins.toString port}/hello_world")
|
||||
assert "${sawatdi_chao_lok}" in hello_world
|
||||
|
||||
file_handler = server.succeed("curl --fail-with-body http://${domain}:${builtins.toString port}/file_handler")
|
||||
assert "FILE_HANDLER" in file_handler
|
||||
'';
|
||||
}
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue