blob: f0a91fd15b5e1e87b2243b2dffa4cef5f5a85ca1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
import pytest
from mitmproxy.contentviews import protobuf
from . import full_eval
datadir = "mitmproxy/contentviews/test_protobuf_data/"
def test_view_protobuf_request(tdata):
v = full_eval(protobuf.ViewProtobuf())
p = tdata.path(datadir + "protobuf01.bin")
with open(p, "rb") as f:
raw = f.read()
content_type, output = v(raw)
assert content_type == "Protobuf"
assert output == [[('text', '1: 3bbc333c-e61c-433b-819a-0b9a8cc103b8')]]
with pytest.raises(ValueError, match="Failed to parse input."):
v(b'foobar')
@pytest.mark.parametrize("filename", ["protobuf02.bin", "protobuf03.bin"])
def test_format_pbuf(filename, tdata):
path = tdata.path(datadir + filename)
with open(path, "rb") as f:
input = f.read()
with open(path.replace(".bin", "-decoded.bin")) as f:
expected = f.read()
assert protobuf.format_pbuf(input) == expected
|