mitmproxy/test/pathod/test_test.py

35 lines
1.2 KiB
Python
Raw Normal View History

import os
import requests
import pytest
from pathod import test
from pathod.pathod import SSLOptions, CA_CERT_NAME
2014-10-24 01:01:34 +00:00
2012-06-09 03:08:51 +00:00
class TestDaemonManual:
2015-06-18 16:12:11 +00:00
def test_simple(self):
2012-07-30 08:58:59 +00:00
with test.Daemon() as d:
2015-05-30 00:03:13 +00:00
rsp = requests.get("http://localhost:%s/p/202:da" % d.port)
2012-07-30 08:58:59 +00:00
assert rsp.ok
assert rsp.status_code == 202
with pytest.raises(requests.ConnectionError):
2015-12-03 17:45:37 +00:00
requests.get("http://localhost:%s/p/202:da" % d.port)
@pytest.mark.parametrize('not_after_connect', [True, False])
def test_startstop_ssl(self, not_after_connect):
ssloptions = SSLOptions(
cn=b'localhost',
sans=[b'localhost', b'127.0.0.1'],
not_after_connect=not_after_connect,
)
d = test.Daemon(ssl=True, ssloptions=ssloptions)
2015-05-30 00:03:13 +00:00
rsp = requests.get(
"https://localhost:%s/p/202:da" % d.port,
2017-05-24 15:25:12 +00:00
verify=os.path.expanduser(os.path.join(d.thread.server.ssloptions.confdir, CA_CERT_NAME)))
assert rsp.ok
assert rsp.status_code == 202
d.shutdown()
with pytest.raises(requests.ConnectionError):
2015-12-03 17:45:37 +00:00
requests.get("http://localhost:%s/p/202:da" % d.port)