2019-11-05 21:13:16 +00:00
|
|
|
import ./make-test-python.nix ({ pkgs, ... }:
|
2014-04-19 12:37:05 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2024-04-21 07:15:22 +00:00
|
|
|
# FIXME: 404s
|
2014-04-19 12:37:05 +00:00
|
|
|
stick = pkgs.fetchurl {
|
2020-04-18 20:51:19 +00:00
|
|
|
url = "https://nixos.org/~eelco/nix/udisks-test.img.xz";
|
2014-04-19 12:37:05 +00:00
|
|
|
sha256 = "0was1xgjkjad91nipzclaz5biv3m4b2nk029ga6nk7iklwi19l8b";
|
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2014-06-28 14:04:49 +00:00
|
|
|
name = "udisks2";
|
2021-01-10 19:08:30 +00:00
|
|
|
meta = with pkgs.lib.maintainers; {
|
2024-04-21 07:15:22 +00:00
|
|
|
maintainers = [ ];
|
2015-07-12 10:09:40 +00:00
|
|
|
};
|
2014-04-19 12:37:05 +00:00
|
|
|
|
2022-03-20 23:15:30 +00:00
|
|
|
nodes.machine =
|
2018-07-20 20:56:59 +00:00
|
|
|
{ ... }:
|
2014-04-19 12:37:05 +00:00
|
|
|
{ services.udisks2.enable = true;
|
|
|
|
imports = [ ./common/user-account.nix ];
|
|
|
|
|
|
|
|
security.polkit.extraConfig =
|
|
|
|
''
|
|
|
|
polkit.addRule(function(action, subject) {
|
|
|
|
if (subject.user == "alice") return "yes";
|
|
|
|
});
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript =
|
|
|
|
''
|
2019-11-05 21:13:16 +00:00
|
|
|
import lzma
|
2014-04-19 12:37:05 +00:00
|
|
|
|
2023-11-12 09:09:58 +00:00
|
|
|
machine.systemctl("start udisks2")
|
|
|
|
machine.wait_for_unit("udisks2.service")
|
|
|
|
|
2019-11-05 21:13:16 +00:00
|
|
|
with lzma.open(
|
|
|
|
"${stick}"
|
2021-09-14 21:17:15 +00:00
|
|
|
) as data, open(machine.state_dir / "usbstick.img", "wb") as stick:
|
2019-11-05 21:13:16 +00:00
|
|
|
stick.write(data.read())
|
|
|
|
|
|
|
|
machine.succeed("udisksctl info -b /dev/vda >&2")
|
|
|
|
machine.fail("udisksctl info -b /dev/sda1")
|
2014-04-19 12:37:05 +00:00
|
|
|
|
|
|
|
# Attach a USB stick and wait for it to show up.
|
2019-11-05 21:13:16 +00:00
|
|
|
machine.send_monitor_command(
|
|
|
|
f"drive_add 0 id=stick,if=none,file={stick.name},format=raw"
|
|
|
|
)
|
|
|
|
machine.send_monitor_command("device_add usb-storage,id=stick,drive=stick")
|
|
|
|
machine.wait_until_succeeds("udisksctl info -b /dev/sda1")
|
|
|
|
machine.succeed("udisksctl info -b /dev/sda1 | grep 'IdLabel:.*USBSTICK'")
|
2014-04-19 12:37:05 +00:00
|
|
|
|
|
|
|
# Mount the stick as a non-root user and do some stuff with it.
|
2019-11-05 21:13:16 +00:00
|
|
|
machine.succeed("su - alice -c 'udisksctl info -b /dev/sda1'")
|
|
|
|
machine.succeed("su - alice -c 'udisksctl mount -b /dev/sda1'")
|
|
|
|
machine.succeed(
|
|
|
|
"su - alice -c 'cat /run/media/alice/USBSTICK/test.txt' | grep -q 'Hello World'"
|
|
|
|
)
|
|
|
|
machine.succeed("su - alice -c 'echo foo > /run/media/alice/USBSTICK/bar.txt'")
|
2014-04-19 12:37:05 +00:00
|
|
|
|
|
|
|
# Unmounting the stick should make the mountpoint disappear.
|
2019-11-05 21:13:16 +00:00
|
|
|
machine.succeed("su - alice -c 'udisksctl unmount -b /dev/sda1'")
|
|
|
|
machine.fail("[ -d /run/media/alice/USBSTICK ]")
|
2014-04-19 12:37:05 +00:00
|
|
|
|
|
|
|
# Remove the USB stick.
|
2019-11-05 21:13:16 +00:00
|
|
|
machine.send_monitor_command("device_del stick")
|
|
|
|
machine.wait_until_fails("udisksctl info -b /dev/sda1")
|
|
|
|
machine.fail("[ -e /dev/sda ]")
|
2014-04-19 12:37:05 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
})
|