nixpkgs/nixos/tests/pam/zfs-key.nix
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

87 lines
3.1 KiB
Nix

import ../make-test-python.nix (
{ ... }:
let
userPassword = "password";
mismatchPass = "mismatch";
in
{
name = "pam-zfs-key";
nodes.machine =
{ ... }:
{
boot.supportedFilesystems = [ "zfs" ];
networking.hostId = "12345678";
security.pam.zfs.enable = true;
users.users = {
alice = {
isNormalUser = true;
password = userPassword;
};
bob = {
isNormalUser = true;
password = userPassword;
};
};
};
testScript =
{ nodes, ... }:
let
homes = nodes.machine.security.pam.zfs.homes;
pool = builtins.head (builtins.split "/" homes);
in
''
machine.wait_for_unit("multi-user.target")
machine.wait_until_succeeds("pgrep -f 'agetty.*tty1'")
with subtest("Create encrypted ZFS datasets"):
machine.succeed("truncate -s 64M /testpool.img")
machine.succeed("zpool create -O canmount=off '${pool}' /testpool.img")
machine.succeed("zfs create -o canmount=off -p '${homes}'")
machine.succeed("echo ${userPassword} | zfs create -o canmount=noauto -o encryption=on -o keyformat=passphrase '${homes}/alice'")
machine.succeed("zfs unload-key '${homes}/alice'")
machine.succeed("echo ${mismatchPass} | zfs create -o canmount=noauto -o encryption=on -o keyformat=passphrase '${homes}/bob'")
machine.succeed("zfs unload-key '${homes}/bob'")
with subtest("Switch to tty2"):
machine.fail("pgrep -f 'agetty.*tty2'")
machine.send_key("alt-f2")
machine.wait_until_succeeds("[ $(fgconsole) = 2 ]")
machine.wait_for_unit("getty@tty2.service")
machine.wait_until_succeeds("pgrep -f 'agetty.*tty2'")
with subtest("Log in as user with home locked by login password"):
machine.wait_until_tty_matches("2", "login: ")
machine.send_chars("alice\n")
machine.wait_until_tty_matches("2", "login: alice")
machine.wait_until_succeeds("pgrep login")
machine.wait_until_tty_matches("2", "Password: ")
machine.send_chars("${userPassword}\n")
machine.wait_until_succeeds("pgrep -u alice bash")
machine.succeed("mount | grep ${homes}/alice")
with subtest("Switch to tty3"):
machine.fail("pgrep -f 'agetty.*tty3'")
machine.send_key("alt-f3")
machine.wait_until_succeeds("[ $(fgconsole) = 3 ]")
machine.wait_for_unit("getty@tty3.service")
machine.wait_until_succeeds("pgrep -f 'agetty.*tty3'")
with subtest("Log in as user with home locked by password different from login"):
machine.wait_until_tty_matches("3", "login: ")
machine.send_chars("bob\n")
machine.wait_until_tty_matches("3", "login: bob")
machine.wait_until_succeeds("pgrep login")
machine.wait_until_tty_matches("3", "Password: ")
machine.send_chars("${userPassword}\n")
machine.wait_until_succeeds("pgrep -u bob bash")
machine.fail("mount | grep ${homes}/bob")
'';
}
)