Example #1
0
def _save_session(session: SecureCookieSession) -> Response:
    interface = SecureCookieSessionInterface()
    app = Quart(__name__)
    app.secret_key = 'secret'
    response = Response('')
    interface.save_session(app, session, response)
    return response
Example #2
0
def test_secure_cookie_session_interface_open_session() -> None:
    session = SecureCookieSession()
    session['something'] = 'else'
    interface = SecureCookieSessionInterface()
    app = Quart(__name__)
    app.secret_key = 'secret'
    response = Response('')
    interface.save_session(app, session, response)
    request = Request('GET', 'http', '/', b'', CIMultiDict())
    request.headers['Cookie'] = response.headers['Set-Cookie']
    new_session = interface.open_session(app, request)
    assert new_session == session
Example #3
0
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('')
    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'