From 4df325335b4abcdea6d59314ebfc96e7465a3979 Mon Sep 17 00:00:00 2001 From: rjt-gupta Date: Fri, 14 Dec 2018 21:31:34 +0530 Subject: multipart-fix --- test/mitmproxy/net/http/test_request.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/net/http/test_request.py b/test/mitmproxy/net/http/test_request.py index ef581a91..6ef73389 100644 --- a/test/mitmproxy/net/http/test_request.py +++ b/test/mitmproxy/net/http/test_request.py @@ -372,5 +372,6 @@ class TestRequestUtils: def test_set_multipart_form(self): request = treq(content=b"foobar") - with pytest.raises(NotImplementedError): - request.multipart_form = "foobar" + request.multipart_form = [("filename", "shell.jpg"), ("file_size", "1000")] + assert request.headers['Content-Type'] == "multipart/form-data" + assert request.content -- cgit v1.2.3 From d08d2185eab0d58eef7a2b32d557475e51acb61a Mon Sep 17 00:00:00 2001 From: rjt-gupta Date: Tue, 29 Jan 2019 22:35:01 +0530 Subject: multipart encoder and tests --- test/mitmproxy/net/http/test_multipart.py | 18 ++++++++++++++++++ test/mitmproxy/net/http/test_request.py | 8 ++++---- 2 files changed, 22 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/net/http/test_multipart.py b/test/mitmproxy/net/http/test_multipart.py index 68ae6bbd..ce7dee5a 100644 --- a/test/mitmproxy/net/http/test_multipart.py +++ b/test/mitmproxy/net/http/test_multipart.py @@ -1,5 +1,6 @@ from mitmproxy.net.http import Headers from mitmproxy.net.http import multipart +import pytest def test_decode(): @@ -22,3 +23,20 @@ def test_decode(): assert len(form) == 2 assert form[0] == (b"field1", b"value1") assert form[1] == (b"field2", b"value2") + + +def test_encode(): + data = [("file".encode('utf-8'), "shell.jpg".encode('utf-8')), + ("file_size".encode('utf-8'), "1000".encode('utf-8'))] + headers = Headers( + content_type='multipart/form-data; boundary=127824672498' + ) + content = multipart.encode(headers, data) + + assert b'Content-Disposition: form-data; name="file"' in content + assert b'Content-Type: text/plain; charset=utf-8\r\n\r\nshell.jpg\r\n\r\n--127824672498\r\n' in content + assert b'1000\r\n\r\n--127824672498--\r\n' + assert len(content) == 252 + + with pytest.raises(ValueError, match=r"boundary found in encoded string"): + multipart.encode(headers, [("key".encode('utf-8'), "--127824672498".encode('utf-8'))]) diff --git a/test/mitmproxy/net/http/test_request.py b/test/mitmproxy/net/http/test_request.py index 6ef73389..71d5c7a1 100644 --- a/test/mitmproxy/net/http/test_request.py +++ b/test/mitmproxy/net/http/test_request.py @@ -371,7 +371,7 @@ class TestRequestUtils: assert list(request.multipart_form.items()) == [] def test_set_multipart_form(self): - request = treq(content=b"foobar") - request.multipart_form = [("filename", "shell.jpg"), ("file_size", "1000")] - assert request.headers['Content-Type'] == "multipart/form-data" - assert request.content + request = treq() + request.multipart_form = [("file", "shell.jpg"), ("file_size", "1000")] + assert request.headers["Content-Type"] == 'multipart/form-data' + assert request.content is None -- cgit v1.2.3 From 580ba356adf4e11241725005eb79d47f3468e092 Mon Sep 17 00:00:00 2001 From: rjt-gupta Date: Wed, 6 Feb 2019 03:35:36 +0530 Subject: test coverage improved --- test/mitmproxy/net/http/test_multipart.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test') diff --git a/test/mitmproxy/net/http/test_multipart.py b/test/mitmproxy/net/http/test_multipart.py index ce7dee5a..6d2e5017 100644 --- a/test/mitmproxy/net/http/test_multipart.py +++ b/test/mitmproxy/net/http/test_multipart.py @@ -24,6 +24,18 @@ def test_decode(): assert form[0] == (b"field1", b"value1") assert form[1] == (b"field2", b"value2") + boundary = 'boundary茅莽' + headers = Headers( + content_type='multipart/form-data; boundary=' + boundary + ) + result = multipart.decode(headers, content) + assert result == [] + + headers = Headers( + content_type='' + ) + assert multipart.decode(headers, content) == [] + def test_encode(): data = [("file".encode('utf-8'), "shell.jpg".encode('utf-8')), @@ -40,3 +52,10 @@ def test_encode(): with pytest.raises(ValueError, match=r"boundary found in encoded string"): multipart.encode(headers, [("key".encode('utf-8'), "--127824672498".encode('utf-8'))]) + + boundary = 'boundary茅莽' + headers = Headers( + content_type='multipart/form-data; boundary=' + boundary + ) + result = multipart.encode(headers, data) + assert result == b'' -- cgit v1.2.3 From f97996126f7a7606f8601f0318f0a70a4e818c6c Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Mon, 11 Nov 2019 18:35:06 +0100 Subject: minor improvements and sans-io adjustments --- test/mitmproxy/net/test_tls.py | 2 +- test/mitmproxy/test_connections.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/net/test_tls.py b/test/mitmproxy/net/test_tls.py index 68e67dbe..c4e76bc6 100644 --- a/test/mitmproxy/net/test_tls.py +++ b/test/mitmproxy/net/test_tls.py @@ -116,7 +116,7 @@ class TestClientHello: ) c = tls.ClientHello(data) assert repr(c) - assert c.sni == 'example.com' + assert c.sni == b'example.com' assert c.cipher_suites == [ 49195, 49199, 49196, 49200, 52393, 52392, 52244, 52243, 49161, 49171, 49162, 49172, 156, 157, 47, 53, 10 diff --git a/test/mitmproxy/test_connections.py b/test/mitmproxy/test_connections.py index 7c371c1e..c744e621 100644 --- a/test/mitmproxy/test_connections.py +++ b/test/mitmproxy/test_connections.py @@ -95,7 +95,7 @@ class TestServerConnection: def test_repr(self): c = tflow.tserver_conn() - c.sni = 'foobar' + c.sni = b'foobar' c.tls_established = True c.alpn_proto_negotiated = b'h2' assert 'address:22' in repr(c) -- cgit v1.2.3 From bdc15cbe0c0cd5175af1b58078d65d400cca71d1 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Tue, 12 Nov 2019 02:59:01 +0100 Subject: update mypy --- test/mitmproxy/test_connections.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/mitmproxy/test_connections.py b/test/mitmproxy/test_connections.py index c744e621..7c371c1e 100644 --- a/test/mitmproxy/test_connections.py +++ b/test/mitmproxy/test_connections.py @@ -95,7 +95,7 @@ class TestServerConnection: def test_repr(self): c = tflow.tserver_conn() - c.sni = b'foobar' + c.sni = 'foobar' c.tls_established = True c.alpn_proto_negotiated = b'h2' assert 'address:22' in repr(c) -- cgit v1.2.3