vuls: init at 0.27.0 (#348530)
[NixPkgs.git] / nixos / tests / user-expiry.nix
blobbcaed7a0ccb0b3c485ba3b8588ace481dd6143d0
1 let
2   alice = "alice";
3   bob = "bob";
4   eve = "eve";
5   passwd = "pass1";
6 in
8   name = "user-expiry";
10   nodes = {
11     machine = {
12       users.users = {
13         ${alice} = {
14           initialPassword = passwd;
15           isNormalUser = true;
16           expires = "1990-01-01";
17         };
18         ${bob} = {
19           initialPassword = passwd;
20           isNormalUser = true;
21           expires = "2990-01-01";
22         };
23         ${eve} = {
24           initialPassword = passwd;
25           isNormalUser = true;
26         };
27       };
28     };
29   };
31   testScript = ''
32     def switch_to_tty(tty_number):
33       machine.fail(f"pgrep -f 'agetty.*tty{tty_number}'")
34       machine.send_key(f"alt-f{tty_number}")
35       machine.wait_until_succeeds(f"[ $(fgconsole) = {tty_number} ]")
36       machine.wait_for_unit(f"getty@tty{tty_number}.service")
37       machine.wait_until_succeeds(f"pgrep -f 'agetty.*tty{tty_number}'")
40     machine.wait_for_unit("multi-user.target")
41     machine.wait_for_unit("getty@tty1.service")
43     with subtest("${alice} cannot login"):
44       machine.wait_until_tty_matches("1", "login: ")
45       machine.send_chars("${alice}\n")
46       machine.wait_until_tty_matches("1", "Password: ")
47       machine.send_chars("${passwd}\n")
49       machine.wait_until_succeeds("journalctl --grep='account ${alice} has expired \\(account expired\\)'")
50       machine.wait_until_tty_matches("1", "login: ")
52     with subtest("${bob} can login"):
53       switch_to_tty(2)
54       machine.wait_until_tty_matches("2", "login: ")
55       machine.send_chars("${bob}\n")
56       machine.wait_until_tty_matches("2", "Password: ")
57       machine.send_chars("${passwd}\n")
59       machine.wait_until_succeeds("pgrep -u ${bob} bash")
61     with subtest("${eve} can login"):
62       switch_to_tty(3)
63       machine.wait_until_tty_matches("3", "login: ")
64       machine.send_chars("${eve}\n")
65       machine.wait_until_tty_matches("3", "Password: ")
66       machine.send_chars("${passwd}\n")
68       machine.wait_until_succeeds("pgrep -u ${eve} bash")
69   '';