Exemplo n.º 1
0
async def test_secure_cookie_session_interface_save_session() -> None:
    session = SecureCookieSession()
    session['something'] = 'else'
    interface = SecureCookieSessionInterface()
    app = Quart(__name__)
    app.secret_key = 'secret'
    response = Response('')
    await interface.save_session(app, session, response)
    cookies = SimpleCookie()
    cookies.load(response.headers['Set-Cookie'])
    cookie = cookies[app.session_cookie_name]
    assert cookie['path'] == interface.get_cookie_path(app)
    assert cookie['httponly'] == '' if not interface.get_cookie_httponly(
        app) else True
    assert cookie['secure'] == '' if not interface.get_cookie_secure(
        app) else True
    assert cookie['domain'] == (interface.get_cookie_domain(app) or '')
    assert cookie['expires'] == (interface.get_expiration_time(app, session)
                                 or '')
    assert response.headers['Vary'] == 'Cookie'
Exemplo n.º 2
0
async def test_secure_cookie_session_interface_save_session() -> None:
    session = SecureCookieSession()
    session["something"] = "else"
    interface = SecureCookieSessionInterface()
    app = Quart(__name__)
    app.secret_key = "secret"
    response = Response("")
    await interface.save_session(app, session, response)
    cookies: SimpleCookie = SimpleCookie()
    cookies.load(response.headers["Set-Cookie"])
    cookie = cookies[app.session_cookie_name]
    assert cookie["path"] == interface.get_cookie_path(app)
    assert cookie["httponly"] == "" if not interface.get_cookie_httponly(
        app) else True
    assert cookie["secure"] == "" if not interface.get_cookie_secure(
        app) else True
    if version_info >= (3, 8):
        assert cookie["samesite"] == (interface.get_cookie_samesite(app) or "")
    assert cookie["domain"] == (interface.get_cookie_domain(app) or "")
    assert cookie["expires"] == (interface.get_expiration_time(app, session)
                                 or "")
    assert response.headers["Vary"] == "Cookie"