1import ./make-test.nix ({ pkgs, latestKernel ? false, ... }:
2
3{
4 name = "login";
5 meta = with pkgs.stdenv.lib.maintainers; {
6 maintainers = [ eelco chaoflow ];
7 };
8
9 machine =
10 { config, pkgs, lib, ... }:
11 { boot.kernelPackages = lib.mkIf latestKernel pkgs.linuxPackages_latest;
12 };
13
14 testScript =
15 ''
16 $machine->waitForUnit('multi-user.target');
17 $machine->waitUntilSucceeds("pgrep -f 'agetty.*tty1'");
18 $machine->screenshot("postboot");
19
20 subtest "create user", sub {
21 $machine->succeed("useradd -m alice");
22 $machine->succeed("(echo foobar; echo foobar) | passwd alice");
23 };
24
25 # Check whether switching VTs works.
26 subtest "virtual console switching", sub {
27 $machine->fail("pgrep -f 'agetty.*tty2'");
28 $machine->sendKeys("alt-f2");
29 $machine->waitUntilSucceeds("[ \$(fgconsole) = 2 ]");
30 $machine->waitForUnit('getty@tty2.service');
31 $machine->waitUntilSucceeds("pgrep -f 'agetty.*tty2'");
32 };
33
34 # Log in as alice on a virtual console.
35 subtest "virtual console login", sub {
36 $machine->sleep(2); # urgh: wait for username prompt
37 $machine->sendChars("alice\n");
38 $machine->waitUntilSucceeds("pgrep login");
39 $machine->sleep(2); # urgh: wait for `Password:'
40 $machine->sendChars("foobar\n");
41 $machine->waitUntilSucceeds("pgrep -u alice bash");
42 $machine->sendChars("touch done\n");
43 $machine->waitForFile("/home/alice/done");
44 };
45
46 # Check whether systemd gives and removes device ownership as
47 # needed.
48 subtest "device permissions", sub {
49 $machine->succeed("getfacl /dev/snd/timer | grep -q alice");
50 $machine->sendKeys("alt-f1");
51 $machine->waitUntilSucceeds("[ \$(fgconsole) = 1 ]");
52 $machine->fail("getfacl /dev/snd/timer | grep -q alice");
53 $machine->succeed("chvt 2");
54 $machine->waitUntilSucceeds("getfacl /dev/snd/timer | grep -q alice");
55 };
56
57 # Log out.
58 subtest "virtual console logout", sub {
59 $machine->sendChars("exit\n");
60 $machine->waitUntilFails("pgrep -u alice bash");
61 $machine->screenshot("mingetty");
62 };
63
64 # Check whether ctrl-alt-delete works.
65 subtest "ctrl-alt-delete", sub {
66 $machine->sendKeys("ctrl-alt-delete");
67 $machine->waitForShutdown;
68 };
69 '';
70
71})