summaryrefslogtreecommitdiff
path: root/tests/unit/browser/webkit/http/test_http.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/browser/webkit/http/test_http.py')
-rw-r--r--tests/unit/browser/webkit/http/test_http.py41
1 files changed, 37 insertions, 4 deletions
diff --git a/tests/unit/browser/webkit/http/test_http.py b/tests/unit/browser/webkit/http/test_http.py
index 4da7c3986..ce1ae9419 100644
--- a/tests/unit/browser/webkit/http/test_http.py
+++ b/tests/unit/browser/webkit/http/test_http.py
@@ -17,13 +17,13 @@
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
-"""Tests for qutebrowser.browser.webkit.http.
+"""Tests for qutebrowser.browser.webkit.http."""
-Note that tests for parse_content_disposition are in their own
-test_content_disposition.py file.
-"""
+import logging
import pytest
+import hypothesis
+from hypothesis import strategies
from PyQt5.QtCore import QUrl
from qutebrowser.browser.webkit import http
@@ -44,6 +44,33 @@ def test_no_content_disposition(stubs, url, expected):
assert filename == expected
+@pytest.mark.parametrize('template', [
+ '{}',
+ 'attachment; filename="{}"',
+ 'inline; {}',
+ 'attachment; {}="foo"',
+ "attachment; filename*=iso-8859-1''{}",
+ 'attachment; filename*={}',
+])
+@hypothesis.given(strategies.text(alphabet=[chr(x) for x in range(255)]))
+def test_parse_content_disposition_hypothesis(caplog, template, stubs, s):
+ """Test parsing headers based on templates which hypothesis completes."""
+ header = template.format(s)
+ reply = stubs.FakeNetworkReply(headers={'Content-Disposition': header})
+ with caplog.at_level(logging.ERROR, 'network'):
+ http.parse_content_disposition(reply)
+
+
+@hypothesis.given(strategies.binary())
+def test_content_disposition_directly_hypothesis(s):
+ """Test rfc6266 parsing directly with binary data."""
+ try:
+ cd = http.ContentDisposition.parse(s)
+ cd.filename()
+ except (SyntaxError, UnicodeDecodeError, http.ContentDispositionError):
+ pass
+
+
@pytest.mark.parametrize('content_type, expected_mimetype, expected_rest', [
(None, None, None),
('image/example', 'image/example', None),
@@ -59,3 +86,9 @@ def test_parse_content_type(stubs, content_type, expected_mimetype,
mimetype, rest = http.parse_content_type(reply)
assert mimetype == expected_mimetype
assert rest == expected_rest
+
+
+@hypothesis.given(strategies.text())
+def test_parse_content_type_hypothesis(stubs, s):
+ reply = stubs.FakeNetworkReply(headers={'Content-Type': s})
+ http.parse_content_type(reply)