about summary refs log tree commit diff
path: root/nixpkgs/nixos/tests/nginx-http3.nix
blob: 22f7f61f10ce68bec47d9ee7ead87c8f3f048372 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
{ system ? builtins.currentSystem,
  config ? {},
  pkgs ? import ../.. { inherit system config; }
}:

with import ../lib/testing-python.nix { inherit system pkgs; };

let
  hosts = ''
    192.168.2.101 acme.test
  '';

in

builtins.listToAttrs (
  builtins.map
    (nginxPackage:
      {
        name = pkgs.lib.getName nginxPackage;
        value = makeTest {
          name = "nginx-http3-${pkgs.lib.getName nginxPackage}";
          meta.maintainers = with pkgs.lib.maintainers; [ izorkin ];

          nodes = {
            server = { lib, pkgs, ... }: {
              networking = {
                interfaces.eth1 = {
                  ipv4.addresses = [
                    { address = "192.168.2.101"; prefixLength = 24; }
                  ];
                };
                extraHosts = hosts;
                firewall.allowedTCPPorts = [ 443 ];
                firewall.allowedUDPPorts = [ 443 ];
              };

              security.pki.certificates = [
                (builtins.readFile ./common/acme/server/ca.cert.pem)
              ];

              services.nginx = {
                enable = true;
                package = nginxPackage;

                virtualHosts."acme.test" = {
                  onlySSL = true;
                  sslCertificate = ./common/acme/server/acme.test.cert.pem;
                  sslCertificateKey = ./common/acme/server/acme.test.key.pem;
                  http2 = true;
                  http3 = true;
                  http3_hq = false;
                  quic = true;
                  reuseport = true;
                  root = lib.mkForce (pkgs.runCommandLocal "testdir" {} ''
                    mkdir "$out"
                    cat > "$out/index.html" <<EOF
                    <html><body>Hello World!</body></html>
                    EOF
                    cat > "$out/example.txt" <<EOF
                    Check http3 protocol.
                    EOF
                  '');
                };
              };
            };

            client = { pkgs, ... }: {
              environment.systemPackages = [ pkgs.curlHTTP3 ];
              networking = {
                interfaces.eth1 = {
                  ipv4.addresses = [
                    { address = "192.168.2.201"; prefixLength = 24; }
                  ];
                };
                extraHosts = hosts;
              };

              security.pki.certificates = [
                (builtins.readFile ./common/acme/server/ca.cert.pem)
              ];
            };
          };

          testScript = ''
            start_all()

            server.wait_for_unit("nginx")
            server.wait_for_open_port(443)

            # Check http connections
            client.succeed("curl --verbose --http3-only https://acme.test | grep 'Hello World!'")

            # Check downloadings
            client.succeed("curl --verbose --http3-only https://acme.test/example.txt --output /tmp/example.txt")
            client.succeed("cat /tmp/example.txt | grep 'Check http3 protocol.'")

            # Check header reading
            client.succeed("curl --verbose --http3-only --head https://acme.test | grep 'content-type'")
            client.succeed("curl --verbose --http3-only --head https://acme.test | grep 'HTTP/3 200'")
            client.succeed("curl --verbose --http3-only --head https://acme.test/error | grep 'HTTP/3 404'")

            # Check change User-Agent
            client.succeed("curl --verbose --http3-only --user-agent 'Curl test 3.0' https://acme.test")
            server.succeed("cat /var/log/nginx/access.log | grep 'Curl test 3.0'")

            server.shutdown()
            client.shutdown()
          '';
        };
      }
    )
    [ pkgs.angieQuic pkgs.nginxQuic ]
)