summary refs log tree commit diff
diff options
context:
space:
mode:
authorMilan Pässler <mil@nyantec.com>2021-01-03 13:53:34 +0100
committerFrederik Rietdijk <freddyrietdijk@fridh.nl>2021-01-03 15:54:48 +0100
commit12f3e2c42cd7ece1dfb90ee96119d1db548dc734 (patch)
treeec20d749f196cab971d53b43e24c99a459829911
parent018072ea221254a449d11e45acba0f4b1f688c9d (diff)
downloadnixpkgs-12f3e2c42cd7ece1dfb90ee96119d1db548dc734.tar
nixpkgs-12f3e2c42cd7ece1dfb90ee96119d1db548dc734.tar.gz
nixpkgs-12f3e2c42cd7ece1dfb90ee96119d1db548dc734.tar.bz2
nixpkgs-12f3e2c42cd7ece1dfb90ee96119d1db548dc734.tar.lz
nixpkgs-12f3e2c42cd7ece1dfb90ee96119d1db548dc734.tar.xz
nixpkgs-12f3e2c42cd7ece1dfb90ee96119d1db548dc734.tar.zst
nixpkgs-12f3e2c42cd7ece1dfb90ee96119d1db548dc734.zip
nixos/tests/shadow: add switch user subtest
-rw-r--r--nixos/tests/shadow.nix14
1 files changed, 14 insertions, 0 deletions
diff --git a/nixos/tests/shadow.nix b/nixos/tests/shadow.nix
index 0cc1d681140..8f8cdef7ef9 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 ]")