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

Side by Side Diff: tests/test_parser.py

Issue 29793573: Issue 6701 - Implement CSP support in python-abp (Closed) Base URL: https://hg.adblockplus.org/python-abp/
Patch Set: Created May 29, 2018, 4:54 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« abp/filters/parser.py ('K') | « abp/filters/parser.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This file is part of Adblock Plus <https://adblockplus.org/>, 1 # This file is part of Adblock Plus <https://adblockplus.org/>,
2 # Copyright (C) 2006-present eyeo GmbH 2 # Copyright (C) 2006-present eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 }, 60 },
61 '@@http://bla$~script,~other,sitekey=foo|bar': { 61 '@@http://bla$~script,~other,sitekey=foo|bar': {
62 'selector': {'type': ST.URL_PATTERN, 'value': 'http://bla'}, 62 'selector': {'type': ST.URL_PATTERN, 'value': 'http://bla'},
63 'action': FA.ALLOW, 63 'action': FA.ALLOW,
64 'options': [ 64 'options': [
65 (OPT.SCRIPT, False), 65 (OPT.SCRIPT, False),
66 (OPT.OTHER, False), 66 (OPT.OTHER, False),
67 (OPT.SITEKEY, ['foo', 'bar']), 67 (OPT.SITEKEY, ['foo', 'bar']),
68 ], 68 ],
69 }, 69 },
70 "||foo.com^$csp=script-src 'self' * 'unsafe-inline'": {
71 'selector': {'type': ST.URL_PATTERN, 'value': '||foo.com^'},
72 'action': FA.BLOCK,
73 'options': [
74 (OPT.CSP, "script-src 'self' * 'unsafe-inline'"),
75 ],
76 },
70 # Element hiding filters and exceptions. 77 # Element hiding filters and exceptions.
71 '##ddd': { 78 '##ddd': {
72 'selector': {'type': ST.CSS, 'value': 'ddd'}, 79 'selector': {'type': ST.CSS, 'value': 'ddd'},
73 'action': FA.HIDE, 80 'action': FA.HIDE,
74 'options': [], 81 'options': [],
75 }, 82 },
76 '#@#body > div:first-child': { 83 '#@#body > div:first-child': {
77 'selector': {'type': ST.CSS, 'value': 'body > div:first-child'}, 84 'selector': {'type': ST.CSS, 'value': 'body > div:first-child'},
78 'action': FA.SHOW, 85 'action': FA.SHOW,
79 'options': [], 86 'options': [],
(...skipping 16 matching lines...) Expand all
96 '#?#:-abp-properties(|background-image: url(data:*))': { 103 '#?#:-abp-properties(|background-image: url(data:*))': {
97 'selector': { 104 'selector': {
98 'type': ST.XCSS, 105 'type': ST.XCSS,
99 'value': ':-abp-properties(|background-image: url(data:*))', 106 'value': ':-abp-properties(|background-image: url(data:*))',
100 }, 107 },
101 'options': [], 108 'options': [],
102 }, 109 },
103 }.items()) 110 }.items())
104 def test_parse_filters(filter_text, expected): 111 def test_parse_filters(filter_text, expected):
105 """Parametric test for filter parsing.""" 112 """Parametric test for filter parsing."""
113 # from pdb import set_trace; set_trace()
Vasily Kuznetsov 2018/05/30 19:49:26 ;)
rhowell 2018/06/07 18:16:55 oops! Done. :)
106 parsed = parse_line(filter_text) 114 parsed = parse_line(filter_text)
107 assert parsed.type == 'filter' 115 assert parsed.type == 'filter'
108 assert parsed.text == filter_text 116 assert parsed.text == filter_text
109 for attribute, expected_value in expected.items(): 117 for attribute, expected_value in expected.items():
110 assert getattr(parsed, attribute) == expected_value 118 assert getattr(parsed, attribute) == expected_value
111 119
112 120
113 def test_parse_comment(): 121 def test_parse_comment():
114 line = parse_line('! Block foo') 122 line = parse_line('! Block foo')
115 assert line.type == 'comment' 123 assert line.type == 'comment'
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 def test_exception_timing(): 166 def test_exception_timing():
159 result = parse_filterlist(['! good line', '%bad line%']) 167 result = parse_filterlist(['! good line', '%bad line%'])
160 assert next(result) == Comment('good line') 168 assert next(result) == Comment('good line')
161 with pytest.raises(ParseError): 169 with pytest.raises(ParseError):
162 next(result) 170 next(result)
163 171
164 172
165 def test_parse_line_bytes(): 173 def test_parse_line_bytes():
166 line = parse_line(b'! \xc3\xbc') 174 line = parse_line(b'! \xc3\xbc')
167 assert line.text == '\xfc' 175 assert line.text == '\xfc'
OLDNEW
« abp/filters/parser.py ('K') | « abp/filters/parser.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld