1import ./make-test-python.nix (
2 { lib, ... }:
3 {
4 name = "grub";
5
6 meta = with lib.maintainers; {
7 maintainers = [ rnhmjoj ];
8 };
9
10 nodes.machine =
11 { ... }:
12 {
13 virtualisation.useBootLoader = true;
14
15 boot.loader.timeout = null;
16 boot.loader.grub = {
17 enable = true;
18 users.alice.password = "supersecret";
19
20 # OCR is not accurate enough
21 extraConfig = "serial; terminal_output serial";
22 };
23 };
24
25 testScript = ''
26 def grub_login_as(user, password):
27 """
28 Enters user and password to log into GRUB
29 """
30 machine.wait_for_console_text("Enter username:")
31 machine.send_chars(user + "\n")
32 machine.wait_for_console_text("Enter password:")
33 machine.send_chars(password + "\n")
34
35
36 def grub_select_all_configurations():
37 """
38 Selects "All configurations" from the GRUB menu
39 to trigger a login request.
40 """
41 machine.send_monitor_command("sendkey down")
42 machine.send_monitor_command("sendkey ret")
43
44
45 machine.start()
46
47 # wait for grub screen
48 machine.wait_for_console_text("GNU GRUB")
49
50 grub_select_all_configurations()
51 with subtest("Invalid credentials are rejected"):
52 grub_login_as("wronguser", "wrongsecret")
53 machine.wait_for_console_text("error: access denied.")
54
55 grub_select_all_configurations()
56 with subtest("Valid credentials are accepted"):
57 grub_login_as("alice", "supersecret")
58 machine.send_chars("\n") # press enter to boot
59 machine.wait_for_console_text("Linux version")
60
61 with subtest("Machine boots correctly"):
62 machine.wait_for_unit("multi-user.target")
63 '';
64 }
65)