diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-04-07 13:20:29 +0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-04-07 13:22:12 +0200 |
commit | 2f51ca9609fbdec380888640dcec1df2917861df (patch) | |
tree | 7304cafbf6067a1b8c7868fabf089e15f9d568d5 /nixos/tests/udisks.nix | |
parent | 59ea2d7ba5089b64f5ba7c243c17c73a1a66f8b0 (diff) | |
download | nixlib-2f51ca9609fbdec380888640dcec1df2917861df.tar nixlib-2f51ca9609fbdec380888640dcec1df2917861df.tar.gz nixlib-2f51ca9609fbdec380888640dcec1df2917861df.tar.bz2 nixlib-2f51ca9609fbdec380888640dcec1df2917861df.tar.lz nixlib-2f51ca9609fbdec380888640dcec1df2917861df.tar.xz nixlib-2f51ca9609fbdec380888640dcec1df2917861df.tar.zst nixlib-2f51ca9609fbdec380888640dcec1df2917861df.zip |
Add a regression test for udisks
Diffstat (limited to 'nixos/tests/udisks.nix')
-rw-r--r-- | nixos/tests/udisks.nix | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/nixos/tests/udisks.nix b/nixos/tests/udisks.nix new file mode 100644 index 000000000000..e3e3f740d07b --- /dev/null +++ b/nixos/tests/udisks.nix @@ -0,0 +1,56 @@ +{ pkgs, ... }: + +let + + stick = pkgs.fetchurl { + url = http://nixos.org/~eelco/nix/udisks-test.img.xz; + sha256 = "0was1xgjkjad91nipzclaz5biv3m4b2nk029ga6nk7iklwi19l8b"; + }; + +in + +{ + + machine = + { config, pkgs, ... }: + { services.udisks.enable = true; + imports = [ ./common/user-account.nix ]; + + security.polkit.extraConfig = + '' + polkit.addRule(function(action, subject) { + if (subject.user == "alice") return "yes"; + }); + ''; + }; + + testScript = + '' + my $stick = $machine->stateDir . "/usbstick.img"; + system("xz -d < ${stick} > $stick") == 0 or die; + + $machine->succeed("udisks --enumerate | grep /org/freedesktop/UDisks/devices/vda"); + $machine->fail("udisks --enumerate | grep /org/freedesktop/UDisks/devices/sda1"); + + # Attach a USB stick and wait for it to show up. + $machine->sendMonitorCommand("usb_add disk:$stick"); + $machine->waitUntilSucceeds("udisks --enumerate | grep /org/freedesktop/UDisks/devices/sda1"); + $machine->succeed("udisks --show-info /dev/sda1 | grep 'label:.*USBSTICK'"); + + # Mount the stick as a non-root user and do some stuff with it. + $machine->succeed("su - alice -c 'udisks --enumerate | grep /org/freedesktop/UDisks/devices/sda1'"); + $machine->succeed("su - alice -c 'udisks --mount /dev/sda1'"); + $machine->succeed("su - alice -c 'cat /media/USBSTICK/test.txt'") =~ /Hello World/; + $machine->succeed("su - alice -c 'echo foo > /media/USBSTICK/bar.txt'"); + + # Unmounting the stick should make the mountpoint disappear. + $machine->succeed("su - alice -c 'udisks --unmount /dev/sda1'"); + $machine->fail("[ -d /media/USBSTICK ]"); + + # Remove the USB stick. + $machine->sendMonitorCommand("usb_del 0.3"); # FIXME + $machine->waitUntilFails("udisks --enumerate | grep /org/freedesktop/UDisks/devices/sda1"); + $machine->fail("[ -e /dev/sda ]"); + ''; + +} \ No newline at end of file |