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