Skip to content

Commit

Permalink
Fix getCookie implementation in test classes
Browse files Browse the repository at this point in the history
getCookie method included with many of the test suite classes pulls the first item from the dict returned by parse_cookie(). In versions of Python where the dict is not ordered (<=3.5), this may return the session cookie rather than the CSRF token cookie, causing tests to fail. This change to getCookie ensures that the tests don't rely on parse_cookie returned an ordered dict.

Addresses #86
  • Loading branch information
bjudson committed Mar 19, 2019
1 parent 157d27d commit 4ec08be
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions test_seasurf.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ def test_token_validation(self):
def getCookie(self, response, cookie_name):
cookies = response.headers.getlist('Set-Cookie')
for cookie in cookies:
key, value = list(parse_cookie(cookie).items())[0]
if key == cookie_name:
value = parse_cookie(cookie).get(cookie_name)
if value:
return value
return None

Expand Down Expand Up @@ -380,8 +380,8 @@ def test_token_validation(self):
def getCookie(self, response, cookie_name):
cookies = response.headers.getlist('Set-Cookie')
for cookie in cookies:
key, value = list(parse_cookie(cookie).items())[0]
if key == cookie_name:
value = parse_cookie(cookie).get(cookie_name)
if value:
return value
return None

Expand Down Expand Up @@ -447,8 +447,8 @@ def test_no_csrf_cookie_even_after_manually_validated(self):
def getCookie(self, response, cookie_name):
cookies = response.headers.getlist('Set-Cookie')
for cookie in cookies:
key, value = list(parse_cookie(cookie).items())[0]
if key == cookie_name:
value = parse_cookie(cookie).get(cookie_name)
if value:
return value
return None

Expand Down Expand Up @@ -485,8 +485,8 @@ def test_can_manually_validate_exempt_views(self):
def getCookie(self, response, cookie_name):
cookies = response.headers.getlist('Set-Cookie')
for cookie in cookies:
key, value = list(parse_cookie(cookie).items())[0]
if key == cookie_name:
value = parse_cookie(cookie).get(cookie_name)
if value:
return value
return None

Expand Down

0 comments on commit 4ec08be

Please sign in to comment.