From 703c05066ec0bc05c680e24d368606791dd1c958 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Thu, 14 Jul 2016 12:59:00 +1200 Subject: [PATCH] Fix indeterminacy in sticky cookie tests How has this not bitten us before? --- test/mitmproxy/builtins/test_stickycookie.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/test/mitmproxy/builtins/test_stickycookie.py b/test/mitmproxy/builtins/test_stickycookie.py index ddfaf5e04..e64ecb5b8 100644 --- a/test/mitmproxy/builtins/test_stickycookie.py +++ b/test/mitmproxy/builtins/test_stickycookie.py @@ -64,8 +64,11 @@ class TestStickyCookie(mastertest.MasterTest): self._response(s, m, sc, c, "www.google.com") assert sc.jar.keys() - self._response(s, m, sc, "SSID=mooo", "www.google.com") - assert sc.jar.keys()[0] == ('www.google.com', 80, '/') + sc.jar.clear() + self._response( + s, m, sc, "SSID=mooo", "www.google.com" + ) + assert list(sc.jar.keys())[0] == ('www.google.com', 80, '/') def test_response_multiple(self): s, m, sc = self.mk() @@ -76,7 +79,7 @@ class TestStickyCookie(mastertest.MasterTest): f = self._response(s, m, sc, c1, "www.google.com") f.response.headers["Set-Cookie"] = c2 self.invoke(m, "response", f) - googlekey = sc.jar.keys()[0] + googlekey = list(sc.jar.keys())[0] assert len(sc.jar[googlekey].keys()) == 2 def test_response_weird(self): @@ -93,7 +96,7 @@ class TestStickyCookie(mastertest.MasterTest): for c in cs: f.response.headers["Set-Cookie"] = c self.invoke(m, "response", f) - googlekey = sc.jar.keys()[0] + googlekey = list(sc.jar.keys())[0] assert len(sc.jar[googlekey].keys()) == len(cs) def test_response_overwrite(self): @@ -105,9 +108,9 @@ class TestStickyCookie(mastertest.MasterTest): f = self._response(s, m, sc, c1, "www.google.com") f.response.headers["Set-Cookie"] = c2 self.invoke(m, "response", f) - googlekey = sc.jar.keys()[0] + googlekey = list(sc.jar.keys())[0] assert len(sc.jar[googlekey].keys()) == 1 - assert sc.jar[googlekey]["somecookie"].items()[0][1] == "newvalue" + assert list(sc.jar[googlekey]["somecookie"].items())[0][1] == "newvalue" def test_request(self): s, m, sc = self.mk()