1 import ./make-test-python.nix ({ pkgs, ... }:
4 echoAll = pkgs.writeScript "echo-all" ''
5 #! ${pkgs.runtimeShell}
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 ];
15 name = "systemd-escaping";
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}
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]
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]