aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/contentviews/test_image_parser.py76
-rw-r--r--test/mitmproxy/data/png_parser/aspect.pngbin0 -> 1230326 bytes
-rw-r--r--test/mitmproxy/data/png_parser/ct0n0g04.pngbin0 -> 273 bytes
-rw-r--r--test/mitmproxy/data/png_parser/ct1n0g04.pngbin0 -> 792 bytes
-rw-r--r--test/mitmproxy/data/png_parser/cten0g04.pngbin0 -> 742 bytes
-rw-r--r--test/mitmproxy/data/png_parser/ctzn0g04.pngbin0 -> 753 bytes
-rw-r--r--test/mitmproxy/data/png_parser/g07n0g16.pngbin0 -> 321 bytes
-rw-r--r--test/mitmproxy/test_server.py22
8 files changed, 98 insertions, 0 deletions
diff --git a/test/mitmproxy/contentviews/test_image_parser.py b/test/mitmproxy/contentviews/test_image_parser.py
new file mode 100644
index 00000000..62a07f56
--- /dev/null
+++ b/test/mitmproxy/contentviews/test_image_parser.py
@@ -0,0 +1,76 @@
+import pytest
+
+from mitmproxy.contentviews.image import image_parser
+from mitmproxy.test import tutils
+
+
+@pytest.mark.parametrize("filename, metadata", {
+ # no textual data
+ "mitmproxy/data/png_parser/ct0n0g04.png": [
+ ('Format', 'Portable network graphics'),
+ ('Size', '32 x 32 px'),
+ ('gamma', '1.0')
+ ],
+ # with textual data
+ "mitmproxy/data/png_parser/ct1n0g04.png": [
+ ('Format', 'Portable network graphics'),
+ ('Size', '32 x 32 px'),
+ ('gamma', '1.0'),
+ ('Title', 'PngSuite'),
+ ('Author', 'Willem A.J. van Schaik\n(willem@schaik.com)'),
+ ('Copyright', 'Copyright Willem van Schaik, Singapore 1995-96'),
+ ('Description', 'A compilation of a set of images created to test the\n'
+ 'various color-types of the PNG format. Included are\nblack&white, color,'
+ ' paletted, with alpha channel, with\ntransparency formats. All bit-depths'
+ ' allowed according\nto the spec are present.'),
+ ('Software', 'Created on a NeXTstation color using "pnmtopng".'),
+ ('Disclaimer', 'Freeware.')
+ ],
+ # with compressed textual data
+ "mitmproxy/data/png_parser/ctzn0g04.png": [
+ ('Format', 'Portable network graphics'),
+ ('Size', '32 x 32 px'),
+ ('gamma', '1.0'),
+ ('Title', 'PngSuite'),
+ ('Author', 'Willem A.J. van Schaik\n(willem@schaik.com)'),
+ ('Copyright', 'Copyright Willem van Schaik, Singapore 1995-96'),
+ ('Description', 'A compilation of a set of images created to test the\n'
+ 'various color-types of the PNG format. Included are\nblack&white, color,'
+ ' paletted, with alpha channel, with\ntransparency formats. All bit-depths'
+ ' allowed according\nto the spec are present.'),
+ ('Software', 'Created on a NeXTstation color using "pnmtopng".'),
+ ('Disclaimer', 'Freeware.')
+ ],
+ # UTF-8 international text - english
+ "mitmproxy/data/png_parser/cten0g04.png": [
+ ('Format', 'Portable network graphics'),
+ ('Size', '32 x 32 px'),
+ ('gamma', '1.0'),
+ ('Title', 'PngSuite'),
+ ('Author', 'Willem van Schaik (willem@schaik.com)'),
+ ('Copyright', 'Copyright Willem van Schaik, Canada 2011'),
+ ('Description', 'A compilation of a set of images created to test the '
+ 'various color-types of the PNG format. Included are black&white, color,'
+ ' paletted, with alpha channel, with transparency formats. All bit-depths'
+ ' allowed according to the spec are present.'),
+ ('Software', 'Created on a NeXTstation color using "pnmtopng".'),
+ ('Disclaimer', 'Freeware.')
+ ],
+ # check gamma value
+ "mitmproxy/data/png_parser/g07n0g16.png": [
+ ('Format', 'Portable network graphics'),
+ ('Size', '32 x 32 px'),
+ ('gamma', '0.7')
+ ],
+ # check aspect value
+ "mitmproxy/data/png_parser/aspect.png": [
+ ('Format', 'Portable network graphics'),
+ ('Size', '1280 x 798 px'),
+ ('aspect', '72 x 72'),
+ ('date:create', '2012-07-11T14:04:52-07:00'),
+ ('date:modify', '2012-07-11T14:04:52-07:00')
+ ],
+}.items())
+def test_parse_png(filename, metadata):
+ with open(tutils.test_data.path(filename), "rb") as f:
+ assert metadata == image_parser.parse_png(f.read())
diff --git a/test/mitmproxy/data/png_parser/aspect.png b/test/mitmproxy/data/png_parser/aspect.png
new file mode 100644
index 00000000..17c01913
--- /dev/null
+++ b/test/mitmproxy/data/png_parser/aspect.png
Binary files differ
diff --git a/test/mitmproxy/data/png_parser/ct0n0g04.png b/test/mitmproxy/data/png_parser/ct0n0g04.png
new file mode 100644
index 00000000..40d1e062
--- /dev/null
+++ b/test/mitmproxy/data/png_parser/ct0n0g04.png
Binary files differ
diff --git a/test/mitmproxy/data/png_parser/ct1n0g04.png b/test/mitmproxy/data/png_parser/ct1n0g04.png
new file mode 100644
index 00000000..3ba110aa
--- /dev/null
+++ b/test/mitmproxy/data/png_parser/ct1n0g04.png
Binary files differ
diff --git a/test/mitmproxy/data/png_parser/cten0g04.png b/test/mitmproxy/data/png_parser/cten0g04.png
new file mode 100644
index 00000000..a6a56faf
--- /dev/null
+++ b/test/mitmproxy/data/png_parser/cten0g04.png
Binary files differ
diff --git a/test/mitmproxy/data/png_parser/ctzn0g04.png b/test/mitmproxy/data/png_parser/ctzn0g04.png
new file mode 100644
index 00000000..b4401c9c
--- /dev/null
+++ b/test/mitmproxy/data/png_parser/ctzn0g04.png
Binary files differ
diff --git a/test/mitmproxy/data/png_parser/g07n0g16.png b/test/mitmproxy/data/png_parser/g07n0g16.png
new file mode 100644
index 00000000..d6a47c2d
--- /dev/null
+++ b/test/mitmproxy/data/png_parser/g07n0g16.png
Binary files differ
diff --git a/test/mitmproxy/test_server.py b/test/mitmproxy/test_server.py
index 272fc0e0..86fc6ba0 100644
--- a/test/mitmproxy/test_server.py
+++ b/test/mitmproxy/test_server.py
@@ -503,6 +503,7 @@ class TestSocks5(tservers.SocksModeTest):
f = p.request("get:/p/200")
assert f.status_code == 502
assert b"SOCKS5 mode failure" in f.content
+ assert b"Invalid SOCKS version. Expected 0x05, got 0x47" in f.content
def test_no_connect(self):
"""
@@ -526,6 +527,27 @@ class TestSocks5(tservers.SocksModeTest):
f = p.request("get:/p/200") # the request doesn't matter, error response from handshake will be read anyway.
assert f.status_code == 502
assert b"SOCKS5 mode failure" in f.content
+ assert b"mitmproxy only supports SOCKS5 CONNECT" in f.content
+
+ def test_with_authentication(self):
+ p = self.pathoc()
+ with p.connect():
+ socks.ClientGreeting(
+ socks.VERSION.SOCKS5,
+ [socks.METHOD.USERNAME_PASSWORD]
+ ).to_file(p.wfile)
+ socks.Message(
+ socks.VERSION.SOCKS5,
+ socks.CMD.BIND,
+ socks.ATYP.DOMAINNAME,
+ ("example.com", 8080)
+ ).to_file(p.wfile)
+
+ p.wfile.flush()
+ f = p.request("get:/p/200") # the request doesn't matter, error response from handshake will be read anyway.
+ assert f.status_code == 502
+ assert b"SOCKS5 mode failure" in f.content
+ assert b"mitmproxy only supports SOCKS without authentication" in f.content
class TestSocks5SSL(tservers.SocksModeTest):