From 7a154e1ae18f12056447ef030b2bb321cfb13111 Mon Sep 17 00:00:00 2001 From: Pedro Worcel Date: Sat, 22 Feb 2014 15:00:10 +1300 Subject: add basic backwards search --- test/test_console_contentview.py | 97 ------------------------------- test/test_console_search.py | 121 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+), 97 deletions(-) create mode 100644 test/test_console_search.py (limited to 'test') diff --git a/test/test_console_contentview.py b/test/test_console_contentview.py index 07ecf1d0..a878ad4e 100644 --- a/test/test_console_contentview.py +++ b/test/test_console_contentview.py @@ -276,100 +276,3 @@ if cv.ViewProtobuf.is_available(): def test_get_by_shortcut(): assert cv.get_by_shortcut("h") -def test_search_highlights(): - # Default text in requests is content. We will search for nt once, and - # expect the first bit to be highlighted. We will do it again and expect the - # second to be. - f = tutils.tflowview() - - f.search("nt") - text_object = tutils.get_body_line(f.last_displayed_body, 0) - assert text_object.get_text() == ('content', [(None, 2), (f.highlight_color, 2)]) - - f.search("nt") - text_object = tutils.get_body_line(f.last_displayed_body, 1) - assert text_object.get_text() == ('content', [(None, 5), (f.highlight_color, 2)]) - -def test_search_returns_useful_messages(): - f = tutils.tflowview() - - # original string is content. this string should not be in there. - response = f.search("oranges and other fruit.") - assert response == "no matches for 'oranges and other fruit.'" - -def test_search_highlights_clears_prev(): - f = tutils.tflowview(request_contents="this is string\nstring is string") - - f.search("string") - text_object = tutils.get_body_line(f.last_displayed_body, 0) - assert text_object.get_text() == ('this is string', [(None, 8), (f.highlight_color, 6)]) - - # search again, it should not be highlighted again. - f.search("string") - text_object = tutils.get_body_line(f.last_displayed_body, 0) - assert text_object.get_text() != ('this is string', [(None, 8), (f.highlight_color, 6)]) - -def test_search_highlights_multi_line(): - f = tutils.tflowview(request_contents="this is string\nstring is string") - - # should highlight the first line. - f.search("string") - text_object = tutils.get_body_line(f.last_displayed_body, 0) - assert text_object.get_text() == ('this is string', [(None, 8), (f.highlight_color, 6)]) - - # should highlight second line, first appearance of string. - f.search("string") - text_object = tutils.get_body_line(f.last_displayed_body, 1) - assert text_object.get_text() == ('string is string', [(None, 0), (f.highlight_color, 6)]) - - # should highlight third line, second appearance of string. - f.search("string") - text_object = tutils.get_body_line(f.last_displayed_body, 1) - assert text_object.get_text() == ('string is string', [(None, 10), (f.highlight_color, 6)]) - -def test_search_loops(): - f = tutils.tflowview(request_contents="this is string\nstring is string") - - # get to the end. - f.search("string") - f.search("string") - f.search("string") - - # should highlight the first line. - message = f.search("string") - text_object = tutils.get_body_line(f.last_displayed_body, 0) - assert text_object.get_text() == ('this is string', [(None, 8), (f.highlight_color, 6)]) - assert message == "search hit BOTTOM, continuing at TOP" - -def test_search_focuses(): - f = tutils.tflowview(request_contents="this is string\nstring is string") - - # should highlight the first line. - f.search("string") - - # should be focusing on the 2nd text line. - f.search("string") - text_object = tutils.get_body_line(f.last_displayed_body, 1) - assert f.last_displayed_body.focus == text_object - -def test_search_does_not_crash_on_bad(): - """ - this used to crash, kept for reference. - """ - - f = tutils.tflowview(request_contents="this is string\nstring is string\n"+("A" * cv.VIEW_CUTOFF)+"AFTERCUTOFF") - f.search("AFTERCUTOFF") - - # pretend F - f.state.add_flow_setting( - f.flow, - (f.state.view_flow_mode, "fullcontents"), - True - ) - f.master.refresh_flow(f.flow) - - # text changed, now this string will exist. can happen when user presses F - # for full text view - f.search("AFTERCUTOFF") - - diff --git a/test/test_console_search.py b/test/test_console_search.py new file mode 100644 index 00000000..7374f399 --- /dev/null +++ b/test/test_console_search.py @@ -0,0 +1,121 @@ + +import sys +import libmproxy.console.contentview as cv +from libmproxy import utils, flow, encoding +import tutils + +def test_search_highlights(): + # Default text in requests is content. We will search for nt once, and + # expect the first bit to be highlighted. We will do it again and expect the + # second to be. + f = tutils.tflowview() + + f.search("nt") + text_object = tutils.get_body_line(f.last_displayed_body, 0) + assert text_object.get_text() == ('content', [(None, 2), (f.highlight_color, 2)]) + + f.search("nt") + text_object = tutils.get_body_line(f.last_displayed_body, 1) + assert text_object.get_text() == ('content', [(None, 5), (f.highlight_color, 2)]) + +def test_search_returns_useful_messages(): + f = tutils.tflowview() + + # original string is content. this string should not be in there. + test_string = "oranges and other fruit." + response = f.search(test_string) + assert response == "no matches for '%s'" % test_string + +def test_search_highlights_clears_prev(): + f = tutils.tflowview(request_contents="this is string\nstring is string") + + f.search("string") + text_object = tutils.get_body_line(f.last_displayed_body, 0) + assert text_object.get_text() == ('this is string', [(None, 8), (f.highlight_color, 6)]) + + # search again, it should not be highlighted again. + f.search("string") + text_object = tutils.get_body_line(f.last_displayed_body, 0) + assert text_object.get_text() != ('this is string', [(None, 8), (f.highlight_color, 6)]) + +def test_search_highlights_multi_line(): + f = tutils.tflowview(request_contents="this is string\nstring is string") + + # should highlight the first line. + f.search("string") + text_object = tutils.get_body_line(f.last_displayed_body, 0) + assert text_object.get_text() == ('this is string', [(None, 8), (f.highlight_color, 6)]) + + # should highlight second line, first appearance of string. + f.search("string") + text_object = tutils.get_body_line(f.last_displayed_body, 1) + assert text_object.get_text() == ('string is string', [(None, 0), (f.highlight_color, 6)]) + + # should highlight third line, second appearance of string. + f.search("string") + text_object = tutils.get_body_line(f.last_displayed_body, 1) + print(text_object.get_text(), ('string is string', [(None, 10), (f.highlight_color, 6)])) + assert text_object.get_text() == ('string is string', [(None, 10), (f.highlight_color, 6)]) + +def test_search_loops(): + f = tutils.tflowview(request_contents="this is string\nstring is string") + + # get to the end. + f.search("string") + f.search("string") + f.search("string") + + # should highlight the first line. + message = f.search("string") + text_object = tutils.get_body_line(f.last_displayed_body, 0) + assert text_object.get_text() == ('this is string', [(None, 8), (f.highlight_color, 6)]) + assert message == "search hit BOTTOM, continuing at TOP" + +def test_search_focuses(): + f = tutils.tflowview(request_contents="this is string\nstring is string") + + # should highlight the first line. + f.search("string") + + # should be focusing on the 2nd text line. + f.search("string") + text_object = tutils.get_body_line(f.last_displayed_body, 1) + assert f.last_displayed_body.focus == text_object + +def test_search_does_not_crash_on_bad(): + """ + this used to crash, kept for reference. + """ + + f = tutils.tflowview(request_contents="this is string\nstring is string\n"+("A" * cv.VIEW_CUTOFF)+"AFTERCUTOFF") + f.search("AFTERCUTOFF") + + # pretend F + f.state.add_flow_setting( + f.flow, + (f.state.view_flow_mode, "fullcontents"), + True + ) + f.master.refresh_flow(f.flow) + + # text changed, now this string will exist. can happen when user presses F + # for full text view + f.search("AFTERCUTOFF") + +def test_search_backwards(): + f = tutils.tflowview(request_contents="content, content") + + first_match = ('content, content', [(None, 2), (f.highlight_color, 2)]) + + f.search("nt") + text_object = tutils.get_body_line(f.last_displayed_body, 0) + assert text_object.get_text() == first_match + + f.search("nt") + text_object = tutils.get_body_line(f.last_displayed_body, 1) + assert text_object.get_text() == ('content, content', [(None, 5), (f.highlight_color, 2)]) + + f.search_again(backwards=True) + text_object = tutils.get_body_line(f.last_displayed_body, 0) + assert text_object.get_text() == first_match + -- cgit v1.2.3 From 3c02865e8b5839d536bc9982e4c0e6e699fd1943 Mon Sep 17 00:00:00 2001 From: Pedro Worcel Date: Sat, 22 Feb 2014 15:32:35 +1300 Subject: add multi-line support --- test/test_console_search.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test') diff --git a/test/test_console_search.py b/test/test_console_search.py index 7374f399..69c033b9 100644 --- a/test/test_console_search.py +++ b/test/test_console_search.py @@ -119,3 +119,18 @@ def test_search_backwards(): text_object = tutils.get_body_line(f.last_displayed_body, 0) assert text_object.get_text() == first_match +def test_search_back_multiline(): + f = tutils.tflowview(request_contents="this is string\nstring is string") + + f.search("string") + text_object = tutils.get_body_line(f.last_displayed_body, 0) + first_match = ('this is string', [(None, 8), (f.highlight_color, 6)]) + assert text_object.get_text() == first_match + + f.search_again() + text_object = tutils.get_body_line(f.last_displayed_body, 1) + assert text_object.get_text() == ('string is string', [(None, 0), (f.highlight_color, 6)]) + + f.search_again(backwards=True) + text_object = tutils.get_body_line(f.last_displayed_body, 0) + assert text_object.get_text() == first_match -- cgit v1.2.3 From 4284fd3614561fe5e2c53154defb3774f14c589c Mon Sep 17 00:00:00 2001 From: Pedro Worcel Date: Sat, 22 Feb 2014 16:32:22 +1300 Subject: add multi-line support to backwards search --- test/test_console_search.py | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/test_console_search.py b/test/test_console_search.py index 69c033b9..60b998cc 100644 --- a/test/test_console_search.py +++ b/test/test_console_search.py @@ -38,8 +38,8 @@ def test_search_highlights_clears_prev(): text_object = tutils.get_body_line(f.last_displayed_body, 0) assert text_object.get_text() != ('this is string', [(None, 8), (f.highlight_color, 6)]) -def test_search_highlights_multi_line(): - f = tutils.tflowview(request_contents="this is string\nstring is string") +def test_search_highlights_multi_line(flow=None): + f = flow if flow else tutils.tflowview(request_contents="this is string\nstring is string") # should highlight the first line. f.search("string") @@ -54,7 +54,6 @@ def test_search_highlights_multi_line(): # should highlight third line, second appearance of string. f.search("string") text_object = tutils.get_body_line(f.last_displayed_body, 1) - print(text_object.get_text(), ('string is string', [(None, 10), (f.highlight_color, 6)])) assert text_object.get_text() == ('string is string', [(None, 10), (f.highlight_color, 6)]) def test_search_loops(): @@ -122,15 +121,38 @@ def test_search_backwards(): def test_search_back_multiline(): f = tutils.tflowview(request_contents="this is string\nstring is string") - f.search("string") + # shared assertions. highlight and pointers should now be on the third + # 'string' appearance + test_search_highlights_multi_line(f) + + # should highlight second line, first appearance of string. + f.search_again(backwards=True) + text_object = tutils.get_body_line(f.last_displayed_body, 1) + assert text_object.get_text() == ('string is string', [(None, 0), (f.highlight_color, 6)]) + + # should highlight the first line again. + f.search_again(backwards=True) text_object = tutils.get_body_line(f.last_displayed_body, 0) - first_match = ('this is string', [(None, 8), (f.highlight_color, 6)]) - assert text_object.get_text() == first_match + assert text_object.get_text() == ('this is string', [(None, 8), (f.highlight_color, 6)]) +def test_search_back_multi_multi_line(): + """ + same as above for some bugs the above won't catch. + """ + f = tutils.tflowview(request_contents="this is string\nthis is string\nthis is string") + + f.search("string") f.search_again() + f.search_again() + + # should be on second line + f.search_again(backwards=True) text_object = tutils.get_body_line(f.last_displayed_body, 1) - assert text_object.get_text() == ('string is string', [(None, 0), (f.highlight_color, 6)]) + assert text_object.get_text() == ('this is string', [(None, 8), (f.highlight_color, 6)]) + # first line now f.search_again(backwards=True) text_object = tutils.get_body_line(f.last_displayed_body, 0) - assert text_object.get_text() == first_match + print(text_object.get_text(), ('this is string', [(None, 8), (f.highlight_color, 6)])) + assert text_object.get_text() == ('this is string', [(None, 8), (f.highlight_color, 6)]) + -- cgit v1.2.3 From 3e500344282a364f1fbd7245c49d980fe0bfab11 Mon Sep 17 00:00:00 2001 From: Pedro Worcel Date: Sat, 22 Feb 2014 17:15:37 +1300 Subject: fix the wrapping on backward searches --- test/test_console_search.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/test_console_search.py b/test/test_console_search.py index 60b998cc..0e47ef79 100644 --- a/test/test_console_search.py +++ b/test/test_console_search.py @@ -153,6 +153,24 @@ def test_search_back_multi_multi_line(): # first line now f.search_again(backwards=True) text_object = tutils.get_body_line(f.last_displayed_body, 0) - print(text_object.get_text(), ('this is string', [(None, 8), (f.highlight_color, 6)])) + assert text_object.get_text() == ('this is string', [(None, 8), (f.highlight_color, 6)]) + +def test_search_backwards_wraps(): + """ + when searching past line 0, it should loop. + """ + f = tutils.tflowview(request_contents="this is string\nthis is string\nthis is string") + + # should be on second line + f.search("string") + f.search_again() + text_object = tutils.get_body_line(f.last_displayed_body, 1) + assert text_object.get_text() == ('this is string', [(None, 8), (f.highlight_color, 6)]) + + # should be on third now. + f.search_again(backwards=True) + message = f.search_again(backwards=True) + + text_object = tutils.get_body_line(f.last_displayed_body, 2) assert text_object.get_text() == ('this is string', [(None, 8), (f.highlight_color, 6)]) -- cgit v1.2.3 From cffae49e348a444466b46ea08cd982e099cdabc3 Mon Sep 17 00:00:00 2001 From: Pedro Worcel Date: Sat, 22 Feb 2014 18:04:56 +1300 Subject: add helpful messages on wrap --- test/test_console_search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/test_console_search.py b/test/test_console_search.py index 0e47ef79..f4e9ff9b 100644 --- a/test/test_console_search.py +++ b/test/test_console_search.py @@ -170,7 +170,7 @@ def test_search_backwards_wraps(): # should be on third now. f.search_again(backwards=True) message = f.search_again(backwards=True) - text_object = tutils.get_body_line(f.last_displayed_body, 2) assert text_object.get_text() == ('this is string', [(None, 8), (f.highlight_color, 6)]) + assert message == "search hit TOP, continuing at BOTTOM" -- cgit v1.2.3 From a34a4831843d5745e200c1df58672973a57aebb0 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 2 Mar 2014 15:14:22 +1300 Subject: Adapt for new pathod and netlib APIs. --- test/test_protocol_http.py | 3 --- test/test_server.py | 13 ++++++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/test_protocol_http.py b/test/test_protocol_http.py index d2ba24de..18aad3b6 100644 --- a/test/test_protocol_http.py +++ b/test/test_protocol_http.py @@ -88,7 +88,6 @@ class TestHTTPResponse: class TestInvalidRequests(tservers.HTTPProxTest): ssl = True - def test_double_connect(self): p = self.pathoc() r = p.request("connect:'%s:%s'" % ("127.0.0.1", self.server2.port)) @@ -117,9 +116,7 @@ class TestProxyChaining(tservers.HTTPChainProxyTest): class TestProxyChainingSSL(tservers.HTTPChainProxyTest): ssl = True - def test_simple(self): - p = self.pathoc() req = p.request("get:'/p/418:b\"content\"'") assert req.content == "content" diff --git a/test/test_server.py b/test/test_server.py index 2f9e6728..a86c095c 100644 --- a/test/test_server.py +++ b/test/test_server.py @@ -206,13 +206,20 @@ class TestHTTPSCertfile(tservers.HTTPProxTest, CommonMixin): def test_certfile(self): assert self.pathod("304") -class TestHTTPSNoCommonName(tservers.HTTPProxTest, CommonMixin): + +class TestHTTPSNoCommonName(tservers.HTTPProxTest): """ Test what happens if we get a cert without common name back. """ ssl = True - ssloptions=pathod.SSLOptions(certfile=tutils.test_data.path("data/no_common_name.pem"), - keyfile=tutils.test_data.path("data/no_common_name.pem")) + ssloptions=pathod.SSLOptions( + certfile = tutils.test_data.path("data/no_common_name.pem"), + cacert = tutils.test_data.path("data/no_common_name.pem"), + ) + def test_http(self): + f = self.pathod("202") + assert f.sslinfo.certchain[0].get_subject().CN == "127.0.0.1" + class TestReverse(tservers.ReverseProxTest, CommonMixin): reverse = True -- cgit v1.2.3 From 863b1e14552f5216ae4c47bf6dfe9b68ff2ca13b Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 2 Mar 2014 15:58:53 +1300 Subject: Update for pathod.SSLOptions changes. --- test/test_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/test_server.py b/test/test_server.py index a86c095c..e31fb589 100644 --- a/test/test_server.py +++ b/test/test_server.py @@ -214,7 +214,7 @@ class TestHTTPSNoCommonName(tservers.HTTPProxTest): ssl = True ssloptions=pathod.SSLOptions( certfile = tutils.test_data.path("data/no_common_name.pem"), - cacert = tutils.test_data.path("data/no_common_name.pem"), + keyfile = tutils.test_data.path("data/no_common_name.pem"), ) def test_http(self): f = self.pathod("202") -- cgit v1.2.3 From f373ac5b6c443d0e633323e39b846fbe78822c2c Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 2 Mar 2014 17:27:24 +1300 Subject: Improve explicit certificate specification - Support cert/key in the same PEM file - Rationalize arguments, expand tests, clean up a bit --- test/test_proxy.py | 9 ++++++--- test/tservers.py | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/test_proxy.py b/test/test_proxy.py index c42d66e7..5ff00290 100644 --- a/test/test_proxy.py +++ b/test/test_proxy.py @@ -70,9 +70,12 @@ class TestProcessProxyOptions: def test_simple(self): assert self.p() - def test_cert(self): - self.assert_noerr("--cert", tutils.test_data.path("data/testkey.pem")) - self.assert_err("does not exist", "--cert", "nonexistent") + def test_certfile_keyfile(self): + self.assert_noerr("--certfile", tutils.test_data.path("data/testkey.pem")) + self.assert_err("does not exist", "--certfile", "nonexistent") + + self.assert_noerr("--keyfile", tutils.test_data.path("data/testkey.pem")) + self.assert_err("does not exist", "--keyfile", "nonexistent") def test_confdir(self): with tutils.tmpdir() as confdir: diff --git a/test/tservers.py b/test/tservers.py index 812e8921..a0f37c98 100644 --- a/test/tservers.py +++ b/test/tservers.py @@ -128,6 +128,7 @@ class ProxTestBase(object): d["clientcerts"] = tutils.test_data.path("data/clientcert") if cls.certfile: d["certfile"] =tutils.test_data.path("data/testkey.pem") + d["keyfile"] =tutils.test_data.path("data/testkey.pem") return d -- cgit v1.2.3 From 32af66881465ae98a53665c8ddd42c02aaf492f7 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 2 Mar 2014 22:15:53 +1300 Subject: Minor cleanups. --- test/test_server.py | 3 --- test/tservers.py | 4 +++- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/test_server.py b/test/test_server.py index e31fb589..2714ef52 100644 --- a/test/test_server.py +++ b/test/test_server.py @@ -377,7 +377,6 @@ class TestTransparentResolveError(tservers.TransparentProxTest): assert self.pathod("304").status_code == 502 - class MasterIncomplete(tservers.TestMaster): def handle_request(self, m): resp = tutils.tresp() @@ -390,5 +389,3 @@ class TestIncompleteResponse(tservers.HTTPProxTest): def test_incomplete(self): assert self.pathod("200").status_code == 502 - - diff --git a/test/tservers.py b/test/tservers.py index a0f37c98..540cda60 100644 --- a/test/tservers.py +++ b/test/tservers.py @@ -28,7 +28,6 @@ class TestMaster(flow.FlowMaster): self.apps.add(testapp, "testapp", 80) self.apps.add(errapp, "errapp", 80) self.clear_log() - self.start_app(APP_HOST, APP_PORT, False) def handle_request(self, m): flow.FlowMaster.handle_request(self, m) @@ -77,6 +76,7 @@ class ProxTestBase(object): no_upstream_cert = False authenticator = None masterclass = TestMaster + externalapp = False @classmethod def setupAll(cls): cls.server = libpathod.test.Daemon(ssl=cls.ssl, ssloptions=cls.ssloptions) @@ -89,6 +89,7 @@ class ProxTestBase(object): **pconf ) tmaster = cls.masterclass(config) + tmaster.start_app(APP_HOST, APP_PORT, cls.externalapp) cls.proxy = ProxyThread(tmaster) cls.proxy.start() @@ -266,6 +267,7 @@ class ChainProxTest(ProxTestBase): cls.chain[-1].port ) tmaster = cls.masterclass(config) + tmaster.start_app(APP_HOST, APP_PORT, cls.externalapp) cls.chain.append(ProxyThread(tmaster)) cls.chain[-1].start() -- cgit v1.2.3 From d65f2215cb9191a24b36ad6a4fcbf474798d3b2d Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 5 Mar 2014 17:25:12 +1300 Subject: Much more sophisticated cert handling - Specify per-domain certificates and keys - Certs are no longer regenerated for SANs - And more. :) --- test/test_app.py | 4 +--- test/test_console_contentview.py | 2 +- test/test_proxy.py | 14 ++++++-------- test/test_server.py | 5 +++-- test/tservers.py | 13 +++++++------ 5 files changed, 18 insertions(+), 20 deletions(-) (limited to 'test') diff --git a/test/test_app.py b/test/test_app.py index f0eab7cc..52cd1ba6 100644 --- a/test/test_app.py +++ b/test/test_app.py @@ -9,11 +9,9 @@ class TestApp(tservers.HTTPProxTest): assert self.app("/").status_code == 200 def test_cert(self): - path = tutils.test_data.path("data/confdir/") + "mitmproxy-ca-cert." with tutils.tmpdir() as d: for ext in ["pem", "p12"]: resp = self.app("/cert/%s" % ext) assert resp.status_code == 200 - with open(path + ext, "rb") as f: - assert resp.content == f.read() + assert resp.content diff --git a/test/test_console_contentview.py b/test/test_console_contentview.py index a878ad4e..0aabd2c5 100644 --- a/test/test_console_contentview.py +++ b/test/test_console_contentview.py @@ -120,7 +120,7 @@ class TestContentView: def test_view_css(self): v = cv.ViewCSS() - with open('./test/data/1.css', 'r') as fp: + with open(tutils.test_data.path('data/1.css'), 'r') as fp: fixture_1 = fp.read() result = v([], 'a', 100) diff --git a/test/test_proxy.py b/test/test_proxy.py index 5ff00290..b15e3f84 100644 --- a/test/test_proxy.py +++ b/test/test_proxy.py @@ -70,13 +70,6 @@ class TestProcessProxyOptions: def test_simple(self): assert self.p() - def test_certfile_keyfile(self): - self.assert_noerr("--certfile", tutils.test_data.path("data/testkey.pem")) - self.assert_err("does not exist", "--certfile", "nonexistent") - - self.assert_noerr("--keyfile", tutils.test_data.path("data/testkey.pem")) - self.assert_err("does not exist", "--keyfile", "nonexistent") - def test_confdir(self): with tutils.tmpdir() as confdir: self.assert_noerr("--confdir", confdir) @@ -93,11 +86,16 @@ class TestProcessProxyOptions: self.assert_err("invalid reverse proxy", "-P", "reverse") self.assert_noerr("-P", "http://localhost") - def test_certs(self): + def test_client_certs(self): with tutils.tmpdir() as confdir: self.assert_noerr("--client-certs", confdir) self.assert_err("directory does not exist", "--client-certs", "nonexistent") + def test_certs(self): + with tutils.tmpdir() as confdir: + self.assert_noerr("--cert", tutils.test_data.path("data/testkey.pem")) + self.assert_err("does not exist", "--cert", "nonexistent") + def test_auth(self): p = self.assert_noerr("--nonanonymous") assert p.authenticator diff --git a/test/test_server.py b/test/test_server.py index 2714ef52..ed21e75c 100644 --- a/test/test_server.py +++ b/test/test_server.py @@ -213,8 +213,9 @@ class TestHTTPSNoCommonName(tservers.HTTPProxTest): """ ssl = True ssloptions=pathod.SSLOptions( - certfile = tutils.test_data.path("data/no_common_name.pem"), - keyfile = tutils.test_data.path("data/no_common_name.pem"), + certs = [ + ("*", tutils.test_data.path("data/no_common_name.pem")) + ] ) def test_http(self): f = self.pathod("202") diff --git a/test/tservers.py b/test/tservers.py index 540cda60..3a6a610f 100644 --- a/test/tservers.py +++ b/test/tservers.py @@ -1,4 +1,5 @@ import threading, Queue +import shutil, tempfile import flask import libpathod.test, libpathod.pathoc from libmproxy import proxy, flow, controller @@ -72,7 +73,6 @@ class ProxTestBase(object): ssl = None ssloptions = False clientcerts = False - certfile = None no_upstream_cert = False authenticator = None masterclass = TestMaster @@ -82,9 +82,10 @@ class ProxTestBase(object): cls.server = libpathod.test.Daemon(ssl=cls.ssl, ssloptions=cls.ssloptions) cls.server2 = libpathod.test.Daemon(ssl=cls.ssl, ssloptions=cls.ssloptions) pconf = cls.get_proxy_config() + cls.confdir = tempfile.gettempdir() config = proxy.ProxyConfig( no_upstream_cert = cls.no_upstream_cert, - cacert = tutils.test_data.path("data/confdir/mitmproxy-ca.pem"), + confdir = cls.confdir, authenticator = cls.authenticator, **pconf ) @@ -93,6 +94,10 @@ class ProxTestBase(object): cls.proxy = ProxyThread(tmaster) cls.proxy.start() + @classmethod + def tearDownAll(cls): + shutil.rmtree(cls.confdir) + @property def master(cls): return cls.proxy.tmaster @@ -127,9 +132,6 @@ class ProxTestBase(object): d = dict() if cls.clientcerts: d["clientcerts"] = tutils.test_data.path("data/clientcert") - if cls.certfile: - d["certfile"] =tutils.test_data.path("data/testkey.pem") - d["keyfile"] =tutils.test_data.path("data/testkey.pem") return d @@ -254,7 +256,6 @@ class ChainProxTest(ProxTestBase): """ n = 2 chain_config = [lambda: proxy.ProxyConfig( - cacert = tutils.test_data.path("data/confdir/mitmproxy-ca.pem"), )] * n @classmethod def setupAll(cls): -- cgit v1.2.3 From 221973aff6553ffb1d40859c5d35b88d959f9718 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Fri, 7 Mar 2014 16:38:24 +1300 Subject: Revert to old cert names, use a subdir for test conf dir. --- test/test_app.py | 1 - test/tservers.py | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/test_app.py b/test/test_app.py index 52cd1ba6..0b6ed14c 100644 --- a/test/test_app.py +++ b/test/test_app.py @@ -14,4 +14,3 @@ class TestApp(tservers.HTTPProxTest): resp = self.app("/cert/%s" % ext) assert resp.status_code == 200 assert resp.content - diff --git a/test/tservers.py b/test/tservers.py index 3a6a610f..cf9b3f73 100644 --- a/test/tservers.py +++ b/test/tservers.py @@ -1,3 +1,4 @@ +import os.path import threading, Queue import shutil, tempfile import flask @@ -82,7 +83,7 @@ class ProxTestBase(object): cls.server = libpathod.test.Daemon(ssl=cls.ssl, ssloptions=cls.ssloptions) cls.server2 = libpathod.test.Daemon(ssl=cls.ssl, ssloptions=cls.ssloptions) pconf = cls.get_proxy_config() - cls.confdir = tempfile.gettempdir() + cls.confdir = os.path.join(tempfile.gettempdir(), "mitmproxy") config = proxy.ProxyConfig( no_upstream_cert = cls.no_upstream_cert, confdir = cls.confdir, -- cgit v1.2.3