mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
pathod: properly verify certificate in tests
This commit is contained in:
parent
6214c6e185
commit
673ed5b45e
@ -1,15 +1,10 @@
|
|||||||
import logging
|
import os
|
||||||
import requests
|
import requests
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pathod import test
|
|
||||||
|
|
||||||
from mitmproxy.test import tutils
|
from mitmproxy.test import tutils
|
||||||
|
from pathod import test
|
||||||
import requests.packages.urllib3
|
from pathod.pathod import SSLOptions, CA_CERT_NAME
|
||||||
|
|
||||||
requests.packages.urllib3.disable_warnings()
|
|
||||||
logging.disable(logging.CRITICAL)
|
|
||||||
|
|
||||||
|
|
||||||
class TestDaemonManual:
|
class TestDaemonManual:
|
||||||
@ -22,29 +17,17 @@ class TestDaemonManual:
|
|||||||
with pytest.raises(requests.ConnectionError):
|
with pytest.raises(requests.ConnectionError):
|
||||||
requests.get("http://localhost:%s/p/202:da" % d.port)
|
requests.get("http://localhost:%s/p/202:da" % d.port)
|
||||||
|
|
||||||
def test_startstop_ssl(self):
|
@pytest.mark.parametrize('not_after_connect', [True, False])
|
||||||
d = test.Daemon(ssl=True)
|
def test_startstop_ssl(self, not_after_connect):
|
||||||
rsp = requests.get(
|
ssloptions = SSLOptions(
|
||||||
"https://localhost:%s/p/202:da" %
|
cn=b'localhost',
|
||||||
d.port,
|
sans=[b'localhost', b'127.0.0.1'],
|
||||||
verify=False)
|
not_after_connect=not_after_connect,
|
||||||
assert rsp.ok
|
|
||||||
assert rsp.status_code == 202
|
|
||||||
d.shutdown()
|
|
||||||
with pytest.raises(requests.ConnectionError):
|
|
||||||
requests.get("http://localhost:%s/p/202:da" % d.port)
|
|
||||||
|
|
||||||
def test_startstop_ssl_explicit(self):
|
|
||||||
ssloptions = dict(
|
|
||||||
certfile=tutils.test_data.path("pathod/data/testkey.pem"),
|
|
||||||
cacert=tutils.test_data.path("pathod/data/testkey.pem"),
|
|
||||||
ssl_after_connect=False
|
|
||||||
)
|
)
|
||||||
d = test.Daemon(ssl=ssloptions)
|
d = test.Daemon(ssl=True, ssloptions=ssloptions)
|
||||||
rsp = requests.get(
|
rsp = requests.get(
|
||||||
"https://localhost:%s/p/202:da" %
|
"https://localhost:%s/p/202:da" % d.port,
|
||||||
d.port,
|
verify=os.path.join(d.thread.server.ssloptions.confdir, CA_CERT_NAME))
|
||||||
verify=False)
|
|
||||||
assert rsp.ok
|
assert rsp.ok
|
||||||
assert rsp.status_code == 202
|
assert rsp.status_code == 202
|
||||||
d.shutdown()
|
d.shutdown()
|
||||||
|
@ -13,6 +13,7 @@ from pathod import language
|
|||||||
from pathod import pathoc
|
from pathod import pathoc
|
||||||
from pathod import pathod
|
from pathod import pathod
|
||||||
from pathod import test
|
from pathod import test
|
||||||
|
from pathod.pathod import CA_CERT_NAME
|
||||||
|
|
||||||
|
|
||||||
def treader(bytes):
|
def treader(bytes):
|
||||||
@ -72,7 +73,7 @@ class DaemonTests:
|
|||||||
self.d.port,
|
self.d.port,
|
||||||
path
|
path
|
||||||
),
|
),
|
||||||
verify=False,
|
verify=os.path.join(self.d.thread.server.ssloptions.confdir, CA_CERT_NAME),
|
||||||
params=params
|
params=params
|
||||||
)
|
)
|
||||||
return resp
|
return resp
|
||||||
|
Loading…
Reference in New Issue
Block a user