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
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
function matches_always(perm, principals) {
principals.forEach((principal) => {
do_check_true(perm.matches(principal, true), "perm: " + perm.principal.origin + ", princ: " + principal.origin);
do_check_true(perm.matches(principal, false), "perm: " + perm.principal.origin + ", princ: " + principal.origin);
});
}
function matches_weak(perm, principals) {
principals.forEach((principal) => {
do_check_false(perm.matches(principal, true), "perm: " + perm.principal.origin + ", princ: " + principal.origin);
do_check_true(perm.matches(principal, false), "perm: " + perm.principal.origin + ", princ: " + principal.origin);
});
}
function matches_never(perm, principals) {
principals.forEach((principal) => {
do_check_false(perm.matches(principal, true), "perm: " + perm.principal.origin + ", princ: " + principal.origin);
do_check_false(perm.matches(principal, false), "perm: " + perm.principal.origin + ", princ: " + principal.origin);
});
}
function run_test() {
// initialize the permission manager service
let pm = Cc["@mozilla.org/permissionmanager;1"].
getService(Ci.nsIPermissionManager);
let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager);
// Add some permissions
let uri0 = NetUtil.newURI("http://google.com/search?q=foo#hashtag", null, null);
let uri1 = NetUtil.newURI("http://hangouts.google.com/subdir", null, null);
let uri2 = NetUtil.newURI("http://google.org/", null, null);
let uri3 = NetUtil.newURI("https://google.com/some/random/subdirectory", null, null);
let uri4 = NetUtil.newURI("https://hangouts.google.com/#!/hangout", null, null);
let uri5 = NetUtil.newURI("http://google.com:8096/", null, null);
let uri0_n_n = secMan.createCodebasePrincipal(uri0, {});
let uri1_n_n = secMan.createCodebasePrincipal(uri1, {});
let uri2_n_n = secMan.createCodebasePrincipal(uri2, {});
let uri3_n_n = secMan.createCodebasePrincipal(uri3, {});
let uri4_n_n = secMan.createCodebasePrincipal(uri4, {});
let uri5_n_n = secMan.createCodebasePrincipal(uri5, {});
let attrs = {appId: 1000};
let uri0_1000_n = secMan.createCodebasePrincipal(uri0, attrs);
let uri1_1000_n = secMan.createCodebasePrincipal(uri1, attrs);
let uri2_1000_n = secMan.createCodebasePrincipal(uri2, attrs);
let uri3_1000_n = secMan.createCodebasePrincipal(uri3, attrs);
let uri4_1000_n = secMan.createCodebasePrincipal(uri4, attrs);
let uri5_1000_n = secMan.createCodebasePrincipal(uri5, attrs);
attrs = {appId: 1000, inIsolatedMozBrowser: true};
let uri0_1000_y = secMan.createCodebasePrincipal(uri0, attrs);
let uri1_1000_y = secMan.createCodebasePrincipal(uri1, attrs);
let uri2_1000_y = secMan.createCodebasePrincipal(uri2, attrs);
let uri3_1000_y = secMan.createCodebasePrincipal(uri3, attrs);
let uri4_1000_y = secMan.createCodebasePrincipal(uri4, attrs);
let uri5_1000_y = secMan.createCodebasePrincipal(uri5, attrs);
attrs = {appId: 2000};
let uri0_2000_n = secMan.createCodebasePrincipal(uri0, attrs);
let uri1_2000_n = secMan.createCodebasePrincipal(uri1, attrs);
let uri2_2000_n = secMan.createCodebasePrincipal(uri2, attrs);
let uri3_2000_n = secMan.createCodebasePrincipal(uri3, attrs);
let uri4_2000_n = secMan.createCodebasePrincipal(uri4, attrs);
let uri5_2000_n = secMan.createCodebasePrincipal(uri5, attrs);
attrs = {appId: 2000, inIsolatedMozBrowser: true};
let uri0_2000_y = secMan.createCodebasePrincipal(uri0, attrs);
let uri1_2000_y = secMan.createCodebasePrincipal(uri1, attrs);
let uri2_2000_y = secMan.createCodebasePrincipal(uri2, attrs);
let uri3_2000_y = secMan.createCodebasePrincipal(uri3, attrs);
let uri4_2000_y = secMan.createCodebasePrincipal(uri4, attrs);
let uri5_2000_y = secMan.createCodebasePrincipal(uri5, attrs);
attrs = {userContextId: 1};
let uri0_1 = secMan.createCodebasePrincipal(uri0, attrs);
let uri1_1 = secMan.createCodebasePrincipal(uri1, attrs);
let uri2_1 = secMan.createCodebasePrincipal(uri2, attrs);
let uri3_1 = secMan.createCodebasePrincipal(uri3, attrs);
let uri4_1 = secMan.createCodebasePrincipal(uri4, attrs);
let uri5_1 = secMan.createCodebasePrincipal(uri5, attrs);
attrs = {firstPartyDomain: "cnn.com"};
let uri0_cnn = secMan.createCodebasePrincipal(uri0, attrs);
let uri1_cnn = secMan.createCodebasePrincipal(uri1, attrs);
let uri2_cnn = secMan.createCodebasePrincipal(uri2, attrs);
let uri3_cnn = secMan.createCodebasePrincipal(uri3, attrs);
let uri4_cnn = secMan.createCodebasePrincipal(uri4, attrs);
let uri5_cnn = secMan.createCodebasePrincipal(uri5, attrs);
pm.addFromPrincipal(uri0_n_n, "test/matches", pm.ALLOW_ACTION);
let perm_n_n = pm.getPermissionObject(uri0_n_n, "test/matches", true);
pm.addFromPrincipal(uri0_1000_n, "test/matches", pm.ALLOW_ACTION);
let perm_1000_n = pm.getPermissionObject(uri0_1000_n, "test/matches", true);
pm.addFromPrincipal(uri0_1000_y, "test/matches", pm.ALLOW_ACTION);
let perm_1000_y = pm.getPermissionObject(uri0_1000_y, "test/matches", true);
pm.addFromPrincipal(uri0_2000_n, "test/matches", pm.ALLOW_ACTION);
let perm_2000_n = pm.getPermissionObject(uri0_2000_n, "test/matches", true);
pm.addFromPrincipal(uri0_2000_y, "test/matches", pm.ALLOW_ACTION);
let perm_2000_y = pm.getPermissionObject(uri0_2000_y, "test/matches", true);
pm.addFromPrincipal(uri0_1, "test/matches", pm.ALLOW_ACTION);
let perm_1 = pm.getPermissionObject(uri0_n_n, "test/matches", true);
pm.addFromPrincipal(uri0_cnn, "test/matches", pm.ALLOW_ACTION);
let perm_cnn = pm.getPermissionObject(uri0_n_n, "test/matches", true);
matches_always(perm_n_n, [uri0_n_n, uri0_1, uri0_cnn]);
matches_weak(perm_n_n, [uri1_n_n, uri1_1, uri1_cnn]);
matches_never(perm_n_n, [uri2_n_n, uri3_n_n, uri4_n_n, uri5_n_n,
uri0_1000_n, uri1_1000_n, uri2_1000_n, uri3_1000_n, uri4_1000_n, uri5_1000_n,
uri0_1000_y, uri1_1000_y, uri2_1000_y, uri3_1000_y, uri4_1000_y, uri5_1000_y,
uri0_2000_n, uri1_2000_n, uri2_2000_n, uri3_2000_n, uri4_2000_n, uri5_2000_n,
uri0_2000_y, uri1_2000_y, uri2_2000_y, uri3_2000_y, uri4_2000_y, uri5_2000_y,
uri2_1, uri3_1, uri4_1, uri5_1,
uri2_cnn, uri3_cnn, uri4_cnn, uri5_cnn]);
matches_always(perm_1000_n, [uri0_1000_n]);
matches_weak(perm_1000_n, [uri1_1000_n]);
matches_never(perm_1000_n, [uri2_1000_n, uri3_1000_n, uri4_1000_n, uri5_1000_n,
uri0_n_n, uri1_n_n, uri2_n_n, uri3_n_n, uri4_n_n, uri5_n_n,
uri0_1000_y, uri1_1000_y, uri2_1000_y, uri3_1000_y, uri4_1000_y, uri5_1000_y,
uri0_2000_n, uri1_2000_n, uri2_2000_n, uri3_2000_n, uri4_2000_n, uri5_2000_n,
uri0_2000_y, uri1_2000_y, uri2_2000_y, uri3_2000_y, uri4_2000_y, uri5_2000_y,
uri0_1, uri1_1, uri2_1, uri3_1, uri4_1, uri5_1,
uri0_cnn, uri1_cnn, uri2_cnn, uri3_cnn, uri4_cnn, uri5_cnn]);
matches_always(perm_1000_y, [uri0_1000_y]);
matches_weak(perm_1000_y, [uri1_1000_y]);
matches_never(perm_1000_y, [uri2_1000_y, uri3_1000_y, uri4_1000_y, uri5_1000_y,
uri0_n_n, uri1_n_n, uri2_n_n, uri3_n_n, uri4_n_n, uri5_n_n,
uri0_1000_n, uri1_1000_n, uri2_1000_n, uri3_1000_n, uri4_1000_n, uri5_1000_n,
uri0_2000_n, uri1_2000_n, uri2_2000_n, uri3_2000_n, uri4_2000_n, uri5_2000_n,
uri0_2000_y, uri1_2000_y, uri2_2000_y, uri3_2000_y, uri4_2000_y, uri5_2000_y,
uri0_1, uri1_1, uri2_1, uri3_1, uri4_1, uri5_1,
uri0_cnn, uri1_cnn, uri2_cnn, uri3_cnn, uri4_cnn, uri5_cnn]);
matches_always(perm_2000_n, [uri0_2000_n]);
matches_weak(perm_2000_n, [uri1_2000_n]);
matches_never(perm_2000_n, [uri2_2000_n, uri3_2000_n, uri4_2000_n, uri5_2000_n,
uri0_n_n, uri1_n_n, uri2_n_n, uri3_n_n, uri4_n_n, uri5_n_n,
uri0_2000_y, uri1_2000_y, uri2_2000_y, uri3_2000_y, uri4_2000_y, uri5_2000_y,
uri0_1000_n, uri1_1000_n, uri2_1000_n, uri3_1000_n, uri4_1000_n, uri5_1000_n,
uri0_1000_y, uri1_1000_y, uri2_1000_y, uri3_1000_y, uri4_1000_y, uri5_1000_y,
uri0_1, uri1_1, uri2_1, uri3_1, uri4_1, uri5_1,
uri0_cnn, uri1_cnn, uri2_cnn, uri3_cnn, uri4_cnn, uri5_cnn]);
matches_always(perm_2000_y, [uri0_2000_y]);
matches_weak(perm_2000_y, [uri1_2000_y]);
matches_never(perm_2000_y, [uri2_2000_y, uri3_2000_y, uri4_2000_y, uri5_2000_y,
uri0_n_n, uri1_n_n, uri2_n_n, uri3_n_n, uri4_n_n, uri5_n_n,
uri0_2000_n, uri1_2000_n, uri2_2000_n, uri3_2000_n, uri4_2000_n, uri5_2000_n,
uri0_1000_n, uri1_1000_n, uri2_1000_n, uri3_1000_n, uri4_1000_n, uri5_1000_n,
uri0_1000_y, uri1_1000_y, uri2_1000_y, uri3_1000_y, uri4_1000_y, uri5_1000_y,
uri0_1, uri1_1, uri2_1, uri3_1, uri4_1, uri5_1,
uri0_cnn, uri1_cnn, uri2_cnn, uri3_cnn, uri4_cnn, uri5_cnn]);
matches_always(perm_1, [uri0_n_n, uri0_1, uri0_cnn]);
matches_weak(perm_1, [uri1_n_n, uri1_1, uri1_cnn]);
matches_never(perm_1, [uri2_n_n, uri3_n_n, uri4_n_n, uri5_n_n,
uri0_1000_n, uri1_1000_n, uri2_1000_n, uri3_1000_n, uri4_1000_n, uri5_1000_n,
uri0_1000_y, uri1_1000_y, uri2_1000_y, uri3_1000_y, uri4_1000_y, uri5_1000_y,
uri0_2000_n, uri1_2000_n, uri2_2000_n, uri3_2000_n, uri4_2000_n, uri5_2000_n,
uri0_2000_y, uri1_2000_y, uri2_2000_y, uri3_2000_y, uri4_2000_y, uri5_2000_y,
uri2_1, uri3_1, uri4_1, uri5_1,
uri2_cnn, uri3_cnn, uri4_cnn, uri5_cnn]);
matches_always(perm_cnn, [uri0_n_n, uri0_1, uri0_cnn]);
matches_weak(perm_cnn, [uri1_n_n, uri1_1, uri1_cnn]);
matches_never(perm_cnn, [uri2_n_n, uri3_n_n, uri4_n_n, uri5_n_n,
uri0_1000_n, uri1_1000_n, uri2_1000_n, uri3_1000_n, uri4_1000_n, uri5_1000_n,
uri0_1000_y, uri1_1000_y, uri2_1000_y, uri3_1000_y, uri4_1000_y, uri5_1000_y,
uri0_2000_n, uri1_2000_n, uri2_2000_n, uri3_2000_n, uri4_2000_n, uri5_2000_n,
uri0_2000_y, uri1_2000_y, uri2_2000_y, uri3_2000_y, uri4_2000_y, uri5_2000_y,
uri2_1, uri3_1, uri4_1, uri5_1,
uri2_cnn, uri3_cnn, uri4_cnn, uri5_cnn]);
// Clean up!
pm.removeAll();
}
|