1 # Some tests to ensure doas is working properly.
2 import ./make-test-python.nix (
5 meta = with lib.maintainers; {
6 maintainers = [ cole-h ];
12 users.groups = { foobar = {}; barfoo = {}; baz = { gid = 1337; }; };
14 test0 = { isNormalUser = true; extraGroups = [ "wheel" ]; };
15 test1 = { isNormalUser = true; };
16 test2 = { isNormalUser = true; extraGroups = [ "foobar" ]; };
17 test3 = { isNormalUser = true; extraGroups = [ "barfoo" ]; };
18 test4 = { isNormalUser = true; extraGroups = [ "baz" ]; };
19 test5 = { isNormalUser = true; };
20 test6 = { isNormalUser = true; };
21 test7 = { isNormalUser = true; };
26 wheelNeedsPassword = false;
29 { users = [ "test1" ]; groups = [ "foobar" ]; }
30 { users = [ "test2" ]; noPass = true; setEnv = [ "CORRECT" "HORSE=BATTERY" ]; }
31 { groups = [ "barfoo" 1337 ]; noPass = true; }
32 { users = [ "test5" ]; noPass = true; keepEnv = true; runAs = "test1"; }
33 { users = [ "test6" ]; noPass = true; keepEnv = true; setEnv = [ "-STAPLE" ]; }
34 { users = [ "test7" ]; noPass = true; setEnv = [ "-SSH_AUTH_SOCK" ]; }
40 with subtest("users in wheel group should have passwordless doas"):
41 machine.succeed('su - test0 -c "doas -u root true"')
43 with subtest("test1 user should not be able to use doas without password"):
44 machine.fail('su - test1 -c "doas -n -u root true"')
46 with subtest("test2 user should be able to keep some env"):
47 if "CORRECT=1" not in machine.succeed('su - test2 -c "CORRECT=1 doas env"'):
48 raise Exception("failed to keep CORRECT")
50 if "HORSE=BATTERY" not in machine.succeed('su - test2 -c "doas env"'):
51 raise Exception("failed to setenv HORSE=BATTERY")
53 with subtest("users in group 'barfoo' shouldn't require password"):
54 machine.succeed("doas -u test3 doas -n -u root true")
56 with subtest("users in group 'baz' (GID 1337) shouldn't require password"):
57 machine.succeed("doas -u test4 doas -n -u root echo true")
59 with subtest("test5 user should be able to run commands under test1"):
60 machine.succeed("doas -u test5 doas -n -u test1 true")
62 with subtest("test5 user should not be able to run commands under root"):
63 machine.fail("doas -u test5 doas -n -u root true")
65 with subtest("test6 user should be able to keepenv"):
66 envs = ["BATTERY=HORSE", "CORRECT=false"]
67 out = machine.succeed(
68 'su - test6 -c "BATTERY=HORSE CORRECT=false STAPLE=Tr0ub4dor doas env"'
71 if not all(env in out for env in envs):
72 raise Exception("failed to keep BATTERY or CORRECT")
73 if "STAPLE=Tr0ub4dor" in out:
74 raise Exception("failed to exclude STAPLE")
76 with subtest("test7 should not have access to SSH_AUTH_SOCK"):
77 if "SSH_AUTH_SOCK=HOLEY" in machine.succeed(
78 'su - test7 -c "SSH_AUTH_SOCK=HOLEY doas env"'
80 raise Exception("failed to exclude SSH_AUTH_SOCK")