diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/contentviews/test_wbxml.py | 22 | ||||
-rw-r--r-- | test/mitmproxy/contentviews/test_wbxml_data/data-formatted.wbxml | 10 | ||||
-rw-r--r-- | test/mitmproxy/contentviews/test_wbxml_data/data.wbxml | bin | 0 -> 34 bytes | |||
-rw-r--r-- | test/mitmproxy/contrib/test_tls_parser.py | 43 | ||||
-rw-r--r-- | test/mitmproxy/test_flowfilter.py | 3 |
5 files changed, 34 insertions, 44 deletions
diff --git a/test/mitmproxy/contentviews/test_wbxml.py b/test/mitmproxy/contentviews/test_wbxml.py index 777ab4dd..09c770e7 100644 --- a/test/mitmproxy/contentviews/test_wbxml.py +++ b/test/mitmproxy/contentviews/test_wbxml.py @@ -1 +1,21 @@ -# TODO: write tests +from mitmproxy.contentviews import wbxml +from mitmproxy.test import tutils +from . import full_eval + +data = tutils.test_data.push("mitmproxy/contentviews/test_wbxml_data/") + + +def test_wbxml(): + v = full_eval(wbxml.ViewWBXML()) + + assert v(b'\x03\x01\x6A\x00') == ('WBXML', [[('text', '<?xml version="1.0" ?>')]]) + assert v(b'foo') is None + + path = data.path("data.wbxml") # File taken from https://github.com/davidpshaw/PyWBXMLDecoder/tree/master/wbxml_samples + with open(path, 'rb') as f: + input = f.read() + with open("-formatted.".join(path.rsplit(".", 1))) as f: + expected = f.read() + + p = wbxml.ASCommandResponse.ASCommandResponse(input) + assert p.xmlString == expected diff --git a/test/mitmproxy/contentviews/test_wbxml_data/data-formatted.wbxml b/test/mitmproxy/contentviews/test_wbxml_data/data-formatted.wbxml new file mode 100644 index 00000000..fed293bd --- /dev/null +++ b/test/mitmproxy/contentviews/test_wbxml_data/data-formatted.wbxml @@ -0,0 +1,10 @@ +<?xml version="1.0" ?> +<Sync> + <Collections> + <Collection> + <SyncKey>1509029063</SyncKey> + <CollectionId>7</CollectionId> + <Status>1</Status> + </Collection> + </Collections> +</Sync> diff --git a/test/mitmproxy/contentviews/test_wbxml_data/data.wbxml b/test/mitmproxy/contentviews/test_wbxml_data/data.wbxml Binary files differnew file mode 100644 index 00000000..7c7a2004 --- /dev/null +++ b/test/mitmproxy/contentviews/test_wbxml_data/data.wbxml diff --git a/test/mitmproxy/contrib/test_tls_parser.py b/test/mitmproxy/contrib/test_tls_parser.py deleted file mode 100644 index e4d9177f..00000000 --- a/test/mitmproxy/contrib/test_tls_parser.py +++ /dev/null @@ -1,43 +0,0 @@ -import io -from kaitaistruct import KaitaiStream -from mitmproxy.contrib.kaitaistruct import tls_client_hello - - -def test_parse_chrome(): - """ - Test if we properly parse a ClientHello sent by Chrome 54. - """ - data = bytes.fromhex( - "03033b70638d2523e1cba15f8364868295305e9c52aceabda4b5147210abc783e6e1000022c02bc02fc02cc030" - "cca9cca8cc14cc13c009c013c00ac014009c009d002f0035000a0100006cff0100010000000010000e00000b65" - "78616d706c652e636f6d0017000000230000000d00120010060106030501050304010403020102030005000501" - "00000000001200000010000e000c02683208687474702f312e3175500000000b00020100000a00080006001d00" - "170018" - ) - - c = tls_client_hello.TlsClientHello(KaitaiStream(io.BytesIO(data))) - assert c.version.major == 3 - assert c.version.minor == 3 - - alpn = [a for a in c.extensions.extensions if a.type == 16] - assert len(alpn) == 1 - assert alpn[0].body.alpn_protocols[0].name == b"h2" - assert alpn[0].body.alpn_protocols[1].name == b"http/1.1" - - sni = [a for a in c.extensions.extensions if a.type == 0] - assert len(sni) == 1 - assert sni[0].body.server_names[0].name_type == 0 - assert sni[0].body.server_names[0].host_name == b"example.com" - - -def test_parse_no_extensions(): - data = bytes.fromhex( - "03015658a756ab2c2bff55f636814deac086b7ca56b65058c7893ffc6074f5245f70205658a75475103a152637" - "78e1bb6d22e8bbd5b6b0a3a59760ad354e91ba20d353001a0035002f000a000500040009000300060008006000" - "61006200640100" - ) - - c = tls_client_hello.TlsClientHello(KaitaiStream(io.BytesIO(data))) - assert c.version.major == 3 - assert c.version.minor == 1 - assert c.extensions == [] diff --git a/test/mitmproxy/test_flowfilter.py b/test/mitmproxy/test_flowfilter.py index 46fff477..fe9b2408 100644 --- a/test/mitmproxy/test_flowfilter.py +++ b/test/mitmproxy/test_flowfilter.py @@ -209,6 +209,9 @@ class TestMatchingHTTPFlow: assert self.q("~u address:22/path", q) assert not self.q("~u moo/path", q) + q.request = None + assert not self.q("~u address", q) + assert self.q("~u address", s) assert self.q("~u address:22/path", s) assert not self.q("~u moo/path", s) |