def test_extract(): tf = tflow.tflow(resp=True) tests = [ ["request.method", "GET"], ["request.scheme", "http"], ["request.host", "address"], ["request.http_version", "HTTP/1.1"], ["request.port", "22"], ["request.path", "/path"], ["request.url", "http://address:22/path"], ["request.text", "content"], ["request.content", b"content"], ["request.raw_content", b"content"], ["request.timestamp_start", "1"], ["request.timestamp_end", "2"], ["request.header[header]", "qvalue"], ["response.status_code", "200"], ["response.reason", "OK"], ["response.text", "message"], ["response.content", b"message"], ["response.raw_content", b"message"], ["response.header[header-response]", "svalue"], ["response.timestamp_start", "1"], ["response.timestamp_end", "2"], ["client_conn.address.port", "22"], ["client_conn.address.host", "127.0.0.1"], ["client_conn.tls_version", "TLSv1.2"], ["client_conn.sni", "address"], ["client_conn.ssl_established", "false"], ["server_conn.address.port", "22"], ["server_conn.address.host", "address"], ["server_conn.ip_address.host", "192.168.0.1"], ["server_conn.tls_version", "TLSv1.2"], ["server_conn.sni", "address"], ["server_conn.ssl_established", "false"], ] for t in tests: ret = cut.extract(t[0], tf) if ret != t[1]: raise AssertionError("%s: Expected %s, got %s" % (t[0], t[1], ret)) with open(tutils.test_data.path("mitmproxy/net/data/text_cert"), "rb") as f: d = f.read() c1 = certs.SSLCert.from_pem(d) tf.server_conn.cert = c1 assert "CERTIFICATE" in cut.extract("server_conn.cert", tf)
def test_extract(tdata): tf = tflow.tflow(resp=True) tests = [ ["request.method", "GET"], ["request.scheme", "http"], ["request.host", "address"], ["request.http_version", "HTTP/1.1"], ["request.port", "22"], ["request.path", "/path"], ["request.url", "http://address:22/path"], ["request.text", "content"], ["request.content", b"content"], ["request.raw_content", b"content"], ["request.timestamp_start", "946681200"], ["request.timestamp_end", "946681201"], ["request.header[header]", "qvalue"], ["response.status_code", "200"], ["response.reason", "OK"], ["response.text", "message"], ["response.content", b"message"], ["response.raw_content", b"message"], ["response.header[header-response]", "svalue"], ["response.timestamp_start", "946681202"], ["response.timestamp_end", "946681203"], ["client_conn.address.port", "22"], ["client_conn.address.host", "127.0.0.1"], ["client_conn.tls_version", "TLSv1.2"], ["client_conn.sni", "address"], ["client_conn.tls_established", "false"], ["server_conn.address.port", "22"], ["server_conn.address.host", "address"], ["server_conn.ip_address.host", "192.168.0.1"], ["server_conn.tls_version", "TLSv1.2"], ["server_conn.sni", "address"], ["server_conn.tls_established", "false"], ] for spec, expected in tests: ret = cut.extract(spec, tf) assert spec and ret == expected with open(tdata.path("mitmproxy/net/data/text_cert"), "rb") as f: d = f.read() c1 = certs.Cert.from_pem(d) tf.server_conn.cert = c1 assert "CERTIFICATE" in cut.extract("server_conn.cert", tf)
def test_extract(): tf = tflow.tflow(resp=True) tests = [ ["request.method", "GET"], ["request.scheme", "http"], ["request.host", "address"], ["request.http_version", "HTTP/1.1"], ["request.port", "22"], ["request.path", "/path"], ["request.url", "http://address:22/path"], ["request.text", "content"], ["request.content", b"content"], ["request.raw_content", b"content"], ["request.timestamp_start", "1"], ["request.timestamp_end", "2"], ["request.header[header]", "qvalue"], ["response.status_code", "200"], ["response.reason", "OK"], ["response.text", "message"], ["response.content", b"message"], ["response.raw_content", b"message"], ["response.header[header-response]", "svalue"], ["response.timestamp_start", "1"], ["response.timestamp_end", "2"], ["client_conn.address.port", "22"], ["client_conn.address.host", "127.0.0.1"], ["client_conn.tls_version", "TLSv1.2"], ["client_conn.sni", "address"], ["client_conn.ssl_established", "false"], ["server_conn.address.port", "22"], ["server_conn.address.host", "address"], ["server_conn.ip_address.host", "192.168.0.1"], ["server_conn.tls_version", "TLSv1.2"], ["server_conn.sni", "address"], ["server_conn.ssl_established", "false"], ] for t in tests: ret = cut.extract(t[0], tf) if ret != t[1]: raise AssertionError("%s: Expected %s, got %s" % (t[0], t[1], ret)) with open(tutils.test_data.path("mitmproxy/net/data/text_cert"), "rb") as f: d = f.read() c1 = certs.SSLCert.from_pem(d) tf.server_conn.cert = c1 assert "CERTIFICATE" in cut.extract("server_conn.cert", tf)