mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
Merge pull request #2389 from ujjwal96/test-coverage
Tests for Proxy config
This commit is contained in:
commit
93d37e29c3
@ -22,7 +22,6 @@ exclude_lines =
|
|||||||
[tool:full_coverage]
|
[tool:full_coverage]
|
||||||
exclude =
|
exclude =
|
||||||
mitmproxy/proxy/protocol/
|
mitmproxy/proxy/protocol/
|
||||||
mitmproxy/proxy/config.py
|
|
||||||
mitmproxy/proxy/root_context.py
|
mitmproxy/proxy/root_context.py
|
||||||
mitmproxy/proxy/server.py
|
mitmproxy/proxy/server.py
|
||||||
mitmproxy/tools/
|
mitmproxy/tools/
|
||||||
|
@ -1 +1,38 @@
|
|||||||
# TODO: write tests
|
import pytest
|
||||||
|
|
||||||
|
from mitmproxy import options
|
||||||
|
from mitmproxy import exceptions
|
||||||
|
from mitmproxy.proxy.config import ProxyConfig
|
||||||
|
from mitmproxy.test import tutils
|
||||||
|
|
||||||
|
|
||||||
|
class TestProxyConfig:
|
||||||
|
def test_upstream_cert_insecure(self):
|
||||||
|
opts = options.Options()
|
||||||
|
opts.add_upstream_certs_to_client_chain = True
|
||||||
|
with pytest.raises(exceptions.OptionsError, match="verify-upstream-cert"):
|
||||||
|
ProxyConfig(opts)
|
||||||
|
|
||||||
|
def test_invalid_cadir(self):
|
||||||
|
opts = options.Options()
|
||||||
|
opts.cadir = "foo"
|
||||||
|
with pytest.raises(exceptions.OptionsError, match="parent directory does not exist"):
|
||||||
|
ProxyConfig(opts)
|
||||||
|
|
||||||
|
def test_invalid_client_certs(self):
|
||||||
|
opts = options.Options()
|
||||||
|
opts.client_certs = "foo"
|
||||||
|
with pytest.raises(exceptions.OptionsError, match="certificate path does not exist"):
|
||||||
|
ProxyConfig(opts)
|
||||||
|
|
||||||
|
def test_valid_client_certs(self):
|
||||||
|
opts = options.Options()
|
||||||
|
opts.client_certs = tutils.test_data.path("mitmproxy/data/clientcert/")
|
||||||
|
p = ProxyConfig(opts)
|
||||||
|
assert p.client_certs
|
||||||
|
|
||||||
|
def test_invalid_certificate(self):
|
||||||
|
opts = options.Options()
|
||||||
|
opts.certs = [tutils.test_data.path("mitmproxy/data/dumpfile-011")]
|
||||||
|
with pytest.raises(exceptions.OptionsError, match="Invalid certificate format"):
|
||||||
|
ProxyConfig(opts)
|
||||||
|
Loading…
Reference in New Issue
Block a user