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

Delta Between Two Patch Sets: sitescripts/subscriptions/test/test_updateMalwareDomainsList.py

Issue 29821558: Issue #6707 - Make the generated malware domain filter list encode domains as Punycode (Closed)
Left Patch Set: Created July 3, 2018, 3:50 p.m.
Right Patch Set: Removed uncessary codecs call from updateMalwareDomains.py Created July 9, 2018, 1:08 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 | « sitescripts/subscriptions/bin/updateMalwareDomainsList.py ('k') | tox.ini » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 @pytest.fixture(autouse=True) 52 @pytest.fixture(autouse=True)
53 def urlopen(mocker): 53 def urlopen(mocker):
54 """Mock urlopen function""" 54 """Mock urlopen function"""
55 real_urlopen = urllib2.urlopen 55 real_urlopen = urllib2.urlopen
56 56
57 def mock_urlopen(url): 57 def mock_urlopen(url):
58 if url.startswith('good'): 58 if url.startswith('good'):
59 zf_data = io.BytesIO() 59 zf_data = io.BytesIO()
60 with zipfile.ZipFile(zf_data, 'w') as zf: 60 with zipfile.ZipFile(zf_data, 'w') as zf:
61 idna_url = 'xn--xhq02ykwbp4a.cn\n' 61 idna_urls = ['xn--xhq02ykwbp4a.cn', 'xn--fiq80yua78t.tw']
Vasily Kuznetsov 2018/07/03 16:01:52 I think it would make sense to have 2 domains in t
Tudor Avram 2018/07/06 11:53:16 Done.
62 zf.writestr('justdomains', idna_url) 62 zf.writestr('justdomains', '\n'.join(idna_urls) + '\n')
63 return io.BytesIO(zf_data.getvalue()) 63 return io.BytesIO(zf_data.getvalue())
64 if url.startswith('bad'): 64 if url.startswith('bad'):
65 raise urllib2.HTTPError('Bad', '42', 'No good', [], None) 65 raise urllib2.HTTPError('Bad', '42', 'No good', [], None)
66 if url.startswith('ugly'): 66 if url.startswith('ugly'):
67 raise urllib2.URLError('Ugly') 67 raise urllib2.URLError('Ugly')
68 return real_urlopen(url) 68 return real_urlopen(url)
69 69
70 mocker.patch('urllib2.urlopen', mock_urlopen) 70 mocker.patch('urllib2.urlopen', mock_urlopen)
71 71
72 72
73 def test_good(md_repo): 73 def test_good(md_repo):
74 main() 74 main()
75 subprocess.check_call(['hg', 'up'], cwd=md_repo.strpath) 75 subprocess.check_call(['hg', 'up'], cwd=md_repo.strpath)
76 result = md_repo.join('malwaredomains_full.txt').read() 76 result = md_repo.join('malwaredomains_full.txt').read()
77 assert '.cn-w48dx81cufdl6b' in result 77 puny_urls = ['xn--xhq02ykwbp4a.cn', 'xn--fiq80yua78t.tw']
78 for url in puny_urls:
79 assert url in result
78 80
79 81
80 def test_bad(md_repo, config): 82 def test_bad(md_repo, config):
81 config.set(CONF_SECTION, 'malwaredomains_mirrors', 'bad') 83 config.set(CONF_SECTION, 'malwaredomains_mirrors', 'bad')
82 try: 84 try:
83 main() 85 main()
84 except SystemExit as exc: 86 except SystemExit as exc:
85 err_lines = str(exc).splitlines() 87 err_lines = str(exc).splitlines()
86 assert len(err_lines) == 3 88 assert len(err_lines) == 3
87 assert 'Failed to fetch bad/files/justdomains.zip' in err_lines[2] 89 assert 'Failed to fetch bad/files/justdomains.zip' in err_lines[2]
88 assert '42: No good' in err_lines[2] 90 assert '42: No good' in err_lines[2]
89 91
90 92
91 def test_ugly(md_repo, config): 93 def test_ugly(md_repo, config):
92 config.set(CONF_SECTION, 'malwaredomains_mirrors', 'bad\nugly') 94 config.set(CONF_SECTION, 'malwaredomains_mirrors', 'bad\nugly')
93 try: 95 try:
94 main() 96 main()
95 except SystemExit as exc: 97 except SystemExit as exc:
96 err_lines = str(exc).splitlines() 98 err_lines = str(exc).splitlines()
97 assert len(err_lines) == 4 99 assert len(err_lines) == 4
98 assert 'Failed to fetch bad/files/justdomains.zip' in err_lines[2] 100 assert 'Failed to fetch bad/files/justdomains.zip' in err_lines[2]
99 assert 'Failed to fetch ugly/files/justdomains.zip' in err_lines[3] 101 assert 'Failed to fetch ugly/files/justdomains.zip' in err_lines[3]
100 assert 'Ugly' in err_lines[3] 102 assert 'Ugly' in err_lines[3]
LEFTRIGHT

Powered by Google App Engine
This is Rietveld