Add more tests for PAC

This commit is contained in:
Nikolay Amiantov 2017-01-02 18:49:19 +03:00
parent 19966a9b9f
commit aec002fa29

View File

@ -125,6 +125,47 @@ def test_invalid_port():
res.resolve(QNetworkProxyQuery(QUrl("https://example.com/test")))
def test_no_function():
with pytest.raises(pac.EvalProxyError):
pac.PACResolver("")
def test_fail_eval():
with pytest.raises(pac.EvalProxyError):
pac.PACResolver("{")
@pytest.mark.parametrize("value", [
"",
"DIRECT FOO",
"PROXY",
"SOCKS",
"FOOBAR",
])
def test_fail_parse(value):
test_str_f = """
function FindProxyForURL(domain, host) {{
return "{}";
}}
"""
res = pac.PACResolver(test_str_f.format(value))
with pytest.raises(pac.ParseProxyError):
res.resolve(QNetworkProxyQuery(QUrl("https://example.com/test")))
def test_fail_return():
test_str = """
function FindProxyForURL(domain, host) {
return null;
}
"""
res = pac.PACResolver(test_str)
with pytest.raises(pac.EvalProxyError):
res.resolve(QNetworkProxyQuery(QUrl("https://example.com/test")))
# See https://github.com/The-Compiler/qutebrowser/pull/1891#issuecomment-259222615
try: