Example #1
0
def test_serialize_cookie_date():
    """
        Testing webob.cookies.serialize_cookie_date.
        Missing scenarios:
            * input value is an str, should be returned verbatim
            * input value is an int, should be converted to timedelta and we
              should continue the rest of the process
    """
    eq_(cookies.serialize_cookie_date('Tue, 04-Jan-2011 13:43:50 GMT'),
        'Tue, 04-Jan-2011 13:43:50 GMT')
    eq_(cookies.serialize_cookie_date(None), None)
    cdate_delta = cookies.serialize_cookie_date(timedelta(seconds=10))
    cdate_int = cookies.serialize_cookie_date(10)
    eq_(cdate_delta, cdate_int)
Example #2
0
def test_serialize_cookie_date():
    """
        Testing webob.cookies.serialize_cookie_date.
        Missing scenarios:
            * input value is an str, should be returned verbatim
            * input value is an int, should be converted to timedelta and we
              should continue the rest of the process
    """
    eq_(cookies.serialize_cookie_date('Tue, 04-Jan-2011 13:43:50 GMT'),
        'Tue, 04-Jan-2011 13:43:50 GMT')
    eq_(cookies.serialize_cookie_date(None), None)
    cdate_delta = cookies.serialize_cookie_date(timedelta(seconds=10))
    cdate_int = cookies.serialize_cookie_date(10)
    eq_(cdate_delta, cdate_int)
Example #3
0
def test_serialize_cookie_date():
    """
        Testing webob.cookies.serialize_cookie_date.
        Missing scenarios:
            * input value is an str, should be returned verbatim
            * input value is an int, should be converted to timedelta and we
              should continue the rest of the process
    """
    date_one = cookies.serialize_cookie_date(b'Tue, 04-Jan-2011 13:43:50 GMT')
    assert date_one == b'Tue, 04-Jan-2011 13:43:50 GMT'
    date_two = cookies.serialize_cookie_date(text_('Tue, 04-Jan-2011 13:43:50 GMT'))
    assert date_two == b'Tue, 04-Jan-2011 13:43:50 GMT'
    assert cookies.serialize_cookie_date(None) is None
    cdate_delta = cookies.serialize_cookie_date(timedelta(seconds=10))
    cdate_int = cookies.serialize_cookie_date(10)
    assert cdate_delta == cdate_int
Example #4
0
    def _core_get_cookies(self, environ, value, max_age=None):
        if max_age is not None:
            max_age = int(max_age)
            later = _utcnow() + datetime.timedelta(seconds=max_age)
            environ['VISITOR_NEW_EXPIRY_TIME'] = later
            # Wdy, DD-Mon-YY HH:MM:SS GMT
            expires = serialize_cookie_date(later)
            # the Expires header is *required* at least for IE7 (IE7 does
            # not respect Max-Age)
            max_age = "; Max-Age=%s; Expires=%s" % (max_age, expires)
        else:
            max_age = ''

        secure = ''
        if self.secure:
            secure = '; secure; HttpOnly'

        cur_domain = environ.get('HTTP_HOST', environ.get('SERVER_NAME'))
        cur_domain = cur_domain.split(':')[0]  # drop port
        wild_domain = '.' + cur_domain
        cookies = [('Set-Cookie', '%s="%s"; Path=/%s%s' %
                    (self.cookie_name, value, max_age, secure)),
                   ('Set-Cookie', '%s="%s"; Path=/; Domain=%s%s%s' %
                    (self.cookie_name, value, cur_domain, max_age, secure)),
                   ('Set-Cookie', '%s="%s"; Path=/; Domain=%s%s%s' %
                    (self.cookie_name, value, wild_domain, max_age, secure))]
        return cookies
Example #5
0
def test_serialize_cookie_date():
    """
        Testing webob.cookies.serialize_cookie_date.
        Missing scenarios:
            * input value is an str, should be returned verbatim
            * input value is an int, should be converted to timedelta and we
              should continue the rest of the process
    """
    date_one = cookies.serialize_cookie_date(b"Tue, 04-Jan-2011 13:43:50 GMT")
    assert date_one == b"Tue, 04-Jan-2011 13:43:50 GMT"
    date_two = cookies.serialize_cookie_date(text_("Tue, 04-Jan-2011 13:43:50 GMT"))
    assert date_two == b"Tue, 04-Jan-2011 13:43:50 GMT"
    assert cookies.serialize_cookie_date(None) is None
    cdate_delta = cookies.serialize_cookie_date(timedelta(seconds=10))
    cdate_int = cookies.serialize_cookie_date(10)
    assert cdate_delta == cdate_int