Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: test/filterClasses.js

Issue 29680689: [$csp2 adblockpluscore] Issue 6329 - Add the CSP filter type (Closed)
Left Patch Set: Added test case for case insensitive forbidden directives Created March 16, 2018, 10:29 a.m.
Right Patch Set: Addressed Sebastian's feedback Created March 21, 2018, 4:51 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/filterClasses.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 compareFilter(test, "@@/ddd|f?a[s]d/", ["type=whitelist", "text=@@/ddd|f?a[s]d /", "regexp=ddd|f?a[s]d", "contentType=" + defaultTypes]); 279 compareFilter(test, "@@/ddd|f?a[s]d/", ["type=whitelist", "text=@@/ddd|f?a[s]d /", "regexp=ddd|f?a[s]d", "contentType=" + defaultTypes]);
280 compareFilter(test, "@@*asdf*d**dd*", ["type=whitelist", "text=@@*asdf*d**dd*" , "regexp=asdf.*d.*dd", "contentType=" + defaultTypes]); 280 compareFilter(test, "@@*asdf*d**dd*", ["type=whitelist", "text=@@*asdf*d**dd*" , "regexp=asdf.*d.*dd", "contentType=" + defaultTypes]);
281 compareFilter(test, "@@|*asd|f*d**dd*|", ["type=whitelist", "text=@@|*asd|f*d* *dd*|", "regexp=^.*asd\\|f.*d.*dd.*$", "contentType=" + defaultTypes]); 281 compareFilter(test, "@@|*asd|f*d**dd*|", ["type=whitelist", "text=@@|*asd|f*d* *dd*|", "regexp=^.*asd\\|f.*d.*dd.*$", "contentType=" + defaultTypes]);
282 compareFilter(test, "@@dd[]{}$%<>&()d", ["type=whitelist", "text=@@dd[]{}$%<>& ()d", "regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\)d", "contentType=" + defaultTyp es]); 282 compareFilter(test, "@@dd[]{}$%<>&()d", ["type=whitelist", "text=@@dd[]{}$%<>& ()d", "regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\)d", "contentType=" + defaultTyp es]);
283 283
284 test.done(); 284 test.done();
285 }; 285 };
286 286
287 exports.testFilterOptions = function(test) 287 exports.testFilterOptions = function(test)
288 { 288 {
289 compareFilter(test, "bla$match-case,csp=first csp,script,other,third-party,dom ain=foo.com,sitekey=foo,csp=second csp", ["type=filterlist", "text=bla$match-cas e,csp=first csp,script,other,third-party,domain=foo.com,sitekey=foo,csp=second c sp", "regexp=bla", "matchCase=true", "contentType=" + (t.SCRIPT | t.OTHER | t.CS P), "thirdParty=true", "domains=FOO.COM", "sitekeys=FOO", "csp=first csp; second csp"]); 289 compareFilter(test, "bla$match-case,csp=first csp,script,other,third-party,dom ain=foo.com,sitekey=foo", ["type=filterlist", "text=bla$match-case,csp=first csp ,script,other,third-party,domain=foo.com,sitekey=foo", "regexp=bla", "matchCase= true", "contentType=" + (t.SCRIPT | t.OTHER | t.CSP), "thirdParty=true", "domain s=FOO.COM", "sitekeys=FOO", "csp=first csp"]);
290 compareFilter(test, "bla$~match-case,~csp=csp,~script,~other,~third-party,doma in=~bar.com", ["type=filterlist", "text=bla$~match-case,~csp=csp,~script,~other, ~third-party,domain=~bar.com", "regexp=bla", "contentType=" + (defaultTypes & ~( t.SCRIPT | t.OTHER)), "thirdParty=false", "domains=~BAR.COM"]); 290 compareFilter(test, "bla$~match-case,~csp=csp,~script,~other,~third-party,doma in=~bar.com", ["type=filterlist", "text=bla$~match-case,~csp=csp,~script,~other, ~third-party,domain=~bar.com", "regexp=bla", "contentType=" + (defaultTypes & ~( t.SCRIPT | t.OTHER)), "thirdParty=false", "domains=~BAR.COM"]);
291 compareFilter(test, "@@bla$match-case,script,other,third-party,domain=foo.com| bar.com|~bar.foo.com|~foo.bar.com,csp=c s p,sitekey=foo|bar", ["type=whitelist", "text=@@bla$match-case,script,other,third-party,domain=foo.com|bar.com|~bar.foo .com|~foo.bar.com,csp=c s p,sitekey=foo|bar", "regexp=bla", "matchCase=true", "c ontentType=" + (t.SCRIPT | t.OTHER | t.CSP), "thirdParty=true", "domains=BAR.COM |FOO.COM|~BAR.FOO.COM|~FOO.BAR.COM", "sitekeys=BAR|FOO"]); 291 compareFilter(test, "@@bla$match-case,script,other,third-party,domain=foo.com| bar.com|~bar.foo.com|~foo.bar.com,csp=c s p,sitekey=foo|bar", ["type=whitelist", "text=@@bla$match-case,script,other,third-party,domain=foo.com|bar.com|~bar.foo .com|~foo.bar.com,csp=c s p,sitekey=foo|bar", "regexp=bla", "matchCase=true", "c ontentType=" + (t.SCRIPT | t.OTHER | t.CSP), "thirdParty=true", "domains=BAR.COM |FOO.COM|~BAR.FOO.COM|~FOO.BAR.COM", "sitekeys=BAR|FOO"]);
292 compareFilter(test, "@@bla$match-case,script,other,third-party,domain=foo.com| bar.com|~bar.foo.com|~foo.bar.com,sitekey=foo|bar", ["type=whitelist", "text=@@b la$match-case,script,other,third-party,domain=foo.com|bar.com|~bar.foo.com|~foo. bar.com,sitekey=foo|bar", "regexp=bla", "matchCase=true", "contentType=" + (t.SC RIPT | t.OTHER), "thirdParty=true", "domains=BAR.COM|FOO.COM|~BAR.FOO.COM|~FOO.B AR.COM", "sitekeys=BAR|FOO"]); 292 compareFilter(test, "@@bla$match-case,script,other,third-party,domain=foo.com| bar.com|~bar.foo.com|~foo.bar.com,sitekey=foo|bar", ["type=whitelist", "text=@@b la$match-case,script,other,third-party,domain=foo.com|bar.com|~bar.foo.com|~foo. bar.com,sitekey=foo|bar", "regexp=bla", "matchCase=true", "contentType=" + (t.SC RIPT | t.OTHER), "thirdParty=true", "domains=BAR.COM|FOO.COM|~BAR.FOO.COM|~FOO.B AR.COM", "sitekeys=BAR|FOO"]);
293 293
294 // background and image should be the same for backwards compatibility 294 // background and image should be the same for backwards compatibility
295 compareFilter(test, "bla$image", ["type=filterlist", "text=bla$image", "regexp =bla", "contentType=" + (t.IMAGE)]); 295 compareFilter(test, "bla$image", ["type=filterlist", "text=bla$image", "regexp =bla", "contentType=" + (t.IMAGE)]);
296 compareFilter(test, "bla$background", ["type=filterlist", "text=bla$background ", "regexp=bla", "contentType=" + (t.IMAGE)]); 296 compareFilter(test, "bla$background", ["type=filterlist", "text=bla$background ", "regexp=bla", "contentType=" + (t.IMAGE)]);
297 compareFilter(test, "bla$~image", ["type=filterlist", "text=bla$~image", "rege xp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]); 297 compareFilter(test, "bla$~image", ["type=filterlist", "text=bla$~image", "rege xp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]);
298 compareFilter(test, "bla$~background", ["type=filterlist", "text=bla$~backgrou nd", "regexp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]); 298 compareFilter(test, "bla$~background", ["type=filterlist", "text=bla$~backgrou nd", "regexp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]);
299 299
(...skipping 10 matching lines...) Expand all
310 compareFilter(test, "@@bla$~script,~other,donottrack", ["type=invalid", "text= @@bla$~script,~other,donottrack", "reason=filter_unknown_option"]); 310 compareFilter(test, "@@bla$~script,~other,donottrack", ["type=invalid", "text= @@bla$~script,~other,donottrack", "reason=filter_unknown_option"]);
311 compareFilter(test, "@@bla$~script,~other,~donottrack", ["type=invalid", "text =@@bla$~script,~other,~donottrack", "reason=filter_unknown_option"]); 311 compareFilter(test, "@@bla$~script,~other,~donottrack", ["type=invalid", "text =@@bla$~script,~other,~donottrack", "reason=filter_unknown_option"]);
312 compareFilter(test, "@@bla$donottrack", ["type=invalid", "text=@@bla$donottrac k", "reason=filter_unknown_option"]); 312 compareFilter(test, "@@bla$donottrack", ["type=invalid", "text=@@bla$donottrac k", "reason=filter_unknown_option"]);
313 compareFilter(test, "@@bla$foobar", ["type=invalid", "text=@@bla$foobar", "rea son=filter_unknown_option"]); 313 compareFilter(test, "@@bla$foobar", ["type=invalid", "text=@@bla$foobar", "rea son=filter_unknown_option"]);
314 compareFilter(test, "@@bla$image,foobar", ["type=invalid", "text=@@bla$image,f oobar", "reason=filter_unknown_option"]); 314 compareFilter(test, "@@bla$image,foobar", ["type=invalid", "text=@@bla$image,f oobar", "reason=filter_unknown_option"]);
315 compareFilter(test, "@@bla$foobar,image", ["type=invalid", "text=@@bla$foobar, image", "reason=filter_unknown_option"]); 315 compareFilter(test, "@@bla$foobar,image", ["type=invalid", "text=@@bla$foobar, image", "reason=filter_unknown_option"]);
316 316
317 compareFilter(test, "bla$csp=report-uri", ["type=invalid", "text=bla$csp=repor t-uri", "reason=filter_invalid_csp"]); 317 compareFilter(test, "bla$csp=report-uri", ["type=invalid", "text=bla$csp=repor t-uri", "reason=filter_invalid_csp"]);
318 compareFilter(test, "bla$csp=foo,csp=report-to", ["type=invalid", "text=bla$cs p=foo,csp=report-to", "reason=filter_invalid_csp"]); 318 compareFilter(test, "bla$csp=foo,csp=report-to", ["type=invalid", "text=bla$cs p=foo,csp=report-to", "reason=filter_invalid_csp"]);
319 compareFilter(test, "bla$csp=foo,csp=referrer foo", ["type=invalid", "text=bla $csp=foo,csp=referrer foo", "reason=filter_invalid_csp"]); 319 compareFilter(test, "bla$csp=foo,csp=referrer foo", ["type=invalid", "text=bla $csp=foo,csp=referrer foo", "reason=filter_invalid_csp"]);
320 compareFilter(test, "bla$csp=foo,csp=base-uri", ["type=invalid", "text=bla$csp =foo,csp=base-uri", "reason=filter_invalid_csp"]);
321 compareFilter(test, "bla$csp=foo,csp=upgrade-insecure-requests", ["type=invali d", "text=bla$csp=foo,csp=upgrade-insecure-requests", "reason=filter_invalid_csp "]);
320 compareFilter(test, "bla$csp=foo,csp=ReFeRReR", ["type=invalid", "text=bla$csp =foo,csp=ReFeRReR", "reason=filter_invalid_csp"]); 322 compareFilter(test, "bla$csp=foo,csp=ReFeRReR", ["type=invalid", "text=bla$csp =foo,csp=ReFeRReR", "reason=filter_invalid_csp"]);
321 323
322 test.done(); 324 test.done();
323 }; 325 };
324 326
325 exports.testElementHidingRules = function(test) 327 exports.testElementHidingRules = function(test)
326 { 328 {
327 compareFilter(test, "##ddd", ["type=elemhide", "text=##ddd", "selector=ddd"]); 329 compareFilter(test, "##ddd", ["type=elemhide", "text=##ddd", "selector=ddd"]);
328 compareFilter(test, "##body > div:first-child", ["type=elemhide", "text=##body > div:first-child", "selector=body > div:first-child"]); 330 compareFilter(test, "##body > div:first-child", ["type=elemhide", "text=##body > div:first-child", "selector=body > div:first-child"]);
329 compareFilter(test, "foo##ddd", ["type=elemhide", "text=foo##ddd", "selectorDo main=foo", "selector=ddd", "domains=FOO"]); 331 compareFilter(test, "foo##ddd", ["type=elemhide", "text=foo##ddd", "selectorDo main=foo", "selector=ddd", "domains=FOO"]);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 "text=" + normalized, 445 "text=" + normalized,
444 "csp=c s p", 446 "csp=c s p",
445 "domains=DOMAIN.COM|FOO.COM", 447 "domains=DOMAIN.COM|FOO.COM",
446 "sitekeys=FOO", 448 "sitekeys=FOO",
447 "regexp=b\\$la", 449 "regexp=b\\$la",
448 "contentType=" + t.CSP 450 "contentType=" + t.CSP
449 ] 451 ]
450 ); 452 );
451 453
452 // Some $csp edge cases 454 // Some $csp edge cases
455 test.equal(Filter.normalize("$csp= c s p"),
456 "$csp=c s p");
457 test.equal(Filter.normalize("$$csp= c s p"),
458 "$$csp=c s p");
459 test.equal(Filter.normalize("$$$csp= c s p"),
460 "$$$csp=c s p");
453 test.equal(Filter.normalize("foo?csp=b a r$csp=script-src 'self'"), 461 test.equal(Filter.normalize("foo?csp=b a r$csp=script-src 'self'"),
454 "foo?csp=bar$csp=script-src 'self'"); 462 "foo?csp=bar$csp=script-src 'self'");
455 test.equal(Filter.normalize("foo$bar=c s p = ba z,cs p = script-src 'self'"), 463 test.equal(Filter.normalize("foo$bar=c s p = ba z,cs p = script-src 'self'"),
456 "foo$bar=csp=baz,csp=script-src 'self'"); 464 "foo$bar=csp=baz,csp=script-src 'self'");
457 test.equal(Filter.normalize("foo$csp=c s p csp= ba z,cs p = script-src 'self '"), 465 test.equal(Filter.normalize("foo$csp=c s p csp= ba z,cs p = script-src 'self '"),
458 "foo$csp=c s p csp= ba z,csp=script-src 'self'"); 466 "foo$csp=c s p csp= ba z,csp=script-src 'self'");
459 test.equal(Filter.normalize("foo$csp=bar,$c sp=c s p"), 467 test.equal(Filter.normalize("foo$csp=bar,$c sp=c s p"),
460 "foo$csp=bar,$csp=c s p"); 468 "foo$csp=bar,$csp=c s p");
461 test.equal(Filter.normalize(" f o o $ bar $csp=ba r"), 469 test.equal(Filter.normalize(" f o o $ bar $csp=ba r"),
462 "foo$bar$csp=ba r"); 470 "foo$bar$csp=ba r");
471 test.equal(Filter.normalize("f $ o $ o $ csp=f o o "),
472 "f$o$o$csp=f o o");
463 test.equal(Filter.normalize("/foo$/$ csp = script-src http://example.com/?$1= 1&$2=2&$3=3"), 473 test.equal(Filter.normalize("/foo$/$ csp = script-src http://example.com/?$1= 1&$2=2&$3=3"),
464 "/foo$/$csp=script-src http://example.com/?$1=1&$2=2&$3=3"); 474 "/foo$/$csp=script-src http://example.com/?$1=1&$2=2&$3=3");
465 475
466 test.done(); 476 test.done();
467 }; 477 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld