at 25.11-pre 2.3 kB view raw
1import ./make-test-python.nix ( 2 { pkgs, ... }: 3 4 let 5 6 # FIXME: 404s 7 stick = pkgs.fetchurl { 8 url = "https://nixos.org/~eelco/nix/udisks-test.img.xz"; 9 sha256 = "0was1xgjkjad91nipzclaz5biv3m4b2nk029ga6nk7iklwi19l8b"; 10 }; 11 12 in 13 14 { 15 name = "udisks2"; 16 meta = with pkgs.lib.maintainers; { 17 maintainers = [ ]; 18 }; 19 20 nodes.machine = 21 { ... }: 22 { 23 services.udisks2.enable = true; 24 imports = [ ./common/user-account.nix ]; 25 26 security.polkit.extraConfig = '' 27 polkit.addRule(function(action, subject) { 28 if (subject.user == "alice") return "yes"; 29 }); 30 ''; 31 }; 32 33 testScript = '' 34 import lzma 35 36 machine.systemctl("start udisks2") 37 machine.wait_for_unit("udisks2.service") 38 39 with lzma.open( 40 "${stick}" 41 ) as data, open(machine.state_dir / "usbstick.img", "wb") as stick: 42 stick.write(data.read()) 43 44 machine.succeed("udisksctl info -b /dev/vda >&2") 45 machine.fail("udisksctl info -b /dev/sda1") 46 47 # Attach a USB stick and wait for it to show up. 48 machine.send_monitor_command( 49 f"drive_add 0 id=stick,if=none,file={stick.name},format=raw" 50 ) 51 machine.send_monitor_command("device_add usb-storage,id=stick,drive=stick") 52 machine.wait_until_succeeds("udisksctl info -b /dev/sda1") 53 machine.succeed("udisksctl info -b /dev/sda1 | grep 'IdLabel:.*USBSTICK'") 54 55 # Mount the stick as a non-root user and do some stuff with it. 56 machine.succeed("su - alice -c 'udisksctl info -b /dev/sda1'") 57 machine.succeed("su - alice -c 'udisksctl mount -b /dev/sda1'") 58 machine.succeed( 59 "su - alice -c 'cat /run/media/alice/USBSTICK/test.txt' | grep -q 'Hello World'" 60 ) 61 machine.succeed("su - alice -c 'echo foo > /run/media/alice/USBSTICK/bar.txt'") 62 63 # Unmounting the stick should make the mountpoint disappear. 64 machine.succeed("su - alice -c 'udisksctl unmount -b /dev/sda1'") 65 machine.fail("[ -d /run/media/alice/USBSTICK ]") 66 67 # Remove the USB stick. 68 machine.send_monitor_command("device_del stick") 69 machine.wait_until_fails("udisksctl info -b /dev/sda1") 70 machine.fail("[ -e /dev/sda ]") 71 ''; 72 73 } 74)