at 23.11-beta 2.3 kB view raw
1let 2 dst-dir = "/run/nginx-test-tmpdir-uploads"; 3in 4 import ./make-test-python.nix { 5 name = "nginx-tmpdir"; 6 7 nodes.machine = { pkgs, ... }: { 8 environment.etc."tmpfiles.d/nginx-uploads.conf".text = "d ${dst-dir} 0755 nginx nginx 1d"; 9 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" 13 ]; 14 15 services.nginx.enable = true; 16 # simple upload service using the nginx client body temp path 17 services.nginx.virtualHosts = { 18 localhost = { 19 locations."~ ^/upload/([0-9a-zA-Z-.]*)$" = { 20 extraConfig = '' 21 alias ${dst-dir}/$1; 22 client_body_in_file_only clean; 23 dav_methods PUT; 24 create_full_put_path on; 25 dav_access group:rw all:r; 26 ''; 27 }; 28 }; 29 }; 30 }; 31 32 testScript = '' 33 machine.wait_for_unit("nginx") 34 machine.wait_for_open_port(80) 35 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") 38 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"') 42 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 ]", 47 timeout=150 48 ) 49 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"') 53 54 # manually remove the nginx temp dir 55 machine.succeed("rm -r --interactive=never /tmp/systemd-private-*-nginx.service-*/tmp/nginx_client_body") 56 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'") 59 ''; 60 }