Esempio 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;")
Esempio 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;')
Esempio 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;')
Esempio 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')
Esempio 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'"
Esempio 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"
    )
Esempio 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'
    })
Esempio 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",
    }
Esempio 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'
    }
Esempio 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'"
Esempio 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')
Esempio 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')
Esempio n. 13
0
def test_cookie_empty():
    c = cookies.Cookie() # empty cookie
    eq_(repr(c), '<Cookie: []>')
Esempio n. 14
0
def test_cookie_invalid_name():
    c = cookies.Cookie()
    c['La Pe\xc3\xb1a'] = '1'
    eq_(len(c), 0)
Esempio 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"
Esempio n. 16
0
def test_escape_comma():
    c = cookies.Cookie()
    c['x'] = b'";,"'
    eq_(c.serialize(True), r'x="\"\073\054\""')
Esempio n. 17
0
def test_cookie_empty():
    c = cookies.Cookie()  # empty cookie
    assert repr(c) == '<Cookie: []>'
Esempio 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"
Esempio 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"
Esempio 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')
Esempio 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')
Esempio 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"
Esempio 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'
Esempio 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"')
Esempio 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'
Esempio n. 26
0
def test_cookie_invalid_name():
    c = cookies.Cookie()
    c['La Pe\xc3\xb1a'] = '1'
    assert len(c) == 0
Esempio 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')
Esempio 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'
Esempio 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'])
Esempio 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"