2020-04-24 23:36:52 +00:00
|
|
|
# Mutable users tests.
|
|
|
|
|
|
|
|
import ./make-test-python.nix ({ pkgs, ...} : {
|
|
|
|
name = "mutable-users";
|
2021-01-15 22:18:51 +00:00
|
|
|
meta = with pkgs.lib.maintainers; {
|
2020-04-24 23:36:52 +00:00
|
|
|
maintainers = [ gleber ];
|
|
|
|
};
|
|
|
|
|
|
|
|
nodes = {
|
2024-09-19 14:19:46 +00:00
|
|
|
machine = {
|
|
|
|
specialisation.immutable.configuration = {
|
|
|
|
users.mutableUsers = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
specialisation.mutable.configuration = {
|
|
|
|
users.mutableUsers = true;
|
|
|
|
users.users.dry-test.isNormalUser = true;
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
testScript = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
machine.start()
|
|
|
|
machine.wait_for_unit("default.target")
|
|
|
|
|
|
|
|
# Machine starts in immutable mode. Add a user and test if reactivating
|
|
|
|
# configuration removes the user.
|
|
|
|
with subtest("Machine in immutable mode"):
|
|
|
|
assert "foobar" not in machine.succeed("cat /etc/passwd")
|
|
|
|
machine.succeed("sudo useradd foobar")
|
|
|
|
assert "foobar" in machine.succeed("cat /etc/passwd")
|
|
|
|
machine.succeed(
|
2024-09-19 14:19:46 +00:00
|
|
|
"/run/booted-system/specialisation/immutable/bin/switch-to-configuration test"
|
2020-04-24 23:36:52 +00:00
|
|
|
)
|
|
|
|
assert "foobar" not in machine.succeed("cat /etc/passwd")
|
|
|
|
|
|
|
|
# In immutable mode passwd is not wrapped, while in mutable mode it is
|
|
|
|
# wrapped.
|
|
|
|
with subtest("Password is wrapped in mutable mode"):
|
|
|
|
assert "/run/current-system/" in machine.succeed("which passwd")
|
|
|
|
machine.succeed(
|
2024-09-19 14:19:46 +00:00
|
|
|
"/run/booted-system/specialisation/mutable/bin/switch-to-configuration test"
|
2020-04-24 23:36:52 +00:00
|
|
|
)
|
|
|
|
assert "/run/wrappers/" in machine.succeed("which passwd")
|
2021-09-18 10:52:07 +00:00
|
|
|
|
|
|
|
with subtest("dry-activation does not change files"):
|
|
|
|
machine.succeed('test -e /home/dry-test') # home was created
|
|
|
|
machine.succeed('rm -rf /home/dry-test')
|
|
|
|
|
|
|
|
files_to_check = ['/etc/group',
|
|
|
|
'/etc/passwd',
|
|
|
|
'/etc/shadow',
|
|
|
|
'/etc/subuid',
|
|
|
|
'/etc/subgid',
|
|
|
|
'/var/lib/nixos/uid-map',
|
|
|
|
'/var/lib/nixos/gid-map',
|
|
|
|
'/var/lib/nixos/declarative-groups',
|
|
|
|
'/var/lib/nixos/declarative-users'
|
|
|
|
]
|
|
|
|
expected_hashes = {}
|
|
|
|
expected_stats = {}
|
|
|
|
for file in files_to_check:
|
|
|
|
expected_hashes[file] = machine.succeed(f"sha256sum {file}")
|
|
|
|
expected_stats[file] = machine.succeed(f"stat {file}")
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
machine.succeed("/run/booted-system/specialisation/mutable/bin/switch-to-configuration dry-activate")
|
2021-09-18 10:52:07 +00:00
|
|
|
|
|
|
|
machine.fail('test -e /home/dry-test') # home was not recreated
|
|
|
|
for file in files_to_check:
|
|
|
|
assert machine.succeed(f"sha256sum {file}") == expected_hashes[file]
|
|
|
|
assert machine.succeed(f"stat {file}") == expected_stats[file]
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
})
|