From 5508000ddfc5b6b0db7f25272ef09588637e375f Mon Sep 17 00:00:00 2001 From: Lily Foster Date: Sat, 7 Jan 2023 20:56:11 -0500 Subject: [PATCH] nixos/tests/shadow: ensure hashedPassword takes precedence over initialHashedPassword --- nixos/tests/shadow.nix | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/nixos/tests/shadow.nix b/nixos/tests/shadow.nix index baa2e5945c05..c9a04088e870 100644 --- a/nixos/tests/shadow.nix +++ b/nixos/tests/shadow.nix @@ -5,6 +5,7 @@ let password4 = "asdf123"; hashed_bcrypt = "$2b$05$8xIEflrk2RxQtcVXbGIxs.Vl0x7dF1/JSv3cyX6JJt0npzkTCWvxK"; # fnord hashed_yeshash = "$y$j9T$d8Z4EAf8P1SvM/aDFbxMS0$VnTXMp/Hnc7QdCBEaLTq5ZFOAFo2/PM0/xEAFuOE88."; # fnord + hashed_sha512crypt = "$6$ymzs8WINZ5wGwQcV$VC2S0cQiX8NVukOLymysTPn4v1zJoJp3NGyhnqyv/dAf4NWZsBWYveQcj6gEJr4ZUjRBRjM0Pj1L8TCQ8hUUp0"; # meow in import ./make-test-python.nix ({ pkgs, ... }: { name = "shadow"; meta = with pkgs.lib.maintainers; { maintainers = [ nequissimus ]; }; @@ -39,6 +40,12 @@ in import ./make-test-python.nix ({ pkgs, ... }: { hashedPassword = hashed_yeshash; shell = pkgs.bash; }; + users.leo = { + isNormalUser = true; + initialHashedPassword = "!"; + hashedPassword = hashed_sha512crypt; # should take precedence over initialHashedPassword + shell = pkgs.bash; + }; }; }; @@ -145,5 +152,21 @@ in import ./make-test-python.nix ({ pkgs, ... }: { print(shadow.succeed(f"cat /tmp/{u}")) assert u in shadow.succeed(f"cat /tmp/{u}") shadow.send_chars("logout\n") + + with subtest("Ensure hashedPassword does not get overridden by initialHashedPassword"): + shadow.send_key("alt-f6") + shadow.wait_until_succeeds("[ $(fgconsole) = 6 ]") + shadow.wait_for_unit("getty@tty6.service") + shadow.wait_until_succeeds("pgrep -f 'agetty.*tty6'") + shadow.wait_until_tty_matches("6", "login: ") + shadow.send_chars("leo\n") + shadow.wait_until_tty_matches("6", "login: leo") + shadow.wait_until_succeeds("pgrep login") + shadow.sleep(2) + shadow.send_chars("meow\n") + shadow.send_chars("whoami > /tmp/leo\n") + shadow.wait_for_file("/tmp/leo") + assert "leo" in shadow.succeed("cat /tmp/leo") + shadow.send_chars("logout\n") ''; })