about summary refs log tree commit diff
path: root/nixos/tests/login.nix
blob: 67f5764a0a162daa332f3d1154eed72729f8b0bd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import ./make-test-python.nix ({ pkgs, latestKernel ? false, ... }:

{
  name = "login";
  meta = with pkgs.lib.maintainers; {
    maintainers = [ eelco ];
  };

  nodes.machine =
    { pkgs, lib, ... }:
    { boot.kernelPackages = lib.mkIf latestKernel pkgs.linuxPackages_latest;
      sound.enable = true; # needed for the factl test, /dev/snd/* exists without them but udev doesn't care then
    };

  testScript = ''
      machine.start(allow_reboot = True)

      machine.wait_for_unit("multi-user.target")
      machine.wait_until_succeeds("pgrep -f 'agetty.*tty1'")
      machine.screenshot("postboot")

      with subtest("create user"):
          machine.succeed("useradd -m alice")
          machine.succeed("(echo foobar; echo foobar) | passwd alice")

      with subtest("Check whether switching VTs works"):
          machine.fail("pgrep -f 'agetty.*tty2'")
          machine.send_key("alt-f2")
          machine.wait_until_succeeds("[ $(fgconsole) = 2 ]")
          machine.wait_for_unit("getty@tty2.service")
          machine.wait_until_succeeds("pgrep -f 'agetty.*tty2'")

      with subtest("Log in as alice on a virtual console"):
          machine.wait_until_tty_matches("2", "login: ")
          machine.send_chars("alice\n")
          machine.wait_until_tty_matches("2", "login: alice")
          machine.wait_until_succeeds("pgrep login")
          machine.wait_until_tty_matches("2", "Password: ")
          machine.send_chars("foobar\n")
          machine.wait_until_succeeds("pgrep -u alice bash")
          machine.send_chars("touch done\n")
          machine.wait_for_file("/home/alice/done")

      with subtest("Systemd gives and removes device ownership as needed"):
          machine.succeed("getfacl /dev/snd/timer | grep -q alice")
          machine.send_key("alt-f1")
          machine.wait_until_succeeds("[ $(fgconsole) = 1 ]")
          machine.fail("getfacl /dev/snd/timer | grep -q alice")
          machine.succeed("chvt 2")
          machine.wait_until_succeeds("getfacl /dev/snd/timer | grep -q alice")

      with subtest("Virtual console logout"):
          machine.send_chars("exit\n")
          machine.wait_until_fails("pgrep -u alice bash")
          machine.screenshot("getty")

      with subtest("Check whether ctrl-alt-delete works"):
          boot_id1 = machine.succeed("cat /proc/sys/kernel/random/boot_id").strip()
          assert boot_id1 != ""

          machine.reboot()

          boot_id2 = machine.succeed("cat /proc/sys/kernel/random/boot_id").strip()
          assert boot_id2 != ""

          assert boot_id1 != boot_id2
  '';
})