Exemplo n.º 1
0
def test_cookie_one_value_with_trailing_semi():
    c = cookies.Cookie("dismiss-top=6;")
    vals = list(c.values())
    assert len(vals) == 1
    assert vals[0].name == b"dismiss-top"
    assert vals[0].value == b"6"
    c = cookies.Cookie("dismiss-top=6;")
Exemplo n.º 2
0
def test_cookie_one_value_with_trailing_semi():
    c = cookies.Cookie('dismiss-top=6;')
    vals = list(c.values())
    eq_(len(vals), 1)
    eq_(vals[0].name, b'dismiss-top')
    eq_(vals[0].value, b'6')
    c = cookies.Cookie('dismiss-top=6;')
Exemplo n.º 3
0
def test_cookie_one_value_with_trailing_semi():
    c = cookies.Cookie('dismiss-top=6;')
    vals = list(c.values())
    assert len(vals) == 1
    assert vals[0].name == b'dismiss-top'
    assert vals[0].value == b'6'
    c = cookies.Cookie('dismiss-top=6;')
Exemplo n.º 4
0
def test_cookie_complex_serialize():
    c = cookies.Cookie('dismiss-top=6; CP=null*, '\
                       'PHPSESSID=0a539d42abc001cdc762809248d4beed, a="42,"')
    eq_(
        c.serialize(),
        'CP=null*; PHPSESSID=0a539d42abc001cdc762809248d4beed; a="42\\054"; '
        'dismiss-top=6')
Exemplo n.º 5
0
def test_cookie_samesite_future__default():
    # ensure default behavior when unsupported values are provided
    c = cookies.Cookie()
    with pytest.raises(ValueError) as excinfo:
        c[b"foo"] = b"bar"
        c[b"foo"].samesite = b"Future"
        c.serialize()
    assert excinfo.value.args[0] == "SameSite must be 'strict', 'lax', or 'none'"
Exemplo n.º 6
0
def test_cookie_complex_serialize():
    c = cookies.Cookie(
        "dismiss-top=6; CP=null*, " 'PHPSESSID=0a539d42abc001cdc762809248d4beed, a="42"'
    )
    assert (
        c.serialize() == "CP=null*; PHPSESSID=0a539d42abc001cdc762809248d4beed;"
        " a=42; dismiss-top=6"
    )
Exemplo n.º 7
0
def test_cookie_complex():
    c = cookies.Cookie('dismiss-top=6; CP=null*, '\
                       'PHPSESSID=0a539d42abc001cdc762809248d4beed, a="42,"')
    d = lambda v: v.decode('ascii')
    c_dict = dict((d(k),d(v.value)) for k,v in c.items())
    eq_(c_dict, {'a': '42,',
        'CP': 'null*',
        'PHPSESSID': '0a539d42abc001cdc762809248d4beed',
        'dismiss-top': '6'
    })
Exemplo n.º 8
0
def test_cookie_complex():
    c = cookies.Cookie("dismiss-top=6; CP=null*, "
                       'PHPSESSID=0a539d42abc001cdc762809248d4beed, a="42,"')

    def d(v):
        return v.decode("ascii")

    c_dict = dict((d(k), d(v.value)) for k, v in c.items())
    assert c_dict == {
        "a": "42,",
        "CP": "null*",
        "PHPSESSID": "0a539d42abc001cdc762809248d4beed",
        "dismiss-top": "6",
    }
Exemplo n.º 9
0
def test_cookie_complex():
    c = cookies.Cookie('dismiss-top=6; CP=null*, '
                       'PHPSESSID=0a539d42abc001cdc762809248d4beed, a="42,"')

    def d(v):
        return v.decode('ascii')

    c_dict = dict((d(k), d(v.value)) for k, v in c.items())
    assert c_dict == {
        'a': '42,',
        'CP': 'null*',
        'PHPSESSID': '0a539d42abc001cdc762809248d4beed',
        'dismiss-top': '6'
    }
Exemplo n.º 10
0
def test_cookie_samesite_future__monkeypatched(monkeypatch):
    # disable validation so future args pass
    monkeypatch.setattr(cookies, "SAMESITE_VALIDATION", False)
    c = cookies.Cookie()
    c[b"foo"] = b"bar"
    c[b"foo"].samesite = b"Future"
    assert c.serialize() == "foo=bar; SameSite=Future"

    # ensure we can toggle it to True and re-achieve default behavior...
    monkeypatch.setattr(cookies, "SAMESITE_VALIDATION", True)
    with pytest.raises(ValueError) as excinfo:
        c[b"foo"] = b"bar"
        c[b"foo"].samesite = b"Future"
        c.serialize()
    assert excinfo.value.args[0] == "SameSite must be 'strict', 'lax', or 'none'"
Exemplo n.º 11
0
def test_cookie_one_value():
    c = cookies.Cookie('dismiss-top=6')
    vals = list(c.values())
    eq_(len(vals), 1)
    eq_(vals[0].name, b'dismiss-top')
    eq_(vals[0].value, b'6')
Exemplo n.º 12
0
def test_parse_qmark_in_val():
    v = r'x="\"\073\054\""; expires=Sun, 12-Jun-2011 23:16:01 GMT'
    c = cookies.Cookie(v)
    eq_(c[b'x'].value, b'";,"')
    eq_(c[b'x'].expires, b'Sun, 12-Jun-2011 23:16:01 GMT')
Exemplo n.º 13
0
def test_cookie_empty():
    c = cookies.Cookie() # empty cookie
    eq_(repr(c), '<Cookie: []>')
Exemplo n.º 14
0
def test_cookie_invalid_name():
    c = cookies.Cookie()
    c['La Pe\xc3\xb1a'] = '1'
    eq_(len(c), 0)
Exemplo n.º 15
0
def test_cookie_load_multiple():
    c = cookies.Cookie("a=1; Secure=true")
    vals = list(c.values())
    assert len(vals) == 1
    assert c[b"a"][b"secure"] == b"true"
Exemplo n.º 16
0
def test_escape_comma():
    c = cookies.Cookie()
    c['x'] = b'";,"'
    eq_(c.serialize(True), r'x="\"\073\054\""')
Exemplo n.º 17
0
def test_cookie_empty():
    c = cookies.Cookie()  # empty cookie
    assert repr(c) == '<Cookie: []>'
Exemplo n.º 18
0
def test_cookie_samesite_lax():
    c = cookies.Cookie()
    c[b"foo"] = b"bar"
    c[b"foo"].samesite = b"Lax"
    assert c.serialize() == "foo=bar; SameSite=Lax"
Exemplo n.º 19
0
def test_cookie_secure():
    c = cookies.Cookie()
    c[text_("foo")] = b"bar"
    c[b"foo"].secure = True
    assert c.serialize() == "foo=bar; secure"
Exemplo n.º 20
0
def test_cookie_httponly():
    c = cookies.Cookie()
    c['foo'] = b'bar'
    c[b'foo'].httponly = True
    eq_(c.serialize(), 'foo=bar; HttpOnly')
Exemplo n.º 21
0
def test_cookie_load_multiple():
    c = cookies.Cookie('a=1; Secure=true')
    vals = list(c.values())
    eq_(len(vals), 1)
    eq_(c[b'a'][b'secure'], b'true')
Exemplo n.º 22
0
def test_cookie_httponly():
    c = cookies.Cookie()
    c["foo"] = b"bar"
    c[b"foo"].httponly = True
    assert c.serialize() == "foo=bar; HttpOnly"
Exemplo n.º 23
0
def test_cookie_one_value():
    c = cookies.Cookie('dismiss-top=6')
    vals = list(c.values())
    assert len(vals) == 1
    assert vals[0].name == b'dismiss-top'
    assert vals[0].value == b'6'
Exemplo n.º 24
0
def test_escape_comma_semi_dquote():
    c = cookies.Cookie()
    c['x'] = b'";,"'
    eq_(c.serialize(True), r'x="\042\073\054\042"')
Exemplo n.º 25
0
def test_cookie_complex_serialize():
    c = cookies.Cookie('dismiss-top=6; CP=null*, '
                       'PHPSESSID=0a539d42abc001cdc762809248d4beed, a="42"')
    assert c.serialize() == 'CP=null*; PHPSESSID=0a539d42abc001cdc762809248d4beed;'\
                            ' a=42; dismiss-top=6'
Exemplo n.º 26
0
def test_cookie_invalid_name():
    c = cookies.Cookie()
    c['La Pe\xc3\xb1a'] = '1'
    assert len(c) == 0
Exemplo n.º 27
0
def test_cookie_secure():
    c = cookies.Cookie()
    c[text_('foo')] = b'bar'
    c[b'foo'].secure = True
    eq_(c.serialize(), 'foo=bar; secure')
Exemplo n.º 28
0
def test_cookie_load_multiple():
    c = cookies.Cookie('a=1; Secure=true')
    vals = list(c.values())
    assert len(vals) == 1
    assert c[b'a'][b'secure'] == b'true'
Exemplo n.º 29
0
def test_cookie_reserved_keys():
    c = cookies.Cookie('dismiss-top=6; CP=null*; $version=42; a=42')
    assert '$version' not in c
    c = cookies.Cookie('$reserved=42; a=$42')
    eq_(list(c.keys()), [b'a'])
Exemplo n.º 30
0
def test_cookie_samesite_strict():
    c = cookies.Cookie()
    c[b"foo"] = b"bar"
    c[b"foo"].samesite = b"Strict"
    assert c.serialize() == "foo=bar; SameSite=Strict"