diff options
author | rnhmjoj <rnhmjoj@inventati.org> | 2020-06-13 12:06:26 +0200 |
---|---|---|
committer | rnhmjoj <rnhmjoj@inventati.org> | 2020-06-24 10:22:53 +0200 |
commit | 33c4a4bdd52a750205046cc85775e6caea342868 (patch) | |
tree | dcbc77f5fb2fcfe3764fbd1583d19bc86296d481 /nixos/tests/grub.nix | |
parent | b520055df6c9913ef4ddbc931a1635516433a7a9 (diff) |
nixos/tests: add test for grub authentication
Diffstat (limited to 'nixos/tests/grub.nix')
-rw-r--r-- | nixos/tests/grub.nix | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/nixos/tests/grub.nix b/nixos/tests/grub.nix new file mode 100644 index 000000000000..84bfc90955b5 --- /dev/null +++ b/nixos/tests/grub.nix @@ -0,0 +1,60 @@ +import ./make-test-python.nix ({ lib, ... }: { + name = "grub"; + + meta = with lib.maintainers; { + maintainers = [ rnhmjoj ]; + }; + + machine = { ... }: { + virtualisation.useBootLoader = true; + + boot.loader.timeout = null; + boot.loader.grub = { + enable = true; + users.alice.password = "supersecret"; + + # OCR is not accurate enough + extraConfig = "serial; terminal_output serial"; + }; + }; + + testScript = '' + def grub_login_as(user, password): + """ + Enters user and password to log into GRUB + """ + machine.wait_for_console_text("Enter username:") + machine.send_chars(user + "\n") + machine.wait_for_console_text("Enter password:") + machine.send_chars(password + "\n") + + + def grub_select_all_configurations(): + """ + Selects "All configurations" from the GRUB menu + to trigger a login request. + """ + machine.send_monitor_command("sendkey down") + machine.send_monitor_command("sendkey ret") + + + machine.start() + + # wait for grub screen + machine.wait_for_console_text("GNU GRUB") + + grub_select_all_configurations() + with subtest("Invalid credentials are rejected"): + grub_login_as("wronguser", "wrongsecret") + machine.wait_for_console_text("error: access denied.") + + grub_select_all_configurations() + with subtest("Valid credentials are accepted"): + grub_login_as("alice", "supersecret") + machine.send_chars("\n") # press enter to boot + machine.wait_for_console_text("Linux version") + + with subtest("Machine boots correctly"): + machine.wait_for_unit("multi-user.target") + ''; +}) |