2 dst-dir = "/run/nginx-test-tmpdir-uploads";
4 import ./make-test-python.nix {
7 nodes.machine = { pkgs, ... }: {
8 environment.etc."tmpfiles.d/nginx-uploads.conf".text = "d ${dst-dir} 0755 nginx nginx 1d";
10 # overwrite the tmp.conf with a short age, there will be a duplicate line info from systemd-tmpfiles in the log
11 systemd.tmpfiles.rules = [
12 "q /tmp 1777 root root 1min"
15 services.nginx.enable = true;
16 # simple upload service using the nginx client body temp path
17 services.nginx.virtualHosts = {
19 locations."~ ^/upload/([0-9a-zA-Z-.]*)$" = {
22 client_body_in_file_only clean;
24 create_full_put_path on;
25 dav_access group:rw all:r;
33 machine.wait_for_unit("nginx")
34 machine.wait_for_open_port(80)
36 with subtest("Needed prerequisite --http-client-body-temp-path=/tmp/nginx_client_body and private temp"):
37 machine.succeed("touch /tmp/systemd-private-*-nginx.service-*/tmp/nginx_client_body")
39 with subtest("Working upload of test setup"):
40 machine.succeed("curl -X PUT http://localhost/upload/test1 --fail --data-raw 'Raw data 1'")
41 machine.succeed('test "$(cat ${dst-dir}/test1)" = "Raw data 1"')
43 # let the tmpfiles clean service do its job
44 machine.succeed("touch /tmp/touched")
45 machine.wait_until_succeeds(
46 "sleep 15 && systemctl start systemd-tmpfiles-clean.service && [ ! -f /tmp/touched ]",
50 with subtest("Working upload after cleaning"):
51 machine.succeed("curl -X PUT http://localhost/upload/test2 --fail --data-raw 'Raw data 2'")
52 machine.succeed('test "$(cat ${dst-dir}/test2)" = "Raw data 2"')
54 # manually remove the nginx temp dir
55 machine.succeed("rm -r --interactive=never /tmp/systemd-private-*-nginx.service-*/tmp/nginx_client_body")
57 with subtest("Broken upload after manual temp dir removal"):
58 machine.fail("curl -X PUT http://localhost/upload/test3 --fail --data-raw 'Raw data 3'")