LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 this.randomResult = currentTest.randomResult; | 278 this.randomResult = currentTest.randomResult; |
279 | 279 |
280 let maxHours = Math.round(Math.max.apply(null, currentTest.requests)) + 1; | 280 let maxHours = Math.round(Math.max.apply(null, currentTest.requests)) + 1; |
281 this.runScheduledTasks(maxHours, currentTest.skipAfter, currentTest.skip).th
en(() => | 281 this.runScheduledTasks(maxHours, currentTest.skipAfter, currentTest.skip).th
en(() => |
282 { | 282 { |
283 test.deepEqual(requests, currentTest.requests, "Requests"); | 283 test.deepEqual(requests, currentTest.requests, "Requests"); |
284 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 284 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
285 }; | 285 }; |
286 } | 286 } |
287 | 287 |
288 exports.testChecksumVerification = {}; | |
289 | |
290 for (let [testName, subscriptionBody, expectedResult] of [ | |
291 ["Correct checksum", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JHsq/A\nfoo\nbar\
n", true], | |
292 ["Wrong checksum", "[Adblock]\n! Checksum: wrongggny6Fn24b7JHsq/A\nfoo\nbar\n"
, false], | |
293 ["Empty lines ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JHsq/A\n\nfoo\
n\nbar\n\n", true], | |
294 ["CR LF line breaks treated like LR", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7
JHsq/A\nfoo\r\nbar\r\n", true], | |
295 ["CR line breaks treated like LR", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JHs
q/A\nfoo\rbar\r", true], | |
296 ["Trailing line break not ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JH
sq/A\nfoo\nbar", false], | |
297 ["Line breaks between lines not ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn
24b7JHsq/A\nfoobar", false], | |
298 ["Lines with spaces not ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JHsq
/A\n \nfoo\n\nbar\n", false], | |
299 ["Extra content in checksum line is part of the checksum", "[Adblock]\n! Check
sum: e/JCmqXny6Fn24b7JHsq/A foobar\nfoo\nbar\n", false], | |
300 ["= symbols after checksum are ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn2
4b7JHsq/A==\nfoo\nbar\n", true], | |
301 ["Header line is part of the checksum", "[Adblock Plus]\n! Checksum: e/JCmqXny
6Fn24b7JHsq/A\nfoo\nbar\n", false], | |
302 ["Special comments are part of the checksum", "[Adblock]\n! Checksum: e/JCmqXn
y6Fn24b7JHsq/A\n! Expires: 1\nfoo\nbar\n", false] | |
303 ]) | |
304 { | |
305 exports.testChecksumVerification[testName] = function(test) | |
306 { | |
307 let subscription = Subscription.fromURL("http://example.com/subscription"); | |
308 FilterStorage.addSubscription(subscription); | |
309 | |
310 this.registerHandler("/subscription", metadata => | |
311 { | |
312 return [Cr.NS_OK, 200, subscriptionBody]; | |
313 }); | |
314 | |
315 this.runScheduledTasks(2).then(() => | |
316 { | |
317 test.equal(subscription.downloadStatus, expectedResult ? "synchronize_ok"
: "synchronize_checksum_mismatch"); | |
318 }).catch(unexpectedError.bind(test)).then(() => test.done()); | |
319 }; | |
320 } | |
321 | |
322 exports.testSpecialComments = {}; | 288 exports.testSpecialComments = {}; |
323 | 289 |
324 for (let [comment, check] of [ | 290 for (let [comment, check] of [ |
325 ["! Homepage: http://example.com/", (test, subscription) => | 291 ["! Homepage: http://example.com/", (test, subscription) => |
326 { | 292 { |
327 test.equal(subscription.homepage, "http://example.com/", "Valid homepage com
ment"); | 293 test.equal(subscription.homepage, "http://example.com/", "Valid homepage com
ment"); |
328 }], | 294 }], |
329 ["! Homepage: ssh://example.com/", (test, subscription) => | 295 ["! Homepage: ssh://example.com/", (test, subscription) => |
330 { | 296 { |
331 test.equal(subscription.homepage, "", "Invalid homepage comment"); | 297 test.equal(subscription.homepage, "", "Invalid homepage comment"); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 redirectedRequests.push(this.getTimeOffset()); | 444 redirectedRequests.push(this.getTimeOffset()); |
479 return [Cr.NS_OK, 200, "[Adblock]\n!Expires: 1day\nfoo\nbar"]; | 445 return [Cr.NS_OK, 200, "[Adblock]\n!Expires: 1day\nfoo\nbar"]; |
480 }); | 446 }); |
481 | 447 |
482 return this.runScheduledTasks(100); | 448 return this.runScheduledTasks(100); |
483 }).then(() => | 449 }).then(() => |
484 { | 450 { |
485 test.equal(FilterStorage.subscriptionAt(0).url, "http://example.com/redirect
ed", "Valid redirect from fallback is followed"); | 451 test.equal(FilterStorage.subscriptionAt(0).url, "http://example.com/redirect
ed", "Valid redirect from fallback is followed"); |
486 test.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + initialD
elay], "Stop polling original URL after a valid redirect from fallback"); | 452 test.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + initialD
elay], "Stop polling original URL after a valid redirect from fallback"); |
487 test.deepEqual(redirectedRequests, [48 + initialDelay, 72 + initialDelay, 96
+ initialDelay], "Request new URL after a valid redirect from fallback"); | 453 test.deepEqual(redirectedRequests, [48 + initialDelay, 72 + initialDelay, 96
+ initialDelay], "Request new URL after a valid redirect from fallback"); |
488 | |
489 // Checksum mismatch | |
490 | |
491 this.registerHandler("/subscription", metadata => | |
492 { | |
493 return [Cr.NS_OK, 200, "[Adblock]\n! Checksum: wrong\nfoo\nbar"]; | |
494 }); | |
495 | |
496 subscription = Subscription.fromURL("http://example.com/subscription"); | |
497 resetSubscription(subscription); | |
498 FilterStorage.removeSubscription(FilterStorage.subscriptionAt(0)); | |
499 FilterStorage.addSubscription(subscription); | |
500 | |
501 return this.runScheduledTasks(100); | |
502 }).then(() => | |
503 { | |
504 test.equal(FilterStorage.subscriptionAt(0).url, "http://example.com/redirect
ed", "Wrong checksum produces fallback request"); | |
505 | 454 |
506 // Redirect loop | 455 // Redirect loop |
507 | 456 |
508 this.registerHandler("/subscription", metadata => | 457 this.registerHandler("/subscription", metadata => |
509 { | 458 { |
510 return [Cr.NS_OK, 200, "[Adblock]\n! Redirect: http://example.com/subscrip
tion2"]; | 459 return [Cr.NS_OK, 200, "[Adblock]\n! Redirect: http://example.com/subscrip
tion2"]; |
511 }); | 460 }); |
512 this.registerHandler("/subscription2", metadata => | 461 this.registerHandler("/subscription2", metadata => |
513 { | 462 { |
514 return [Cr.NS_OK, 200, "[Adblock]\n! Redirect: http://example.com/subscrip
tion"]; | 463 return [Cr.NS_OK, 200, "[Adblock]\n! Redirect: http://example.com/subscrip
tion"]; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 return this.runScheduledTasks(24); | 516 return this.runScheduledTasks(24); |
568 }).then(() => | 517 }).then(() => |
569 { | 518 { |
570 test.equal(subscription.downloadStatus, "synchronize_connection_error", "dow
nloadStatus after download error"); | 519 test.equal(subscription.downloadStatus, "synchronize_connection_error", "dow
nloadStatus after download error"); |
571 test.equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + (26 + i
nitialDelay) * MILLIS_IN_HOUR, "lastDownload after download error"); | 520 test.equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + (26 + i
nitialDelay) * MILLIS_IN_HOUR, "lastDownload after download error"); |
572 test.equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + initialD
elay * MILLIS_IN_HOUR, "lastSuccess after download error"); | 521 test.equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + initialD
elay * MILLIS_IN_HOUR, "lastSuccess after download error"); |
573 test.equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + (27 + init
ialDelay) * MILLIS_IN_HOUR, "lastCheck after download error"); | 522 test.equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + (27 + init
ialDelay) * MILLIS_IN_HOUR, "lastCheck after download error"); |
574 test.equal(subscription.errors, 2, "errors after download error"); | 523 test.equal(subscription.errors, 2, "errors after download error"); |
575 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 524 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
576 }; | 525 }; |
LEFT | RIGHT |