nixos/tests: fix all tests that uses wait_until_tty_matches

This commit is contained in:
Bobby Rong 2022-06-04 12:22:03 +08:00
parent 9d2a8e3190
commit 906b0b2e87
No known key found for this signature in database
GPG Key ID: ED07364437C91161
8 changed files with 39 additions and 39 deletions

View File

@ -11,16 +11,16 @@ import ./make-test-python.nix ({ ... }:
testScript = ''
def login_as_alice():
machine.wait_until_tty_matches(1, "login: ")
machine.wait_until_tty_matches("1", "login: ")
machine.send_chars("alice\n")
machine.wait_until_tty_matches(1, "Password: ")
machine.wait_until_tty_matches("1", "Password: ")
machine.send_chars("foobar\n")
machine.wait_until_tty_matches(1, "alice\@machine")
machine.wait_until_tty_matches("1", "alice\@machine")
def logout():
machine.send_chars("logout\n")
machine.wait_until_tty_matches(1, "login: ")
machine.wait_until_tty_matches("1", "login: ")
machine.wait_for_unit("default.target")
@ -36,7 +36,7 @@ import ./make-test-python.nix ({ ... }:
with subtest("Log alice in (ecryptfs passwhrase is wrapped during first login)"):
login_as_alice()
machine.send_chars("logout\n")
machine.wait_until_tty_matches(1, "login: ")
machine.wait_until_tty_matches("1", "login: ")
# Why do I need to do this??
machine.succeed("su alice -c ecryptfs-umount-private || true")

View File

@ -29,11 +29,11 @@ import ./make-test-python.nix ({ pkgs, latestKernel ? false, ... }:
machine.wait_until_succeeds("pgrep -f 'agetty.*tty2'")
with subtest("Log in as alice on a virtual console"):
machine.wait_until_tty_matches(2, "login: ")
machine.wait_until_tty_matches("2", "login: ")
machine.send_chars("alice\n")
machine.wait_until_tty_matches(2, "login: alice")
machine.wait_until_tty_matches("2", "login: alice")
machine.wait_until_succeeds("pgrep login")
machine.wait_until_tty_matches(2, "Password: ")
machine.wait_until_tty_matches("2", "Password: ")
machine.send_chars("foobar\n")
machine.wait_until_succeeds("pgrep -u alice bash")
machine.send_chars("touch done\n")

View File

@ -77,28 +77,28 @@ in
machine.screenshot("postboot")
with subtest("Invalid password"):
switch_to_tty(2)
enter_user_alice(2)
switch_to_tty("2")
enter_user_alice("2")
machine.send_chars("${oathSnakeOilPassword1}\n")
machine.wait_until_tty_matches(2, "Password: ")
machine.wait_until_tty_matches("2", "Password: ")
machine.send_chars("blorg\n")
machine.wait_until_tty_matches(2, "Login incorrect")
machine.wait_until_tty_matches("2", "Login incorrect")
with subtest("Invalid oath token"):
switch_to_tty(3)
enter_user_alice(3)
switch_to_tty("3")
enter_user_alice("3")
machine.send_chars("000000\n")
machine.wait_until_tty_matches(3, "Login incorrect")
machine.wait_until_tty_matches(3, "login:")
machine.wait_until_tty_matches("3", "Login incorrect")
machine.wait_until_tty_matches("3", "login:")
with subtest("Happy path: Both passwords are mandatory to get us in"):
switch_to_tty(4)
enter_user_alice(4)
switch_to_tty("4")
enter_user_alice("4")
machine.send_chars("${oathSnakeOilPassword2}\n")
machine.wait_until_tty_matches(4, "Password: ")
machine.wait_until_tty_matches("4", "Password: ")
machine.send_chars("${alicePassword}\n")
machine.wait_until_succeeds("pgrep -u alice bash")

View File

@ -39,9 +39,9 @@ in import ./make-test-python.nix ({ pkgs, ... }: {
shadow.wait_until_succeeds("[ $(fgconsole) = 2 ]")
shadow.wait_for_unit("getty@tty2.service")
shadow.wait_until_succeeds("pgrep -f 'agetty.*tty2'")
shadow.wait_until_tty_matches(2, "login: ")
shadow.wait_until_tty_matches("2", "login: ")
shadow.send_chars("emma\n")
shadow.wait_until_tty_matches(2, "login: emma")
shadow.wait_until_tty_matches("2", "login: emma")
shadow.wait_until_succeeds("pgrep login")
shadow.sleep(2)
shadow.send_chars("${password1}\n")
@ -63,9 +63,9 @@ in import ./make-test-python.nix ({ pkgs, ... }: {
shadow.wait_until_succeeds("[ $(fgconsole) = 3 ]")
shadow.wait_for_unit("getty@tty3.service")
shadow.wait_until_succeeds("pgrep -f 'agetty.*tty3'")
shadow.wait_until_tty_matches(3, "login: ")
shadow.wait_until_tty_matches("3", "login: ")
shadow.send_chars("emma\n")
shadow.wait_until_tty_matches(3, "login: emma")
shadow.wait_until_tty_matches("3", "login: emma")
shadow.wait_until_succeeds("pgrep login")
shadow.sleep(2)
shadow.send_chars("${password1}\n")
@ -81,16 +81,16 @@ in import ./make-test-python.nix ({ pkgs, ... }: {
shadow.wait_until_succeeds("[ $(fgconsole) = 4 ]")
shadow.wait_for_unit("getty@tty4.service")
shadow.wait_until_succeeds("pgrep -f 'agetty.*tty4'")
shadow.wait_until_tty_matches(4, "login: ")
shadow.wait_until_tty_matches("4", "login: ")
shadow.send_chars("emma\n")
shadow.wait_until_tty_matches(4, "login: emma")
shadow.wait_until_tty_matches("4", "login: emma")
shadow.wait_until_succeeds("pgrep login")
shadow.sleep(2)
shadow.send_chars("${password1}\n")
shadow.wait_until_tty_matches(4, "Login incorrect")
shadow.wait_until_tty_matches(4, "login:")
shadow.wait_until_tty_matches("4", "Login incorrect")
shadow.wait_until_tty_matches("4", "login:")
shadow.send_chars("emma\n")
shadow.wait_until_tty_matches(4, "login: emma")
shadow.wait_until_tty_matches("4", "login: emma")
shadow.wait_until_succeeds("pgrep login")
shadow.sleep(2)
shadow.send_chars("${password3}\n")
@ -109,11 +109,11 @@ in import ./make-test-python.nix ({ pkgs, ... }: {
shadow.wait_until_succeeds("[ $(fgconsole) = 5 ]")
shadow.wait_for_unit("getty@tty5.service")
shadow.wait_until_succeeds("pgrep -f 'agetty.*tty5'")
shadow.wait_until_tty_matches(5, "login: ")
shadow.wait_until_tty_matches("5", "login: ")
shadow.send_chars("layla\n")
shadow.wait_until_tty_matches(5, "login: layla")
shadow.wait_until_tty_matches("5", "login: layla")
shadow.wait_until_succeeds("pgrep login")
shadow.send_chars("${password2}\n")
shadow.wait_until_tty_matches(5, "login:")
shadow.wait_until_tty_matches("5", "login:")
'';
})

View File

@ -42,7 +42,7 @@ in
client1.wait_for_unit("multi-user.target")
client1.wait_until_succeeds("pgrep -f 'agetty.*tty1'")
client1.wait_until_tty_matches(1, "login: ")
client1.wait_until_tty_matches("1", "login: ")
client1.send_chars("root\n")
client1.wait_until_succeeds("pgrep -u root bash")

View File

@ -19,9 +19,9 @@ import ./make-test-python.nix ({ lib, ... }: {
machine.wait_for_unit("multi-user.target")
machine.wait_for_unit("getty@tty1.service")
machine.wait_until_tty_matches(1, "login: ")
machine.wait_until_tty_matches("1", "login: ")
machine.send_chars("alice\n")
machine.wait_until_tty_matches(1, "Password: ")
machine.wait_until_tty_matches("1", "Password: ")
machine.send_chars("pass1\n")
machine.send_chars("touch login-ok\n")
machine.wait_for_file("/home/alice/login-ok")

View File

@ -17,9 +17,9 @@ import ./make-test-python.nix ({ lib, ... }: {
testScript = ''
machine.wait_for_unit("multi-user.target")
machine.wait_for_unit("getty@tty1.service")
machine.wait_until_tty_matches(1, "login: ")
machine.wait_until_tty_matches("1", "login: ")
machine.send_chars("alice\n")
machine.wait_until_tty_matches(1, "Password: ")
machine.wait_until_tty_matches("1", "Password: ")
machine.send_chars("pass1\n")
machine.succeed('[ "$(stat -c %a /home/alice)" == "700" ]')
machine.succeed('[ "$(stat -c %a /home/bob)" == "750" ]')

View File

@ -21,13 +21,13 @@ import ./make-test-python.nix ({ pkgs, ...} : {
default.wait_until_succeeds("pgrep -f 'agetty.*tty1'")
# Login
default.wait_until_tty_matches(1, "login: ")
default.wait_until_tty_matches("1", "login: ")
default.send_chars("root\n")
default.wait_until_tty_matches(1, r"\nroot@default\b")
default.wait_until_tty_matches("1", r"\nroot@default\b")
# Generate some history
default.send_chars("echo foobar\n")
default.wait_until_tty_matches(1, "foobar")
default.wait_until_tty_matches("1", "foobar")
# Ensure that command was recorded in history
default.succeed("/run/current-system/sw/bin/history list | grep -q foobar")