diff options
author | John Dennis <jdennis@redhat.com> | 2012-12-19 12:47:46 -0500 |
---|---|---|
committer | Martin Kosek <mkosek@redhat.com> | 2012-12-20 16:39:48 +0100 |
commit | 8a981c06c36efedc726080583ffdeea82ef36703 (patch) | |
tree | ea306a118774cc38b854c64d29ae28d5e7258eca /tests | |
parent | 8183e2c94b7732f2e19cd257489609d0863c2124 (diff) | |
download | freeipa.git-8a981c06c36efedc726080583ffdeea82ef36703.tar.gz freeipa.git-8a981c06c36efedc726080583ffdeea82ef36703.tar.xz freeipa.git-8a981c06c36efedc726080583ffdeea82ef36703.zip |
Cookie Expires date should be locale insensitive
The Expires attribute in a cookie is supposed to follow the RFC 822
(superseded by RFC 1123) date format. That format includes a weekday
abbreviation (e.g. Tue) which must be in English according to the
RFC's.
ipapython/cookie.py has methods to parse and format the Expires
attribute but they were based on strptime() and strftime() which
respects the locale. If a non-English locale is in effect the wrong
date string will be produced and/or it won't be able to parse the date
string.
The fix is to use the date parsing and formatting functions from
email.utils which specifically follow the RFC's and are not locale
sensitive.
This patch also updates the unit test to use email.utils as well.
The patch should be applied to the following branches:
Ticket: https://fedorahosted.org/freeipa/ticket/3313
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_ipapython/test_cookie.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/tests/test_ipapython/test_cookie.py b/tests/test_ipapython/test_cookie.py index f8c5daf4..b8a2d36d 100644 --- a/tests/test_ipapython/test_cookie.py +++ b/tests/test_ipapython/test_cookie.py @@ -20,6 +20,7 @@ import unittest import time import datetime +import email.utils import calendar from ipapython.cookie import Cookie @@ -129,15 +130,16 @@ class TestExpires(unittest.TestCase): # Force microseconds to zero because cookie timestamps only have second resolution self.now = datetime.datetime.utcnow().replace(microsecond=0) self.now_timestamp = calendar.timegm(self.now.utctimetuple()) - self.now_string = datetime.datetime.strftime(self.now, '%a, %d %b %Y %H:%M:%S GMT') + self.now_string = email.utils.formatdate(self.now_timestamp, usegmt=True) self.max_age = 3600 # 1 hour self.age_expiration = self.now + datetime.timedelta(seconds=self.max_age) - self.age_string = datetime.datetime.strftime(self.age_expiration, '%a, %d %b %Y %H:%M:%S GMT') + self.age_timestamp = calendar.timegm(self.age_expiration.utctimetuple()) + self.age_string = email.utils.formatdate(self.age_timestamp, usegmt=True) self.expires = self.now + datetime.timedelta(days=1) # 1 day self.expires_timestamp = calendar.timegm(self.expires.utctimetuple()) - self.expires_string = datetime.datetime.strftime(self.expires, '%a, %d %b %Y %H:%M:%S GMT') + self.expires_string = email.utils.formatdate(self.expires_timestamp, usegmt=True) def test_expires(self): # 1 cookie with name/value and no Max-Age and no Expires @@ -407,15 +409,16 @@ class TestNormalization(unittest.TestCase): # Force microseconds to zero because cookie timestamps only have second resolution self.now = datetime.datetime.utcnow().replace(microsecond=0) self.now_timestamp = calendar.timegm(self.now.utctimetuple()) - self.now_string = datetime.datetime.strftime(self.now, '%a, %d %b %Y %H:%M:%S GMT') + self.now_string = email.utils.formatdate(self.now_timestamp, usegmt=True) self.max_age = 3600 # 1 hour self.age_expiration = self.now + datetime.timedelta(seconds=self.max_age) - self.age_string = datetime.datetime.strftime(self.age_expiration, '%a, %d %b %Y %H:%M:%S GMT') + self.age_timestamp = calendar.timegm(self.age_expiration.utctimetuple()) + self.age_string = email.utils.formatdate(self.age_timestamp, usegmt=True) self.expires = self.now + datetime.timedelta(days=1) # 1 day self.expires_timestamp = calendar.timegm(self.expires.utctimetuple()) - self.expires_string = datetime.datetime.strftime(self.expires, '%a, %d %b %Y %H:%M:%S GMT') + self.expires_string = email.utils.formatdate(self.expires_timestamp, usegmt=True) def test_path_normalization(self): self.assertEqual(Cookie.normalize_url_path(''), '/') |