summaryrefslogtreecommitdiff
path: root/test/data/etc/polkit-1/rules.d/10-testing.rules
blob: 1dba38a6cce2b4cb845bee897f687a8db8a5bbdd (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
/* -*- 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 */

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

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

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

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

// -----

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

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

polkit.addRule(function(action, subject, details) {
    if (action == "net.company.order0") {
        details["test_detail"] = "a";
        return "yes";
    }
});

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

polkit.addRule(function(action, subject, details) {
    if (action == "net.company.group.only_group_users") {
        if (subject.isInGroup("users"))
            return "yes";
        else
            return "no";
    }
});

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

polkit.addRule(function(action, subject, details) {
    if (action == "net.company.group.only_netgroup_users") {
        if (subject.isInNetGroup("foo"))
            return "yes";
        else
            return "no";
    }
});

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

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

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

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

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

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

polkit.addRule(function(action, subject, details) {
    if (action == "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")
                return "yes"
            return "no";
        }
    }
});