4 # All passwords are "test"
5 rootHashedPasswordFile = "$y$j9T$6ueoTO5y7vvFsGvpQJEEa.$vubxgBiMnkTCtRtPD3hNiZHa7Nm1WsJeE9QomYqSRXB";
6 updatedRootHashedPassword = "$y$j9T$pBCO9N1FRF1rSl6V15n9n/$1JmRLEYPO7TRCx43cvLO19u59WA/oqTEhmSR4wrhzr.";
8 normaloPassword = "test";
9 updatedNormaloHashedPassword = "$y$j9T$IEWqhKtWg.r.8fVkSEF56.$iKNxdMC6hOAQRp6eBtYvBk4c7BGpONXeZMqc8I/LM46";
11 sysuserInitialHashedPassword = "$y$j9T$Kb6jGrk41hudTZpNjazf11$iw7fZXrewC6JxRaGPz7/gPXDZ.Z1VWsupvy81Hi1XiD";
12 updatedSysuserInitialHashedPassword = "$y$j9T$kUBVhgOdSjymSfwfRVja70$eqCwWzVsz0fI0Uc6JsdD2CYMCpfJcErqnIqva2JCi1D";
14 newNormaloHashedPassword = "$y$j9T$UFBMWbGjjVola0YE9YCcV/$jRSi5S6lzkcifbuqjMcyXLTwgOGm9BTQk/G/jYaxroC";
21 meta.maintainers = with lib.maintainers; [ nikstur ];
24 services.userborn.enable = true;
26 # Read this password file at runtime from outside the Nix store.
27 environment.etc."rootpw.secret".text = rootHashedPasswordFile;
32 # Override the empty root password set by the test instrumentation.
33 hashedPasswordFile = lib.mkForce "/etc/rootpw.secret";
37 password = normaloPassword;
42 initialHashedPassword = sysuserInitialHashedPassword;
50 specialisation.new-generation.configuration = {
54 # Forcing this to null simulates removing the config value in a new
56 hashedPasswordFile = lib.mkOverride 9 null;
57 hashedPassword = updatedRootHashedPassword;
60 hashedPassword = updatedNormaloHashedPassword;
63 initialHashedPassword = lib.mkForce updatedSysuserInitialHashedPassword;
67 hashedPassword = newNormaloHashedPassword;
78 machine.wait_for_unit("userborn.service")
80 with subtest("Correct mode on the password files"):
81 assert machine.succeed("stat -c '%a' /etc/passwd") == "644\n"
82 assert machine.succeed("stat -c '%a' /etc/group") == "644\n"
83 assert machine.succeed("stat -c '%a' /etc/shadow") == "0\n"
85 with subtest("root user has correct password"):
86 print(machine.succeed("getent passwd root"))
87 assert "${rootHashedPasswordFile}" in machine.succeed("getent shadow root"), "root user password is not correct"
89 with subtest("normalo user is created"):
90 print(machine.succeed("getent passwd normalo"))
91 assert 1000 <= int(machine.succeed("id --user normalo")), "normalo user doesn't have a normal UID"
92 assert machine.succeed("stat -c '%U' /home/normalo") == "normalo\n"
94 with subtest("system user is created with correct password"):
95 print(machine.succeed("getent passwd sysuser"))
96 assert 1000 > int(machine.succeed("id --user sysuser")), "sysuser user doesn't have a system UID"
97 assert "${sysuserInitialHashedPassword}" in machine.succeed("getent shadow sysuser"), "system user password is not correct"
99 with subtest("sysusers group is created"):
100 print(machine.succeed("getent group sysusers"))
102 with subtest("Check files"):
103 print(machine.succeed("grpck -r"))
104 print(machine.succeed("pwck -r"))
107 machine.succeed("/run/current-system/specialisation/new-generation/bin/switch-to-configuration switch")
110 with subtest("root user password is updated"):
111 print(machine.succeed("getent passwd root"))
112 assert "${updatedRootHashedPassword}" in machine.succeed("getent shadow root"), "root user password is not updated"
114 with subtest("normalo user password is updated"):
115 print(machine.succeed("getent passwd normalo"))
116 assert "${updatedNormaloHashedPassword}" in machine.succeed("getent shadow normalo"), "normalo user password is not updated"
118 with subtest("system user password is NOT updated"):
119 print(machine.succeed("getent passwd sysuser"))
120 assert "${sysuserInitialHashedPassword}" in machine.succeed("getent shadow sysuser"), "sysuser user password is not updated"
122 with subtest("new-normalo user is created after switching to new generation"):
123 print(machine.succeed("getent passwd new-normalo"))
124 assert 1000 <= int(machine.succeed("id --user new-normalo")), "new-normalo user doesn't have a normal UID"
125 assert machine.succeed("stat -c '%U' /home/new-normalo") == "new-normalo\n"
126 assert "${newNormaloHashedPassword}" in machine.succeed("getent shadow new-normalo"), "new-normalo user password is not correct"
128 with subtest("new-group group is created after switching to new generation"):
129 print(machine.succeed("getent group new-group"))
131 with subtest("Check files"):
132 print(machine.succeed("grpck -r"))
133 print(machine.succeed("pwck -r"))