aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libmproxy/flow.py7
-rw-r--r--test/scripts/duplicate_flow.py5
-rw-r--r--test/test_flow.py13
-rw-r--r--test/test_proxy.py2
-rw-r--r--test/test_script.py15
5 files changed, 32 insertions, 10 deletions
diff --git a/libmproxy/flow.py b/libmproxy/flow.py
index 58e4eea4..c4bf35a5 100644
--- a/libmproxy/flow.py
+++ b/libmproxy/flow.py
@@ -1096,11 +1096,8 @@ class State(object):
Add an error response to the state. Returns the matching flow, or
None if there isn't one.
"""
- if err.request:
- f = self._flow_map.get(err.request)
- if not f:
- return None
- else:
+ f = self._flow_map.get(err.request)
+ if not f:
return None
f.error = err
if f.match(self._limit) and not f in self.view:
diff --git a/test/scripts/duplicate_flow.py b/test/scripts/duplicate_flow.py
new file mode 100644
index 00000000..f1b92309
--- /dev/null
+++ b/test/scripts/duplicate_flow.py
@@ -0,0 +1,5 @@
+
+def request(ctx, f):
+ f = ctx.duplicate_flow(f)
+ ctx.replay_request(f)
+
diff --git a/test/test_flow.py b/test/test_flow.py
index ffcb6e25..67dfe3c2 100644
--- a/test/test_flow.py
+++ b/test/test_flow.py
@@ -143,6 +143,17 @@ class uFlow(libpry.AutoTree):
assert not f.request is f2.request
assert f.request.headers == f2.request.headers
assert not f.request.headers is f2.request.headers
+ assert f.response == f2.response
+ assert not f.response is f2.response
+
+ f = tutils.tflow_err()
+ f2 = f.copy()
+ assert not f is f2
+ assert not f.request is f2.request
+ assert f.request.headers == f2.request.headers
+ assert not f.request.headers is f2.request.headers
+ assert f.error == f2.error
+ assert not f.error is f2.error
def test_match(self):
f = tutils.tflow()
@@ -301,7 +312,6 @@ class uState(libpry.AutoTree):
assert c.add_response(resp)
assert c.active_flow_count() == 0
-
def test_err(self):
c = flow.State()
req = tutils.treq()
@@ -322,7 +332,6 @@ class uState(libpry.AutoTree):
assert c.add_error(e)
assert c.view
-
def test_set_limit(self):
c = flow.State()
diff --git a/test/test_proxy.py b/test/test_proxy.py
index 22bcb6d4..fccef977 100644
--- a/test/test_proxy.py
+++ b/test/test_proxy.py
@@ -24,6 +24,7 @@ class u_read_chunked(libpry.AutoTree):
class Dummy: pass
+
class u_read_http_body(libpry.AutoTree):
def test_all(self):
@@ -42,7 +43,6 @@ class u_read_http_body(libpry.AutoTree):
s = cStringIO.StringIO("testing")
libpry.raises(proxy.ProxyError, proxy.read_http_body, s, d, h, False, 4)
-
h = flow.ODict()
s = cStringIO.StringIO("testing")
assert len(proxy.read_http_body(s, d, h, True, 4)) == 4
diff --git a/test/test_script.py b/test/test_script.py
index 32ee2d95..94f036d9 100644
--- a/test/test_script.py
+++ b/test/test_script.py
@@ -1,6 +1,7 @@
import os
from libmproxy import script, flow
import libpry
+import tutils
class uScript(libpry.AutoTree):
def test_simple(self):
@@ -13,15 +14,25 @@ class uScript(libpry.AutoTree):
assert "here" in p.ns
assert p.run("here") == (True, 1)
assert p.run("here") == (True, 2)
-
+
ret = p.run("errargs")
- assert not ret[0]
+ assert not ret[0]
assert len(ret[1]) == 2
# Check reload
p.load()
assert p.run("here") == (True, 1)
+ def test_duplicate_flow(self):
+ s = flow.State()
+ fm = flow.FlowMaster(None, s)
+ fm.load_script(os.path.join("scripts", "duplicate_flow.py"))
+ r = tutils.treq()
+ fm.handle_request(r)
+ assert fm.state.flow_count() == 2
+ assert not fm.state.view[0].request.is_replay()
+ assert fm.state.view[1].request.is_replay()
+
def test_err(self):
s = flow.State()
fm = flow.FlowMaster(None, s)
0'>310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449