From 673ed5b45e92be8919b29ee033770913dc7c0ba9 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Wed, 24 May 2017 17:22:59 +0200 Subject: pathod: properly verify certificate in tests --- test/pathod/test_test.py | 41 ++++++++++++----------------------------- test/pathod/tservers.py | 3 ++- 2 files changed, 14 insertions(+), 30 deletions(-) (limited to 'test/pathod') diff --git a/test/pathod/test_test.py b/test/pathod/test_test.py index 40f45f53..30d0a473 100644 --- a/test/pathod/test_test.py +++ b/test/pathod/test_test.py @@ -1,15 +1,10 @@ -import logging +import os import requests import pytest -from pathod import test - from mitmproxy.test import tutils - -import requests.packages.urllib3 - -requests.packages.urllib3.disable_warnings() -logging.disable(logging.CRITICAL) +from pathod import test +from pathod.pathod import SSLOptions, CA_CERT_NAME class TestDaemonManual: @@ -22,29 +17,17 @@ class TestDaemonManual: with pytest.raises(requests.ConnectionError): requests.get("http://localhost:%s/p/202:da" % d.port) - def test_startstop_ssl(self): - d = test.Daemon(ssl=True) - rsp = requests.get( - "https://localhost:%s/p/202:da" % - d.port, - verify=False) - 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 + @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=ssloptions) + d = test.Daemon(ssl=True, ssloptions=ssloptions) rsp = requests.get( - "https://localhost:%s/p/202:da" % - d.port, - verify=False) + "https://localhost:%s/p/202:da" % d.port, + verify=os.path.join(d.thread.server.ssloptions.confdir, CA_CERT_NAME)) assert rsp.ok assert rsp.status_code == 202 d.shutdown() diff --git a/test/pathod/tservers.py b/test/pathod/tservers.py index fab09288..3dc26311 100644 --- a/test/pathod/tservers.py +++ b/test/pathod/tservers.py @@ -13,6 +13,7 @@ from pathod import language from pathod import pathoc from pathod import pathod from pathod import test +from pathod.pathod import CA_CERT_NAME def treader(bytes): @@ -72,7 +73,7 @@ class DaemonTests: self.d.port, path ), - verify=False, + verify=os.path.join(self.d.thread.server.ssloptions.confdir, CA_CERT_NAME), params=params ) return resp -- cgit v1.2.3 From cfed4432a0d8daf335fe0891ac55e520bac580c0 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Wed, 24 May 2017 17:25:12 +0200 Subject: pathod: fix leaking fds --- test/pathod/language/test_generators.py | 12 +++++------- test/pathod/test_test.py | 3 +-- test/pathod/tservers.py | 1 + 3 files changed, 7 insertions(+), 9 deletions(-) (limited to 'test/pathod') diff --git a/test/pathod/language/test_generators.py b/test/pathod/language/test_generators.py index 6a67ab72..5e64c726 100644 --- a/test/pathod/language/test_generators.py +++ b/test/pathod/language/test_generators.py @@ -14,16 +14,14 @@ def test_randomgenerator(): def test_filegenerator(tmpdir): f = tmpdir.join("foo") - f.write(b"x" * 10000) + f.write(b"abcdefghijklmnopqrstuvwxyz" * 1000) g = generators.FileGenerator(str(f)) - assert len(g) == 10000 - assert g[0] == b"x" - assert g[-1] == b"x" - assert g[0:5] == b"xxxxx" + assert len(g) == 26000 + assert g[0] == b"a" + assert g[2:7] == b"cdefg" assert len(g[1:10]) == 9 - assert len(g[10000:10001]) == 0 + assert len(g[26000:26001]) == 0 assert repr(g) - g.close() def test_transform_generator(): diff --git a/test/pathod/test_test.py b/test/pathod/test_test.py index 30d0a473..d51a2c7a 100644 --- a/test/pathod/test_test.py +++ b/test/pathod/test_test.py @@ -2,7 +2,6 @@ import os import requests import pytest -from mitmproxy.test import tutils from pathod import test from pathod.pathod import SSLOptions, CA_CERT_NAME @@ -27,7 +26,7 @@ class TestDaemonManual: d = test.Daemon(ssl=True, ssloptions=ssloptions) rsp = requests.get( "https://localhost:%s/p/202:da" % d.port, - verify=os.path.join(d.thread.server.ssloptions.confdir, CA_CERT_NAME)) + 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() diff --git a/test/pathod/tservers.py b/test/pathod/tservers.py index 3dc26311..a7c92964 100644 --- a/test/pathod/tservers.py +++ b/test/pathod/tservers.py @@ -1,3 +1,4 @@ +import os import tempfile import re import shutil -- cgit v1.2.3