Cast some data read from dump files to str, to prevent unicode promotion.

This fixes a bug that caused a traceback when de-serialized requests were
replayed. Also adds unit tests for the problem.
This commit is contained in:
Aldo Cortesi 2011-07-01 13:07:09 +12:00
parent 2a90ea69fd
commit 8e176c2086
2 changed files with 10 additions and 6 deletions

View File

@ -198,11 +198,11 @@ class Request(controller.Msg):
def from_state(klass, state): def from_state(klass, state):
return klass( return klass(
ClientConnect.from_state(state["client_conn"]), ClientConnect.from_state(state["client_conn"]),
state["host"], str(state["host"]),
state["port"], state["port"],
state["scheme"], str(state["scheme"]),
state["method"], str(state["method"]),
state["path"], str(state["path"]),
utils.Headers.from_state(state["headers"]), utils.Headers.from_state(state["headers"]),
base64.decodestring(state["content"]), base64.decodestring(state["content"]),
state["timestamp"] state["timestamp"]
@ -353,7 +353,7 @@ class Response(controller.Msg):
return klass( return klass(
request, request,
state["code"], state["code"],
state["msg"], str(state["msg"]),
utils.Headers.from_state(state["headers"]), utils.Headers.from_state(state["headers"]),
base64.decodestring(state["content"]), base64.decodestring(state["content"]),
state["timestamp"], state["timestamp"],

View File

@ -385,6 +385,7 @@ class uSerialize(libpry.AutoTree):
def test_roundtrip(self): def test_roundtrip(self):
sio = StringIO() sio = StringIO()
f = tutils.tflow() f = tutils.tflow()
f.request.content = "".join(chr(i) for i in range(255))
w = flow.FlowWriter(sio) w = flow.FlowWriter(sio)
w.add(f) w.add(f)
@ -392,7 +393,10 @@ class uSerialize(libpry.AutoTree):
r = flow.FlowReader(sio) r = flow.FlowReader(sio)
l = list(r.stream()) l = list(r.stream())
assert len(l) == 1 assert len(l) == 1
assert l[0] == f
f2 = l[0]
assert f2 == f
assert f2.request.assemble() == f.request.assemble()
def test_load_flows(self): def test_load_flows(self):
r = self._treader() r = self._treader()