summaryrefslogtreecommitdiffstats
path: root/nixos/tests/userborn-static.nix
blob: e1d5cf259a7d6167984cc9098d5d0f055bf51020 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{ lib, ... }:

let
  sysuserPassword = "$y$j9T$3aiOV/8CADAK22OK2QT3/0$67OKd50Z4qTaZ8c/eRWHLIM.o3ujtC1.n9ysmJfv639";

  common = {
    services.userborn = {
      enable = true;
      static = true;
    };
    boot.initrd.systemd.enable = true;
    networking.useNetworkd = true;
    system.etc.overlay = {
      enable = true;
      mutable = false;
    };
  };
in

{

  name = "userborn-static";

  meta.maintainers = with lib.maintainers; [
    mic92
    valpackett
  ];

  nodes.machine =
    { ... }:
    {
      imports = [ common ];

      users.users.sysuser = {
        uid = 1337;
        isSystemUser = true;
        group = "wheel";
        home = "/var/empty";
        initialHashedPassword = sysuserPassword;
      };
    };

  testScript = ''
    with subtest("Correct mode on the password files"):
      assert machine.succeed("stat -c '%a' /etc/passwd") == "644\n"
      assert machine.succeed("stat -c '%a' /etc/group") == "644\n"
      assert machine.succeed("stat -c '%a' /etc/shadow") == "0\n"

    with subtest("Check files"):
      print(machine.succeed("grpck -r"))
      print(machine.succeed("pwck -r"))

    with subtest("sysuser user is created"):
      print(machine.succeed("getent passwd sysuser"))
      assert "${sysuserPassword}" in machine.succeed("getent shadow sysuser"), "sysuser user password is not correct"
  '';
}