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: New approach, added more unit tests Created March 14, 2018, 1:41 p.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
300 compareFilter(test, "@@bla$~script,~other", ["type=whitelist", "text=@@bla$~sc ript,~other", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHE R))]); 300 compareFilter(test, "@@bla$~script,~other", ["type=whitelist", "text=@@bla$~sc ript,~other", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHE R))]);
301 compareFilter(test, "@@http://bla$~script,~other", ["type=whitelist", "text=@@ http://bla$~script,~other", "regexp=http\\:\\/\\/bla", "contentType=" + (default Types & ~(t.SCRIPT | t.OTHER))]); 301 compareFilter(test, "@@http://bla$~script,~other", ["type=whitelist", "text=@@ http://bla$~script,~other", "regexp=http\\:\\/\\/bla", "contentType=" + (default Types & ~(t.SCRIPT | t.OTHER))]);
302 compareFilter(test, "@@|ftp://bla$~script,~other", ["type=whitelist", "text=@@ |ftp://bla$~script,~other", "regexp=^ftp\\:\\/\\/bla", "contentType=" + (default Types & ~(t.SCRIPT | t.OTHER))]); 302 compareFilter(test, "@@|ftp://bla$~script,~other", ["type=whitelist", "text=@@ |ftp://bla$~script,~other", "regexp=^ftp\\:\\/\\/bla", "contentType=" + (default Types & ~(t.SCRIPT | t.OTHER))]);
303 compareFilter(test, "@@bla$~script,~other,document", ["type=whitelist", "text= @@bla$~script,~other,document", "regexp=bla", "contentType=" + (defaultTypes & ~ (t.SCRIPT | t.OTHER) | t.DOCUMENT)]); 303 compareFilter(test, "@@bla$~script,~other,document", ["type=whitelist", "text= @@bla$~script,~other,document", "regexp=bla", "contentType=" + (defaultTypes & ~ (t.SCRIPT | t.OTHER) | t.DOCUMENT)]);
304 compareFilter(test, "@@bla$~script,~other,~document", ["type=whitelist", "text =@@bla$~script,~other,~document", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER))]); 304 compareFilter(test, "@@bla$~script,~other,~document", ["type=whitelist", "text =@@bla$~script,~other,~document", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER))]);
305 compareFilter(test, "@@bla$document", ["type=whitelist", "text=@@bla$document" , "regexp=bla", "contentType=" + t.DOCUMENT]); 305 compareFilter(test, "@@bla$document", ["type=whitelist", "text=@@bla$document" , "regexp=bla", "contentType=" + t.DOCUMENT]);
306 compareFilter(test, "@@bla$~script,~other,elemhide", ["type=whitelist", "text= @@bla$~script,~other,elemhide", "regexp=bla", "contentType=" + (defaultTypes & ~ (t.SCRIPT | t.OTHER) | t.ELEMHIDE)]); 306 compareFilter(test, "@@bla$~script,~other,elemhide", ["type=whitelist", "text= @@bla$~script,~other,elemhide", "regexp=bla", "contentType=" + (defaultTypes & ~ (t.SCRIPT | t.OTHER) | t.ELEMHIDE)]);
307 compareFilter(test, "@@bla$~script,~other,~elemhide", ["type=whitelist", "text =@@bla$~script,~other,~elemhide", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER))]); 307 compareFilter(test, "@@bla$~script,~other,~elemhide", ["type=whitelist", "text =@@bla$~script,~other,~elemhide", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER))]);
308 compareFilter(test, "@@bla$elemhide", ["type=whitelist", "text=@@bla$elemhide" , "regexp=bla", "contentType=" + t.ELEMHIDE]); 308 compareFilter(test, "@@bla$elemhide", ["type=whitelist", "text=@@bla$elemhide" , "regexp=bla", "contentType=" + t.ELEMHIDE]);
309 309
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"]);
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 "]);
322 compareFilter(test, "bla$csp=foo,csp=ReFeRReR", ["type=invalid", "text=bla$csp =foo,csp=ReFeRReR", "reason=filter_invalid_csp"]);
319 323
320 test.done(); 324 test.done();
321 }; 325 };
322 326
323 exports.testElementHidingRules = function(test) 327 exports.testElementHidingRules = function(test)
324 { 328 {
325 compareFilter(test, "##ddd", ["type=elemhide", "text=##ddd", "selector=ddd"]); 329 compareFilter(test, "##ddd", ["type=elemhide", "text=##ddd", "selector=ddd"]);
326 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"]);
327 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"]);
328 compareFilter(test, "foo,bar##ddd", ["type=elemhide", "text=foo,bar##ddd", "se lectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO"]); 332 compareFilter(test, "foo,bar##ddd", ["type=elemhide", "text=foo,bar##ddd", "se lectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO"]);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 "text=" + normalized, 445 "text=" + normalized,
442 "csp=c s p", 446 "csp=c s p",
443 "domains=DOMAIN.COM|FOO.COM", 447 "domains=DOMAIN.COM|FOO.COM",
444 "sitekeys=FOO", 448 "sitekeys=FOO",
445 "regexp=b\\$la", 449 "regexp=b\\$la",
446 "contentType=" + t.CSP 450 "contentType=" + t.CSP
447 ] 451 ]
448 ); 452 );
449 453
450 // 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");
451 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'"),
452 "foo?csp=bar$csp=script-src 'self'"); 462 "foo?csp=bar$csp=script-src 'self'");
453 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'"),
454 "foo$bar=csp=baz,csp=script-src 'self'"); 464 "foo$bar=csp=baz,csp=script-src 'self'");
455 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 '"),
456 "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'");
457 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"),
458 "foo$csp=bar,$csp=c s p"); 468 "foo$csp=bar,$csp=c s p");
459
460 test.equal(Filter.normalize(" f o o $ bar $csp=ba r"), 469 test.equal(Filter.normalize(" f o o $ bar $csp=ba r"),
461 "foo$bar$csp=ba r"); 470 "foo$bar$csp=ba r");
462 471 test.equal(Filter.normalize("f $ o $ o $ csp=f o o "),
463 test.done(); 472 "f$o$o$csp=f o o");
464 }; 473 test.equal(Filter.normalize("/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");
475
476 test.done();
477 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld