From 9b5a119972e9c2d327500638d89063f4fce243ec Mon Sep 17 00:00:00 2001 From: aszlig Date: Sun, 29 Apr 2018 19:38:24 +0200 Subject: pkgs/sandbox: Fix and pass through .desktop files Since the introduction and move of a few packages to use the sandbox, we no longer have XDG desktop entries, because the sandbox only creates wrappers for all programs in $drv/bin. This now also copies the XDG desktop files and replaces absolute paths to binaries to refer to the sandboxed binaries. I also modified the test to go through the XDG desktop file by default so we can ensure that this works properly. Signed-off-by: aszlig --- tests/sandbox.nix | 93 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 70 insertions(+), 23 deletions(-) (limited to 'tests') diff --git a/tests/sandbox.nix b/tests/sandbox.nix index 9a1b4a3a..20ae88d6 100644 --- a/tests/sandbox.nix +++ b/tests/sandbox.nix @@ -12,39 +12,86 @@ "/run/bar-test-sandbox" "/run/baz-test-sandbox" ]; + + # Only needed so we get the right XDG paths in the system path. + services.xserver.enable = true; + systemd.services.display-manager.enable = false; + environment.systemPackages = let - testProgram = pkgs.writeScriptBin "test-sandbox" '' - #!${pkgs.stdenv.shell} -ex + testPackage = pkgs.runCommand "test-sandbox" { + program = '' + #!${pkgs.stdenv.shell} -ex + + if [ "$1" != canary ]; then + echo 'Canary check failed, so the test program probably' \ + 'was not executed via the XDG desktop entry.' >&2 + exit 1 + fi + + # Should fail because we can't access the host's PATH + ! echo foo | grep -qF foo + + export PATH=/run/baz-test-sandbox/bin + echo foo > /home/foo/existing/bar + test ! -d /home/foo/nonexisting + /run/foo-test-sandbox/bin/hello + echo aaa | /run/bar-test-sandbox/bin/sed -e 's/a/b/g' - # Should fail because we can't access the host's PATH - ! echo foo | grep -qF foo + echo XDG1 > /home/foo/.local/share/xdg/1 + echo XDG2 > /home/foo/.config/xdg/2 + echo XDG3 > /home/foo/.cache/xdg/3 + echo > /home/foo/.cache/xdg/done + ''; + } '' + mkdir -p "$out/bin" "$out/share/applications" "$out/share/test-sandbox" - export PATH=/run/baz-test-sandbox/bin - echo foo > /home/foo/existing/bar - test ! -d /home/foo/nonexisting - /run/foo-test-sandbox/bin/hello - echo aaa | /run/bar-test-sandbox/bin/sed -e 's/a/b/g' + echo -n "$program" > "$out/bin/test-sandbox" + chmod +x "$out/bin/test-sandbox" - echo XDG1 > /home/foo/.local/share/xdg/1 - echo XDG2 > /home/foo/.config/xdg/2 - echo XDG3 > /home/foo/.cache/xdg/3 + echo '' \ + > "$out/share/test-sandbox/icon.svg" + + cat > "$out/share/applications/test.desktop" <waitForUnit('multi-user.target'); - $machine->succeed('su - -c test-sandbox foo >&2'); + $machine->succeed('su - -c "xvfb-run gtk-launch test" foo >&2'); + $machine->waitForFile('/home/foo/.cache/xdg/done'); $machine->succeed('test -d /home/foo/existing'); $machine->succeed('grep -qF foo /home/foo/existing/bar'); -- cgit 1.4.1