|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // This verifies that AddonUpdateChecker works correctly |
|
6 |
|
7 Components.utils.import("resource://gre/modules/addons/AddonUpdateChecker.jsm"); |
|
8 |
|
9 Components.utils.import("resource://testing-common/httpd.js"); |
|
10 var testserver; |
|
11 |
|
12 function run_test() { |
|
13 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
|
14 |
|
15 // Create and configure the HTTP server. |
|
16 testserver = new HttpServer(); |
|
17 testserver.registerDirectory("/data/", do_get_file("data")); |
|
18 testserver.start(4444); |
|
19 |
|
20 do_test_pending(); |
|
21 run_test_1(); |
|
22 } |
|
23 |
|
24 function end_test() { |
|
25 testserver.stop(do_test_finished); |
|
26 } |
|
27 |
|
28 // Test that a basic update check returns the expected available updates |
|
29 function run_test_1() { |
|
30 AddonUpdateChecker.checkForUpdates("updatecheck1@tests.mozilla.org", null, |
|
31 "http://localhost:4444/data/test_updatecheck.rdf", { |
|
32 onUpdateCheckComplete: function(updates) { |
|
33 check_test_1(updates); |
|
34 }, |
|
35 |
|
36 onUpdateCheckError: function(status) { |
|
37 do_throw("Update check failed with status " + status); |
|
38 } |
|
39 }); |
|
40 } |
|
41 |
|
42 function check_test_1(updates) { |
|
43 do_check_eq(updates.length, 5); |
|
44 let update = AddonUpdateChecker.getNewestCompatibleUpdate(updates); |
|
45 do_check_neq(update, null); |
|
46 do_check_eq(update.version, 3); |
|
47 update = AddonUpdateChecker.getCompatibilityUpdate(updates, "2"); |
|
48 do_check_neq(update, null); |
|
49 do_check_eq(update.version, 2); |
|
50 do_check_eq(update.targetApplications[0].minVersion, 1); |
|
51 do_check_eq(update.targetApplications[0].maxVersion, 2); |
|
52 |
|
53 run_test_2(); |
|
54 } |
|
55 |
|
56 /* |
|
57 * Tests that the security checks are applied correctly |
|
58 * |
|
59 * Test signature updateHash updateLink expected |
|
60 *-------------------------------------------------------- |
|
61 * 2 absent absent http fail |
|
62 * 3 broken absent http fail |
|
63 * 4 correct absent http no update |
|
64 * 5 correct sha1 http update |
|
65 * 6 corrent absent https update |
|
66 * 7 corrent sha1 https update |
|
67 * 8 corrent md2 http no update |
|
68 * 9 corrent md2 https update |
|
69 */ |
|
70 |
|
71 let updateKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDK426erD/H3XtsjvaB5+PJqbhj" + |
|
72 "Zc9EDI5OCJS8R3FIObJ9ZHJK1TXeaE7JWqt9WUmBWTEFvwS+FI9vWu8058N9CHhD" + |
|
73 "NyeP6i4LuUYjTURnn7Yw/IgzyIJ2oKsYa32RuxAyteqAWqPT/J63wBixIeCxmysf" + |
|
74 "awB/zH4KaPiY3vnrzQIDAQAB"; |
|
75 |
|
76 function run_test_2() { |
|
77 AddonUpdateChecker.checkForUpdates("test_bug378216_5@tests.mozilla.org", |
|
78 updateKey, |
|
79 "http://localhost:4444/data/test_updatecheck.rdf", { |
|
80 onUpdateCheckComplete: function(updates) { |
|
81 do_throw("Expected the update check to fail"); |
|
82 }, |
|
83 |
|
84 onUpdateCheckError: function(status) { |
|
85 run_test_3(); |
|
86 } |
|
87 }); |
|
88 } |
|
89 |
|
90 function run_test_3() { |
|
91 AddonUpdateChecker.checkForUpdates("test_bug378216_7@tests.mozilla.org", |
|
92 updateKey, |
|
93 "http://localhost:4444/data/test_updatecheck.rdf", { |
|
94 onUpdateCheckComplete: function(updates) { |
|
95 do_throw("Expected the update check to fail"); |
|
96 }, |
|
97 |
|
98 onUpdateCheckError: function(status) { |
|
99 run_test_4(); |
|
100 } |
|
101 }); |
|
102 } |
|
103 |
|
104 function run_test_4() { |
|
105 AddonUpdateChecker.checkForUpdates("test_bug378216_8@tests.mozilla.org", |
|
106 updateKey, |
|
107 "http://localhost:4444/data/test_updatecheck.rdf", { |
|
108 onUpdateCheckComplete: function(updates) { |
|
109 do_check_eq(updates.length, 1); |
|
110 do_check_false("updateURL" in updates[0]); |
|
111 run_test_5(); |
|
112 }, |
|
113 |
|
114 onUpdateCheckError: function(status) { |
|
115 do_throw("Update check failed with status " + status); |
|
116 } |
|
117 }); |
|
118 } |
|
119 |
|
120 function run_test_5() { |
|
121 AddonUpdateChecker.checkForUpdates("test_bug378216_9@tests.mozilla.org", |
|
122 updateKey, |
|
123 "http://localhost:4444/data/test_updatecheck.rdf", { |
|
124 onUpdateCheckComplete: function(updates) { |
|
125 do_check_eq(updates.length, 1); |
|
126 do_check_eq(updates[0].version, "2.0"); |
|
127 do_check_true("updateURL" in updates[0]); |
|
128 run_test_6(); |
|
129 }, |
|
130 |
|
131 onUpdateCheckError: function(status) { |
|
132 do_throw("Update check failed with status " + status); |
|
133 } |
|
134 }); |
|
135 } |
|
136 |
|
137 function run_test_6() { |
|
138 AddonUpdateChecker.checkForUpdates("test_bug378216_10@tests.mozilla.org", |
|
139 updateKey, |
|
140 "http://localhost:4444/data/test_updatecheck.rdf", { |
|
141 onUpdateCheckComplete: function(updates) { |
|
142 do_check_eq(updates.length, 1); |
|
143 do_check_eq(updates[0].version, "2.0"); |
|
144 do_check_true("updateURL" in updates[0]); |
|
145 run_test_7(); |
|
146 }, |
|
147 |
|
148 onUpdateCheckError: function(status) { |
|
149 do_throw("Update check failed with status " + status); |
|
150 } |
|
151 }); |
|
152 } |
|
153 |
|
154 function run_test_7() { |
|
155 AddonUpdateChecker.checkForUpdates("test_bug378216_11@tests.mozilla.org", |
|
156 updateKey, |
|
157 "http://localhost:4444/data/test_updatecheck.rdf", { |
|
158 onUpdateCheckComplete: function(updates) { |
|
159 do_check_eq(updates.length, 1); |
|
160 do_check_eq(updates[0].version, "2.0"); |
|
161 do_check_true("updateURL" in updates[0]); |
|
162 run_test_8(); |
|
163 }, |
|
164 |
|
165 onUpdateCheckError: function(status) { |
|
166 do_throw("Update check failed with status " + status); |
|
167 } |
|
168 }); |
|
169 } |
|
170 |
|
171 function run_test_8() { |
|
172 AddonUpdateChecker.checkForUpdates("test_bug378216_12@tests.mozilla.org", |
|
173 updateKey, |
|
174 "http://localhost:4444/data/test_updatecheck.rdf", { |
|
175 onUpdateCheckComplete: function(updates) { |
|
176 do_check_eq(updates.length, 1); |
|
177 do_check_false("updateURL" in updates[0]); |
|
178 run_test_9(); |
|
179 }, |
|
180 |
|
181 onUpdateCheckError: function(status) { |
|
182 do_throw("Update check failed with status " + status); |
|
183 } |
|
184 }); |
|
185 } |
|
186 |
|
187 function run_test_9() { |
|
188 AddonUpdateChecker.checkForUpdates("test_bug378216_13@tests.mozilla.org", |
|
189 updateKey, |
|
190 "http://localhost:4444/data/test_updatecheck.rdf", { |
|
191 onUpdateCheckComplete: function(updates) { |
|
192 do_check_eq(updates.length, 1); |
|
193 do_check_eq(updates[0].version, "2.0"); |
|
194 do_check_true("updateURL" in updates[0]); |
|
195 run_test_10(); |
|
196 }, |
|
197 |
|
198 onUpdateCheckError: function(status) { |
|
199 do_throw("Update check failed with status " + status); |
|
200 } |
|
201 }); |
|
202 } |
|
203 |
|
204 function run_test_10() { |
|
205 AddonUpdateChecker.checkForUpdates("test_bug378216_14@tests.mozilla.org", |
|
206 null, |
|
207 "http://localhost:4444/data/test_updatecheck.rdf", { |
|
208 onUpdateCheckComplete: function(updates) { |
|
209 do_check_eq(updates.length, 0); |
|
210 run_test_11(); |
|
211 }, |
|
212 |
|
213 onUpdateCheckError: function(status) { |
|
214 do_throw("Update check failed with status " + status); |
|
215 } |
|
216 }); |
|
217 } |
|
218 |
|
219 function run_test_11() { |
|
220 AddonUpdateChecker.checkForUpdates("test_bug378216_15@tests.mozilla.org", |
|
221 null, |
|
222 "http://localhost:4444/data/test_updatecheck.rdf", { |
|
223 onUpdateCheckComplete: function(updates) { |
|
224 do_throw("Update check should have failed"); |
|
225 }, |
|
226 |
|
227 onUpdateCheckError: function(status) { |
|
228 do_check_eq(status, AddonUpdateChecker.ERROR_PARSE_ERROR); |
|
229 run_test_12(); |
|
230 } |
|
231 }); |
|
232 } |
|
233 |
|
234 function run_test_12() { |
|
235 AddonUpdateChecker.checkForUpdates("ignore-compat@tests.mozilla.org", |
|
236 null, |
|
237 "http://localhost:4444/data/test_updatecheck.rdf", { |
|
238 onUpdateCheckComplete: function(updates) { |
|
239 do_check_eq(updates.length, 3); |
|
240 let update = AddonUpdateChecker.getNewestCompatibleUpdate(updates, |
|
241 null, |
|
242 null, |
|
243 true); |
|
244 do_check_neq(update, null); |
|
245 do_check_eq(update.version, 2); |
|
246 run_test_13(); |
|
247 }, |
|
248 |
|
249 onUpdateCheckError: function(status) { |
|
250 do_throw("Update check failed with status " + status); |
|
251 } |
|
252 }); |
|
253 } |
|
254 |
|
255 function run_test_13() { |
|
256 AddonUpdateChecker.checkForUpdates("compat-override@tests.mozilla.org", |
|
257 null, |
|
258 "http://localhost:4444/data/test_updatecheck.rdf", { |
|
259 onUpdateCheckComplete: function(updates) { |
|
260 do_check_eq(updates.length, 3); |
|
261 let overrides = [{ |
|
262 type: "incompatible", |
|
263 minVersion: 1, |
|
264 maxVersion: 2, |
|
265 appID: "xpcshell@tests.mozilla.org", |
|
266 appMinVersion: 0.1, |
|
267 appMaxVersion: 0.2 |
|
268 }, { |
|
269 type: "incompatible", |
|
270 minVersion: 2, |
|
271 maxVersion: 2, |
|
272 appID: "xpcshell@tests.mozilla.org", |
|
273 appMinVersion: 1, |
|
274 appMaxVersion: 2 |
|
275 }]; |
|
276 let update = AddonUpdateChecker.getNewestCompatibleUpdate(updates, |
|
277 null, |
|
278 null, |
|
279 true, |
|
280 false, |
|
281 overrides); |
|
282 do_check_neq(update, null); |
|
283 do_check_eq(update.version, 1); |
|
284 run_test_14(); |
|
285 }, |
|
286 |
|
287 onUpdateCheckError: function(status) { |
|
288 do_throw("Update check failed with status " + status); |
|
289 } |
|
290 }); |
|
291 } |
|
292 |
|
293 function run_test_14() { |
|
294 AddonUpdateChecker.checkForUpdates("compat-strict-optin@tests.mozilla.org", |
|
295 null, |
|
296 "http://localhost:4444/data/test_updatecheck.rdf", { |
|
297 onUpdateCheckComplete: function(updates) { |
|
298 do_check_eq(updates.length, 1); |
|
299 let update = AddonUpdateChecker.getNewestCompatibleUpdate(updates, |
|
300 null, |
|
301 null, |
|
302 true, |
|
303 false); |
|
304 do_check_eq(update, null); |
|
305 end_test(); |
|
306 }, |
|
307 |
|
308 onUpdateCheckError: function(status) { |
|
309 do_throw("Update check failed with status " + status); |
|
310 } |
|
311 }); |
|
312 } |