postgresqlPackages.sqlite_fdw: 2.4.0 -> 2.5.0 (#364337)
[NixPkgs.git] / nixos / tests / nginx-http3.nix
blobd9f4b072f25eca4b1f79f8b22afca54514d5b61c
2   system ? builtins.currentSystem,
3   config ? { },
4   pkgs ? import ../.. { inherit system config; },
5 }:
7 with import ../lib/testing-python.nix { inherit system pkgs; };
9 let
10   hosts = ''
11     192.168.2.101 acme.test
12   '';
16 builtins.listToAttrs (
17   builtins.map
18     (nginxPackage: {
19       name = pkgs.lib.getName nginxPackage;
20       value = makeTest {
21         name = "nginx-http3-${pkgs.lib.getName nginxPackage}";
22         meta.maintainers = with pkgs.lib.maintainers; [ izorkin ];
24         nodes = {
25           server =
26             { lib, pkgs, ... }:
27             {
28               networking = {
29                 interfaces.eth1 = {
30                   ipv4.addresses = [
31                     {
32                       address = "192.168.2.101";
33                       prefixLength = 24;
34                     }
35                   ];
36                 };
37                 extraHosts = hosts;
38                 firewall.allowedTCPPorts = [ 443 ];
39                 firewall.allowedUDPPorts = [ 443 ];
40               };
42               security.pki.certificates = [
43                 (builtins.readFile ./common/acme/server/ca.cert.pem)
44               ];
46               services.nginx = {
47                 enable = true;
48                 package = nginxPackage;
50                 virtualHosts."acme.test" = {
51                   onlySSL = true;
52                   sslCertificate = ./common/acme/server/acme.test.cert.pem;
53                   sslCertificateKey = ./common/acme/server/acme.test.key.pem;
54                   http2 = true;
55                   http3 = true;
56                   http3_hq = false;
57                   quic = true;
58                   reuseport = true;
59                   root = lib.mkForce (
60                     pkgs.runCommandLocal "testdir" { } ''
61                       mkdir "$out"
62                       cat > "$out/index.html" <<EOF
63                       <html><body>Hello World!</body></html>
64                       EOF
65                       cat > "$out/example.txt" <<EOF
66                       Check http3 protocol.
67                       EOF
68                     ''
69                   );
70                 };
71               };
72             };
74           client =
75             { pkgs, ... }:
76             {
77               environment.systemPackages = [ pkgs.curlHTTP3 ];
78               networking = {
79                 interfaces.eth1 = {
80                   ipv4.addresses = [
81                     {
82                       address = "192.168.2.201";
83                       prefixLength = 24;
84                     }
85                   ];
86                 };
87                 extraHosts = hosts;
88               };
90               security.pki.certificates = [
91                 (builtins.readFile ./common/acme/server/ca.cert.pem)
92               ];
93             };
94         };
96         testScript = ''
97           start_all()
99           server.wait_for_unit("nginx")
100           server.wait_for_open_port(443)
102           # Check http connections
103           client.succeed("curl --verbose --http3-only https://acme.test | grep 'Hello World!'")
105           # Check downloadings
106           client.succeed("curl --verbose --http3-only https://acme.test/example.txt --output /tmp/example.txt")
107           client.succeed("cat /tmp/example.txt | grep 'Check http3 protocol.'")
109           # Check header reading
110           client.succeed("curl --verbose --http3-only --head https://acme.test | grep 'content-type'")
111           client.succeed("curl --verbose --http3-only --head https://acme.test | grep 'HTTP/3 200'")
112           client.succeed("curl --verbose --http3-only --head https://acme.test/error | grep 'HTTP/3 404'")
114           # Check change User-Agent
115           client.succeed("curl --verbose --http3-only --user-agent 'Curl test 3.0' https://acme.test")
116           server.succeed("cat /var/log/nginx/access.log | grep 'Curl test 3.0'")
118           server.shutdown()
119           client.shutdown()
120         '';
121       };
122     })
123     [
124       pkgs.angieQuic
125       pkgs.nginxQuic
126     ]