From 12f3e2c42cd7ece1dfb90ee96119d1db548dc734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20P=C3=A4ssler?= Date: Sun, 3 Jan 2021 13:53:34 +0100 Subject: [PATCH] nixos/tests/shadow: add switch user subtest --- nixos/tests/shadow.nix | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/nixos/tests/shadow.nix b/nixos/tests/shadow.nix index 0cc1d6811400..8f8cdef7ef9d 100644 --- a/nixos/tests/shadow.nix +++ b/nixos/tests/shadow.nix @@ -2,6 +2,7 @@ let password1 = "foobar"; password2 = "helloworld"; password3 = "bazqux"; + password4 = "asdf123"; in import ./make-test-python.nix ({ pkgs, ... }: { name = "shadow"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ nequissimus ]; }; @@ -19,6 +20,10 @@ in import ./make-test-python.nix ({ pkgs, ... }: { password = password2; shell = pkgs.shadow; }; + users.ash = { + password = password4; + shell = pkgs.bash; + }; }; }; @@ -41,6 +46,15 @@ in import ./make-test-python.nix ({ pkgs, ... }: { shadow.wait_for_file("/tmp/1") assert "emma" in shadow.succeed("cat /tmp/1") + with subtest("Switch user"): + shadow.send_chars("su - ash\n") + shadow.sleep(2) + shadow.send_chars("${password4}\n") + shadow.sleep(2) + shadow.send_chars("whoami > /tmp/3\n") + shadow.wait_for_file("/tmp/3") + assert "ash" in shadow.succeed("cat /tmp/3") + with subtest("Change password"): shadow.send_key("alt-f3") shadow.wait_until_succeeds(f"[ $(fgconsole) = 3 ]")