diff options
author | Maximilian Hils <git@maximilianhils.com> | 2017-03-08 00:16:49 +0100 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2017-03-08 00:18:34 +0100 |
commit | 8707928b16c3904249309b6c81244359860cf897 (patch) | |
tree | c97fe6c7e90c792cad414187ffbcf73e48b7b459 /test | |
parent | f0d6237a965f28a9acb3d8249e0e86185788b6c6 (diff) | |
download | mitmproxy-8707928b16c3904249309b6c81244359860cf897.tar.gz mitmproxy-8707928b16c3904249309b6c81244359860cf897.tar.bz2 mitmproxy-8707928b16c3904249309b6c81244359860cf897.zip |
unify server spec parsing
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/net/test_server_spec.py | 32 | ||||
-rw-r--r-- | test/mitmproxy/proxy/test_config.py | 21 |
2 files changed, 33 insertions, 20 deletions
diff --git a/test/mitmproxy/net/test_server_spec.py b/test/mitmproxy/net/test_server_spec.py new file mode 100644 index 00000000..095ad519 --- /dev/null +++ b/test/mitmproxy/net/test_server_spec.py @@ -0,0 +1,32 @@ +import pytest + +from mitmproxy.net import server_spec + + +def test_parse(): + assert server_spec.parse("example.com") == ("https", ("example.com", 443)) + assert server_spec.parse("example.com") == ("https", ("example.com", 443)) + assert server_spec.parse("http://example.com") == ("http", ("example.com", 80)) + assert server_spec.parse("http://127.0.0.1") == ("http", ("127.0.0.1", 80)) + assert server_spec.parse("http://[::1]") == ("http", ("::1", 80)) + assert server_spec.parse("http://[::1]/") == ("http", ("::1", 80)) + assert server_spec.parse("https://[::1]/") == ("https", ("::1", 443)) + assert server_spec.parse("http://[::1]:8080") == ("http", ("::1", 8080)) + + with pytest.raises(ValueError, match="Invalid server specification"): + server_spec.parse(":") + + with pytest.raises(ValueError, match="Invalid server scheme"): + server_spec.parse("ftp://example.com") + + with pytest.raises(ValueError, match="Invalid hostname"): + server_spec.parse("$$$") + + with pytest.raises(ValueError, match="Invalid port"): + server_spec.parse("example.com:999999") + + +def test_parse_with_mode(): + assert server_spec.parse_with_mode("m:example.com") == ("m", ("https", ("example.com", 443))) + with pytest.raises(ValueError): + server_spec.parse_with_mode("moo") diff --git a/test/mitmproxy/proxy/test_config.py b/test/mitmproxy/proxy/test_config.py index 4272d952..777ab4dd 100644 --- a/test/mitmproxy/proxy/test_config.py +++ b/test/mitmproxy/proxy/test_config.py @@ -1,20 +1 @@ -import pytest -from mitmproxy.proxy import config - - -def test_parse_server_spec(): - with pytest.raises(Exception, match="Invalid server specification"): - config.parse_server_spec("") - assert config.parse_server_spec("http://foo.com:88") == ( - "http", ("foo.com", 88) - ) - assert config.parse_server_spec("http://foo.com") == ( - "http", ("foo.com", 80) - ) - assert config.parse_server_spec("https://foo.com") == ( - "https", ("foo.com", 443) - ) - with pytest.raises(Exception, match="Invalid server specification"): - config.parse_server_spec("foo.com") - with pytest.raises(Exception, match="Invalid server specification"): - config.parse_server_spec("http://") +# TODO: write tests |