diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-07-20 23:36:39 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-07-20 23:36:39 +1200 |
commit | d7841898e39b7bb1854f7c066ccccaaa84ab2f2c (patch) | |
tree | cdc96b32388629469ee0ec3dca9e6c0961a8cfce /test/test_rparse.py | |
parent | 2bdbbaa8afb80ff1a59542f011fa87ffdfaf7b16 (diff) | |
download | mitmproxy-d7841898e39b7bb1854f7c066ccccaaa84ab2f2c.tar.gz mitmproxy-d7841898e39b7bb1854f7c066ccccaaa84ab2f2c.tar.bz2 mitmproxy-d7841898e39b7bb1854f7c066ccccaaa84ab2f2c.zip |
Add an injection operator.
Diffstat (limited to 'test/test_rparse.py')
-rw-r--r-- | test/test_rparse.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/test_rparse.py b/test/test_rparse.py index f4b408b2..04a4972f 100644 --- a/test/test_rparse.py +++ b/test/test_rparse.py @@ -169,6 +169,23 @@ class TestDisconnects: assert v.value == "r" +class TestInject: + def test_parse_response(self): + a = rparse.parse_response({}, "400:ir,@100").actions[0] + assert a[0] == "r" + assert a[1] == "inject" + + def test_at(self): + e = rparse.InjectAt.expr() + v = e.parseString("i0,'foo'")[0] + assert v.value.val == "foo" + assert v.offset == 0 + assert isinstance(v, rparse.InjectAt) + + v = e.parseString("ir,'foo'")[0] + assert v.offset == "r" + + class TestShortcuts: def test_parse_response(self): assert rparse.parse_response({}, "400:c'foo'").headers[0][0][:] == "Content-Type" @@ -262,6 +279,21 @@ class TestWriteValues: rparse.send_chunk(s, v, bs, start, end) assert s.getvalue() == v[start:end] + def test_write_values_inject(self): + tst = "foo" + + s = cStringIO.StringIO() + rparse.write_values(s, [tst], [(0, "inject", "aaa")], blocksize=5) + assert s.getvalue() == "aaafoo" + + s = cStringIO.StringIO() + rparse.write_values(s, [tst], [(1, "inject", "aaa")], blocksize=5) + assert s.getvalue() == "faaaoo" + + s = cStringIO.StringIO() + rparse.write_values(s, [tst], [(1, "inject", "aaa")], blocksize=5) + assert s.getvalue() == "faaaoo" + def test_write_values_disconnects(self): s = cStringIO.StringIO() tst = "foo"*100 |