summaryrefslogtreecommitdiff
path: root/test/data/etc/polkit-1/rules.d/10-testing.rules
blob: e346b5dd3f08886cd93ceca3c9c81f7802aa4f18 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/* -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*- */

/* see test/polkitbackend/test-polkitbackendjsauthority.c */

/* NOTE: this is the /etc/polkit-1/rules.d version of 10-testing.rules */

// ---------------------------------------------------------------------
// admin rules

polkit.addAdminRule(function(action, subject) {
    if (action.id == "net.company.action1") {
        return ["unix-group:admin"];
    }
});

polkit.addAdminRule(function(action, subject) {
    if (action.id == "net.company.action2") {
        return ["unix-group:users"];
    }
});

polkit.addAdminRule(function(action, subject) {
    if (action.id == "net.company.action3") {
        return ["unix-netgroup:foo"];
    }
});

// Fallback
polkit.addAdminRule(function(action, subject) {
    return ["unix-group:admin", "unix-user:root"];
});

// -----

// ---------------------------------------------------------------------
// basics

polkit.addRule(function(action, subject) {
    if (action.id == "net.company.productA.action0") {
        return polkit.Result.AUTH_ADMIN;
    }
});

polkit.addRule(function(action, subject) {
    if (action.id == "net.company.productA.action1") {
        return polkit.Result.AUTH_SELF;
    }
});

polkit.addRule(function(action, subject) {
    if (action.id == "net.company.order0") {
        return polkit.Result.YES;
    }
});

polkit.addRule(function(action, subject) {
    if (action.id == "net.company.john_action") {
        if (subject.user == "john") {
            return polkit.Result.YES;
        } else {
            return polkit.Result.NO;
        }
    }
});

polkit.addRule(function(action, subject) {
    if (action.id == "net.company.highuid2_action") {
        if (subject.user == "highuid2") {
            return polkit.Result.YES;
        } else {
            return polkit.Result.NO;
        }
    }
});


// ---------------------------------------------------------------------
// variables

polkit.addRule(function(action, subject) {
    if (action.id == "net.company.group.variables") {
        if (action.lookup("foo") == "1")
            return polkit.Result.YES;
        else if (action.lookup("foo") == "2")
            return polkit.Result.AUTH_SELF;
        else
            return polkit.Result.AUTH_ADMIN;
    }
});


// ---------------------------------------------------------------------
// group membership

polkit.addRule(function(action, subject) {
    if (action.id == "net.company.group.only_group_users") {
        if (subject.isInGroup("users"))
            return polkit.Result.YES;
        else
            return polkit.Result.NO;
    }
});

// ---------------------------------------------------------------------
// netgroup membership

polkit.addRule(function(action, subject) {
    if (action.id == "net.company.group.only_netgroup_users") {
        if (subject.isInNetGroup("foo"))
            return polkit.Result.YES;
        else
            return polkit.Result.NO;
    }
});

// ---------------------------------------------------------------------
// spawning

polkit.addRule(function(action, subject) {
    if (action.id == "net.company.spawning.non_existing_helper") {
        try {
            polkit.spawn(["/path/to/non/existing/helper"]);
            return polkit.Result.NO;
        } catch (error) {
            return polkit.Result.YES;
        }
    }
});

polkit.addRule(function(action, subject) {
    if (action.id == "net.company.spawning.successful_helper") {
        try {
            polkit.spawn(["/bin/true"]);
            return polkit.Result.YES;
        } catch (error) {
            return polkit.Result.NO;
        }
    }
});

polkit.addRule(function(action, subject) {
    if (action.id == "net.company.spawning.failing_helper") {
        try {
            polkit.spawn(["/bin/false"]);
            return polkit.Result.NO;
        } catch (error) {
            return polkit.Result.YES;
        }
    }
});

polkit.addRule(function(action, subject) {
    if (action.id == "net.company.spawning.helper_with_output") {
        try {
            var out = polkit.spawn(["echo", "-n", "-e", "Hello\nWorld"]);
            if (out == "Hello\nWorld")
                return polkit.Result.YES;
            else
                return polkit.Result.NO;
        } catch (error) {
            return polkit.Result.NO;
        }
    }
});

polkit.addRule(function(action, subject) {
    if (action.id == "net.company.spawning.helper_timeout") {
        try {
            polkit.spawn(["sleep", "20"]);
            return polkit.Result.NO;
        } catch (error) {
            if (error == "Error: Error spawning helper: Timed out after 10 seconds (g-io-error-quark, 24)")
                return polkit.Result.YES;
            return polkit.Result.NO;
        }
    }
});

// ---------------------------------------------------------------------
// runaway scripts

polkit.addRule(function(action, subject) {
    if (action.id == "net.company.run_away_script") {
        try {
            // The following code will never terminate so the runaway
            // script killer will step in after 15 seconds and throw
            // an exception...
            while (true)
                ;
        } catch (error) {
            if (error == "Terminating runaway script")
                // Inverted logic to accomodate Duktape's model as well, which
                // will always fail with negation, on timeouts
                return polkit.Result.NO;
            return polkit.Result.YES;
        }
    }
});