Ejemplo n.º 1
0
def test_ch_unquote():
    eq_(cookies._unquote(b'"hello world'), b'"hello world')
    eq_(cookies._unquote(b'hello world'), b'hello world')
    eq_(cookies._unquote(b'"hello world"'), b'hello world')
    eq_(cookies._value_quote(b'hello world'), b'"hello world"')
    # quotation mark escaped w/ backslash is unquoted correctly (support
    # pre webob 1.3 cookies)
    eq_(cookies._unquote(b'"\\""'), b'"')
    # we also are able to unquote the newer \\042 serialization of quotation
    # mark
    eq_(cookies._unquote(b'"\\042"'), b'"')
    # but when we generate a new cookie, quote using normal octal quoting
    # rules
    eq_(cookies._value_quote(b'"'), b'"\\042"')
    # backslash escaped w/ backslash is unquoted correctly (support
    # pre webob 1.3 cookies)
    eq_(cookies._unquote(b'"\\\\"'), b'\\')
    # we also are able to unquote the newer \\134 serialization of backslash
    eq_(cookies._unquote(b'"\\134"'), b'\\')
    # but when we generate a new cookie, quote using normal octal quoting
    # rules
    eq_(cookies._value_quote(b'\\'), b'"\\134"')
    # misc byte escaped as octal
    eq_(cookies._unquote(b'"\\377"'), b'\xff')
    eq_(cookies._value_quote(b'\xff'), b'"\\377"')
    # combination
    eq_(cookies._unquote(b'"a\\"\\377"'), b'a"\xff')
    eq_(cookies._value_quote(b'a"\xff'), b'"a\\042\\377"')
Ejemplo n.º 2
0
def test_ch_unquote():
    eq_(cookies._unquote(b'"hello world'), b'"hello world')
    eq_(cookies._unquote(b'hello world'), b'hello world')
    eq_(cookies._unquote(b'"hello world"'), b'hello world')
    eq_(cookies._value_quote(b'hello world'), b'"hello world"')
    # quotation mark escaped w/ backslash is unquoted correctly (support
    # pre webob 1.3 cookies)
    eq_(cookies._unquote(b'"\\""'), b'"')
    # we also are able to unquote the newer \\042 serialization of quotation
    # mark
    eq_(cookies._unquote(b'"\\042"'), b'"')
    # but when we generate a new cookie, quote using normal octal quoting
    # rules
    eq_(cookies._value_quote(b'"'), b'"\\042"')
    # backslash escaped w/ backslash is unquoted correctly (support
    # pre webob 1.3 cookies)
    eq_(cookies._unquote(b'"\\\\"'), b'\\')
    # we also are able to unquote the newer \\134 serialization of backslash
    eq_(cookies._unquote(b'"\\134"'), b'\\')
    # but when we generate a new cookie, quote using normal octal quoting
    # rules
    eq_(cookies._value_quote(b'\\'), b'"\\134"')
    # misc byte escaped as octal
    eq_(cookies._unquote(b'"\\377"'), b'\xff')
    eq_(cookies._value_quote(b'\xff'), b'"\\377"')
    # combination
    eq_(cookies._unquote(b'"a\\"\\377"'), b'a"\xff')
    eq_(cookies._value_quote(b'a"\xff'), b'"a\\042\\377"')
Ejemplo n.º 3
0
def test_invalid_cookie_space():
    with warnings.catch_warnings(record=True) as w:
        # Cause all warnings to always be triggered.
        warnings.simplefilter("always")
        # Trigger a warning.
        
        cookies._value_quote(b'hello world')

        eq_(len(w), 1)
        eq_(issubclass(w[-1].category, RuntimeWarning), True)
        eq_("ValueError" in str(w[-1].message), True)
Ejemplo n.º 4
0
def test_invalid_cookie_space():
    with warnings.catch_warnings(record=True) as w:
        # Cause all warnings to always be triggered.
        warnings.simplefilter("always")

        # Trigger a warning.
        cookies._value_quote(b'hello world')

        assert len(w) == 1
        assert issubclass(w[-1].category, RuntimeWarning) is True
        assert "ValueError" in str(w[-1].message)
Ejemplo n.º 5
0
def test_ch_unquote():
    assert cookies._unquote(b'"hello world') == b'"hello world'
    assert cookies._unquote(b'hello world') == b'hello world'
    assert cookies._unquote(b'"hello world"') == b'hello world'

    # Spaces are not valid in cookies, we support getting them, but won't
    # support sending them
    with pytest.raises(ValueError):
        cookies._value_quote(b'hello world')

    # quotation mark escaped w/ backslash is unquoted correctly (support
    # pre webob 1.3 cookies)
    assert cookies._unquote(b'"\\""') == b'"'
    # we also are able to unquote the newer \\042 serialization of quotation
    # mark
    assert cookies._unquote(b'"\\042"') == b'"'

    # New cookies can not contain quotes.
    with pytest.raises(ValueError):
        cookies._value_quote(b'"')

    # backslash escaped w/ backslash is unquoted correctly (support
    # pre webob 1.3 cookies)
    assert cookies._unquote(b'"\\\\"') == b'\\'
    # we also are able to unquote the newer \\134 serialization of backslash
    assert cookies._unquote(b'"\\134"') == b'\\'

    # Cookies may not contain a backslash
    with pytest.raises(ValueError):
        cookies._value_quote(b'\\')

    # misc byte escaped as octal
    assert cookies._unquote(b'"\\377"') == b'\xff'

    with pytest.raises(ValueError):
        cookies._value_quote(b'\xff')

    # combination
    assert cookies._unquote(b'"a\\"\\377"') == b'a"\xff'
    with pytest.raises(ValueError):
        cookies._value_quote(b'a"\xff')
Ejemplo n.º 6
0
def test_ch_unquote():
    assert cookies._unquote(b'"hello world') == b'"hello world'
    assert cookies._unquote(b'hello world') == b'hello world'
    assert cookies._unquote(b'"hello world"') == b'hello world'

    # Spaces are not valid in cookies, we support getting them, but won't
    # support sending them
    with pytest.raises(ValueError):
        cookies._value_quote(b'hello world')

    # quotation mark escaped w/ backslash is unquoted correctly (support
    # pre webob 1.3 cookies)
    assert cookies._unquote(b'"\\""') == b'"'
    # we also are able to unquote the newer \\042 serialization of quotation
    # mark
    assert cookies._unquote(b'"\\042"') == b'"'

    # New cookies can not contain quotes.
    with pytest.raises(ValueError):
        cookies._value_quote(b'"')

    # backslash escaped w/ backslash is unquoted correctly (support
    # pre webob 1.3 cookies)
    assert cookies._unquote(b'"\\\\"') == b'\\'
    # we also are able to unquote the newer \\134 serialization of backslash
    assert cookies._unquote(b'"\\134"') == b'\\'

    # Cookies may not contain a backslash
    with pytest.raises(ValueError):
        cookies._value_quote(b'\\')

    # misc byte escaped as octal
    assert cookies._unquote(b'"\\377"') == b'\xff'

    with pytest.raises(ValueError):
        cookies._value_quote(b'\xff')

    # combination
    assert cookies._unquote(b'"a\\"\\377"') == b'a"\xff'
    with pytest.raises(ValueError):
        cookies._value_quote(b'a"\xff')