at 25.11-pre 2.2 kB view raw
1let 2 dst-dir = "/run/nginx-test-tmpdir-uploads"; 3in 4{ ... }: 5{ 6 name = "nginx-tmpdir"; 7 8 nodes.machine = 9 { pkgs, ... }: 10 { 11 environment.etc."tmpfiles.d/nginx-uploads.conf".text = "d ${dst-dir} 0755 nginx nginx 1d"; 12 13 # overwrite the tmp.conf with a short age, there will be a duplicate line info from systemd-tmpfiles in the log 14 systemd.tmpfiles.rules = [ 15 "q /tmp 1777 root root 1min" 16 ]; 17 18 services.nginx.enable = true; 19 # simple upload service using the nginx client body temp path 20 services.nginx.virtualHosts = { 21 localhost = { 22 locations."~ ^/upload/([0-9a-zA-Z-.]*)$" = { 23 extraConfig = '' 24 alias ${dst-dir}/$1; 25 client_body_in_file_only clean; 26 dav_methods PUT; 27 create_full_put_path on; 28 dav_access group:rw all:r; 29 ''; 30 }; 31 }; 32 }; 33 }; 34 35 testScript = '' 36 machine.wait_for_unit("nginx") 37 machine.wait_for_open_port(80) 38 39 with subtest("Needed prerequisite --http-client-body-temp-path=/tmp/nginx_client_body and private temp"): 40 machine.succeed("touch /tmp/systemd-private-*-nginx.service-*/tmp/nginx_client_body") 41 42 with subtest("Working upload of test setup"): 43 machine.succeed("curl -X PUT http://localhost/upload/test1 --fail --data-raw 'Raw data 1'") 44 machine.succeed('test "$(cat ${dst-dir}/test1)" = "Raw data 1"') 45 46 # let the tmpfiles clean service do its job 47 machine.succeed("touch /tmp/touched") 48 machine.wait_until_succeeds( 49 "sleep 15 && systemctl start systemd-tmpfiles-clean.service && [ ! -f /tmp/touched ]", 50 timeout=150 51 ) 52 53 with subtest("Working upload after cleaning"): 54 machine.succeed("curl -X PUT http://localhost/upload/test2 --fail --data-raw 'Raw data 2'") 55 machine.succeed('test "$(cat ${dst-dir}/test2)" = "Raw data 2"') 56 57 # manually remove the nginx temp dir 58 machine.succeed("rm -r --interactive=never /tmp/systemd-private-*-nginx.service-*/tmp/nginx_client_body") 59 60 with subtest("Broken upload after manual temp dir removal"): 61 machine.fail("curl -X PUT http://localhost/upload/test3 --fail --data-raw 'Raw data 3'") 62 ''; 63}