diff options
| author | Florian Schulze <florian.schulze@gmx.net> | 2017-07-30 11:51:08 +0200 |
|---|---|---|
| committer | Florian Schulze <florian.schulze@gmx.net> | 2017-08-01 13:00:28 +0200 |
| commit | 4785f26036c88cffeaf41244b7ebfce31dce9bdf (patch) | |
| tree | 3627d4a4fdcde3cd8c8b31ca2ea9971f78fdb505 /webtest | |
| parent | a6dc65b637ea60c036ea3ed431840cb02c088410 (diff) | |
| download | webtest-4785f26036c88cffeaf41244b7ebfce31dce9bdf.tar.gz | |
Fix strict cookie policy.
The commit b35063f1bc6f6b0cd92b68c56838f385b56e8d00 added a shortcut that breaks strict cookie policies.
We now add ``.local`` to domain names with no dot in them.
Diffstat (limited to 'webtest')
| -rw-r--r-- | webtest/app.py | 9 | ||||
| -rw-r--r-- | webtest/utils.py | 2 |
2 files changed, 6 insertions, 5 deletions
diff --git a/webtest/app.py b/webtest/app.py index 16aeee1..1c19e94 100644 --- a/webtest/app.py +++ b/webtest/app.py @@ -69,13 +69,13 @@ class CookiePolicy(http_cookiejar.DefaultCookiePolicy): Domain=localhost.""" def return_ok_domain(self, cookie, request): - if cookie.domain.endswith(request.origin_req_host): + if cookie.domain == '.localhost': return True return http_cookiejar.DefaultCookiePolicy.return_ok_domain( self, cookie, request) def set_ok_domain(self, cookie, request): - if cookie.domain.endswith(request.origin_req_host): + if cookie.domain == '.localhost': return True return http_cookiejar.DefaultCookiePolicy.set_ok_domain( self, cookie, request) @@ -231,9 +231,10 @@ class TestApp(object): Sets a cookie to be passed through with requests. """ - cookie_domain = self.extra_environ.get('HTTP_HOST', 'localhost') + cookie_domain = self.extra_environ.get('HTTP_HOST', '.localhost') cookie_domain = cookie_domain.split(':', 1)[0] - cookie_domain = '.' + cookie_domain + if '.' not in cookie_domain: + cookie_domain = "%s.local" % cookie_domain value = escape_cookie_value(value) cookie = http_cookiejar.Cookie( version=0, diff --git a/webtest/utils.py b/webtest/utils.py index adb01f3..3eb7f90 100644 --- a/webtest/utils.py +++ b/webtest/utils.py @@ -97,7 +97,7 @@ class _RequestCookieAdapter(object): """ def __init__(self, request): self._request = request - self.origin_req_host = request.host.split(':')[0] + self.origin_req_host = request.host def is_unverifiable(self): return True # sure? Why not? |
