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