| OLD | NEW |
| 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-2016 Eyeo GmbH | 2 # Copyright (C) 2006-2016 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 # Fragment that has a broken include. | 58 # Fragment that has a broken include. |
| 59 incdir.join('broken.txt').write('%include missing.txt%') | 59 incdir.join('broken.txt').write('%include missing.txt%') |
| 60 # Fragment that includes itself. | 60 # Fragment that includes itself. |
| 61 incdir.join('circular.txt').write('%include circular.txt%') | 61 incdir.join('circular.txt').write('%include circular.txt%') |
| 62 return rootdir | 62 return rootdir |
| 63 | 63 |
| 64 | 64 |
| 65 @pytest.fixture | 65 @pytest.fixture |
| 66 def webserver_port(tmpdir, request): | 66 def webserver_port(tmpdir, request): |
| 67 """Serve fragments via HTTP on a random port (return the port number).""" | 67 """Serve fragments via HTTP on a random port (return the port number).""" |
| 68 Handler = SimpleHTTPServer.SimpleHTTPRequestHandler | 68 handler = SimpleHTTPServer.SimpleHTTPRequestHandler |
| 69 httpd = SocketServer.TCPServer(("", 0), Handler) | 69 httpd = SocketServer.TCPServer(('', 0), handler) |
| 70 port = httpd.socket.getsockname()[1] | 70 port = httpd.socket.getsockname()[1] |
| 71 # Create some files to serve. | 71 # Create some files to serve. |
| 72 webroot = tmpdir.join('webroot') | 72 webroot = tmpdir.join('webroot') |
| 73 webroot.mkdir() | 73 webroot.mkdir() |
| 74 webroot.join('inc.txt').write('Web \u1234'.encode('utf-8'), mode='wb') | 74 webroot.join('inc.txt').write('Web \u1234'.encode('utf-8'), mode='wb') |
| 75 webroot.join('metainc.txt').write( | 75 webroot.join('metainc.txt').write( |
| 76 '%include http://localhost:{}/inc.txt%'.format(port)) | 76 '%include http://localhost:{}/inc.txt%'.format(port)) |
| 77 # Change to this directory and start the webserver in another thread. | 77 # Change to this directory and start the webserver in another thread. |
| 78 os.chdir(str(webroot)) | 78 os.chdir(str(webroot)) |
| 79 thread = threading.Thread(target=httpd.serve_forever) | 79 thread = threading.Thread(target=httpd.serve_forever) |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 183 |
| 184 @pytest.mark.slowtest | 184 @pytest.mark.slowtest |
| 185 def test_failed_web_include(rootdir, dstfile, webserver_port): | 185 def test_failed_web_include(rootdir, dstfile, webserver_port): |
| 186 url = 'http://localhost:{}/missing.txt'.format(webserver_port) | 186 url = 'http://localhost:{}/missing.txt'.format(webserver_port) |
| 187 webinc = rootdir.join('webinc.txt') | 187 webinc = rootdir.join('webinc.txt') |
| 188 webinc.write('[Adblock]\n%include {}%'.format(url)) | 188 webinc.write('[Adblock]\n%include {}%'.format(url)) |
| 189 code, err = run_script(str(webinc), str(dstfile)) | 189 code, err = run_script(str(webinc), str(dstfile)) |
| 190 assert code == 1 | 190 assert code == 1 |
| 191 assert err.startswith( | 191 assert err.startswith( |
| 192 "HTTP 404 Not found: '{0}' when including '{0}'".format(url)) | 192 "HTTP 404 Not found: '{0}' when including '{0}'".format(url)) |
| OLD | NEW |