at 23.11-pre 1.7 kB view raw
1import ./make-test-python.nix ({ pkgs, ... }: 2 3let 4 echoAll = pkgs.writeScript "echo-all" '' 5 #! ${pkgs.runtimeShell} 6 for s in "$@"; do 7 printf '%s\n' "$s" 8 done 9 ''; 10 # deliberately using a local empty file instead of pkgs.emptyFile to have 11 # a non-store path in the test 12 args = [ "a%Nything" "lang=\${LANG}" ";" "/bin/sh -c date" ./empty-file 4.2 23 ]; 13in 14{ 15 name = "systemd-escaping"; 16 17 nodes.machine = { pkgs, lib, utils, ... }: { 18 systemd.services.echo = 19 assert !(builtins.tryEval (utils.escapeSystemdExecArgs [ [] ])).success; 20 assert !(builtins.tryEval (utils.escapeSystemdExecArgs [ {} ])).success; 21 assert !(builtins.tryEval (utils.escapeSystemdExecArgs [ null ])).success; 22 assert !(builtins.tryEval (utils.escapeSystemdExecArgs [ false ])).success; 23 assert !(builtins.tryEval (utils.escapeSystemdExecArgs [ (_:_) ])).success; 24 { description = "Echo to the journal"; 25 serviceConfig.Type = "oneshot"; 26 serviceConfig.ExecStart = '' 27 ${echoAll} ${utils.escapeSystemdExecArgs args} 28 ''; 29 }; 30 }; 31 32 testScript = '' 33 machine.wait_for_unit("multi-user.target") 34 machine.succeed("systemctl start echo.service") 35 # skip the first 'Starting <service> ...' line 36 logs = machine.succeed("journalctl -u echo.service -o cat").splitlines()[1:] 37 assert "a%Nything" == logs[0] 38 assert "lang=''${LANG}" == logs[1] 39 assert ";" == logs[2] 40 assert "/bin/sh -c date" == logs[3] 41 assert "/nix/store/ij3gw72f4n5z4dz6nnzl1731p9kmjbwr-empty-file" == logs[4] 42 assert "4.2" in logs[5] # toString produces extra fractional digits! 43 assert "23" == logs[6] 44 ''; 45})