···
# Some tests to ensure sudo is working properly.
4
-
inherit (pkgs.lib) mkIf optionalString;
7
-
import ./make-test-python.nix (
11
-
meta.maintainers = pkgs.sudo-rs.meta.maintainers;
8
+
meta.maintainers = pkgs.sudo-rs.meta.maintainers;
16
-
environment.systemPackages = [ pkgs.faketty ];
13
+
environment.systemPackages = [ pkgs.faketty ];
26
-
isNormalUser = true;
27
-
extraGroups = [ "wheel" ];
30
-
isNormalUser = true;
31
-
password = password;
34
-
isNormalUser = true;
35
-
extraGroups = [ "foobar" ];
36
-
password = password;
39
-
isNormalUser = true;
40
-
extraGroups = [ "barfoo" ];
43
-
isNormalUser = true;
44
-
extraGroups = [ "baz" ];
47
-
isNormalUser = true;
23
+
isNormalUser = true;
24
+
extraGroups = [ "wheel" ];
27
+
isNormalUser = true;
28
+
password = password;
31
+
isNormalUser = true;
32
+
extraGroups = [ "foobar" ];
33
+
password = password;
36
+
isNormalUser = true;
37
+
extraGroups = [ "barfoo" ];
40
+
isNormalUser = true;
41
+
extraGroups = [ "baz" ];
44
+
isNormalUser = true;
51
-
security.sudo-rs = {
53
-
wheelNeedsPassword = false;
48
+
security.sudo-rs = {
50
+
wheelNeedsPassword = false;
56
-
# SUDOERS SYNTAX CHECK (Test whether the module produces a valid output;
57
-
# errors being detected by the visudo checks.
53
+
# SUDOERS SYNTAX CHECK (Test whether the module produces a valid output;
54
+
# errors being detected by the visudo checks.
59
-
# These should not create any entries
61
-
users = [ "notest1" ];
56
+
# These should not create any entries
58
+
users = [ "notest1" ];
73
-
# Test defining commands with the options syntax, though not setting any options
75
-
users = [ "notest2" ];
70
+
# Test defining commands with the options syntax, though not setting any options
72
+
users = [ "notest2" ];
84
-
# CONFIGURATION FOR TEST CASES
86
-
users = [ "test1" ];
87
-
groups = [ "foobar" ];
88
-
commands = [ "ALL" ];
98
-
options = [ "NOPASSWD" ];
103
-
users = [ "test5" ];
107
-
options = [ "NOPASSWD" ];
110
-
runAs = "test1:barfoo";
81
+
# CONFIGURATION FOR TEST CASES
83
+
users = [ "test1" ];
84
+
groups = [ "foobar" ];
85
+
commands = [ "ALL" ];
95
+
options = [ "NOPASSWD" ];
100
+
users = [ "test5" ];
104
+
options = [ "NOPASSWD" ];
107
+
runAs = "test1:barfoo";
119
-
environment.systemPackages = [ pkgs.faketty ];
122
-
isNormalUser = true;
123
-
extraGroups = [ "wheel" ];
126
-
isNormalUser = true;
116
+
environment.systemPackages = [ pkgs.faketty ];
119
+
isNormalUser = true;
120
+
extraGroups = [ "wheel" ];
123
+
isNormalUser = true;
130
-
security.sudo-rs = {
132
-
wheelNeedsPassword = false;
133
-
execWheelOnly = true;
127
+
security.sudo-rs = {
129
+
wheelNeedsPassword = false;
130
+
execWheelOnly = true;
134
+
testScript = # python
with subtest("users in wheel group should have passwordless sudo"):
machine.succeed('faketty -- su - test0 -c "sudo -u root true"')
···
with subtest("non-wheel users should be unable to run sudo thanks to execWheelOnly"):
strict.fail('faketty -- su - noadmin -c "sudo --help"')