예제 #1
0
파일: simple.py 프로젝트: PoorHttp/PoorWSGI
def logout(req):
    log.debug("Input cookies: %s", repr(req.cookies))
    cookie = PoorSession(app.secret_key)
    cookie.destroy()
    response = RedirectResponse('/')
    cookie.header(response)
    return response
예제 #2
0
파일: simple.py 프로젝트: JPilarr/PoorWSGI
def logout(req):
    req.log_error("Input cookies: %s" % repr(req.cookies), state.LOG_DEBUG)
    cookie = PoorSession(req)
    cookie.destroy()
    cookie.header(req, req.headers_out)
    req.log_error("Output headers: %s" % req.headers_out, state.LOG_DEBUG)
    redirect(req, '/')
예제 #3
0
 def test_default(self):
     session = PoorSession(SECRET_KEY)
     headers = session.header()
     assert "Expires" not in headers[0][1]
     assert "Max-Age" not in headers[0][1]
     assert "Path" in headers[0][1]
     assert "Domain" not in headers[0][1]
예제 #4
0
    def test_bad_session(self):
        cookies = SimpleCookie()
        cookies["SESSID"] = "\0"
        session = PoorSession(SECRET_KEY)

        with raises(SessionError):
            session.load(cookies)
예제 #5
0
파일: simple.py 프로젝트: PoorHttp/PoorWSGI
def login(req):
    log.debug("Input cookies: %s", repr(req.cookies))
    cookie = PoorSession(app.secret_key)
    cookie.data['login'] = True
    response = RedirectResponse('/')
    cookie.header(response)
    return response
예제 #6
0
파일: simple.py 프로젝트: JPilarr/PoorWSGI
    def handler(req):
        cookie = PoorSession(req)
        if 'login' not in cookie.data:
            req.log_error('Login cookie not found.', state.LOG_INFO)
            redirect(req, '/', text='Login required')

        return fn(req)
예제 #7
0
def req_session():
    """Instace of Request object with session cookie."""
    request = Request()
    session = PoorSession(request.secret_key)
    session.data['test'] = True
    session.write()
    request.cookies = session.cookie
    return request
예제 #8
0
파일: simple.py 프로젝트: PoorHttp/PoorWSGI
 def handler(req):
     session = PoorSession(app.secret_key)
     try:
         session.load(req.cookies)
     except SessionError:
         pass
     if 'login' not in session.data:
         log.info('Login cookie not found.')
         redirect(
             "/",
             message="Login required",
         )
     return fun(req)
예제 #9
0
def check_login(req):
    cookie = PoorSession(req)
    if 'login' not in cookie.data:
        raise HTTPException(401)
    return "login ok"
예제 #10
0
 def test_none(self):
     session = PoorSession(SECRET_KEY, same_site="None")
     headers = session.header()
     assert "; SameSite=None" in headers[0][1]
예제 #11
0
 def test_https(self):
     session = PoorSession(SECRET_KEY, secure=True)
     headers = session.header()
     assert "; Secure" in headers[0][1]
예제 #12
0
def login(req):
    cookie = PoorSession(req)
    cookie.data['login'] = True
    response = Response(status_code=204)
    cookie.header(response)
    return response
예제 #13
0
 def test_httponly(self):
     session = PoorSession(SECRET_KEY)
     headers = session.header()
     assert "; HttpOnly; " in headers[0][1]
예제 #14
0
 def test_http(self):
     session = PoorSession(SECRET_KEY)
     headers = session.header()
     assert "; Secure" not in headers[0][1]
예제 #15
0
 def test_no_path(self):
     session = PoorSession(SECRET_KEY, path=None)
     headers = session.header()
     assert "Path" not in headers[0][1]
예제 #16
0
 def test_domain(self):
     session = PoorSession(SECRET_KEY, domain="example.org")
     headers = session.header()
     assert "; Domain=example.org; " in headers[0][1]
예제 #17
0
 def test_strict(self):
     session = PoorSession(SECRET_KEY, same_site="Strict")
     headers = session.header()
     assert "; SameSite=Strict" in headers[0][1]
예제 #18
0
 def test_max_age(self):
     session = PoorSession(SECRET_KEY, max_age=10)
     headers = session.header()
     assert "; Max-Age=10;" in headers[0][1]
예제 #19
0
 def test_no_secret_key(self):
     with raises(SessionError):
         PoorSession(Empty)
예제 #20
0
    def test_bad_session_compatibility(self, req):
        req.cookies = SimpleCookie()
        req.cookies["SESSID"] = "\0"

        with raises(SessionError):
            PoorSession(req)
예제 #21
0
 def test_compatibility_empty(self, req):
     session = PoorSession(req)
     assert session.data == {}
예제 #22
0
 def test_write_load(self, req_session):
     """Method write was called in fixture req_session."""
     session = PoorSession(SECRET_KEY)
     session.load(req_session.cookies)
     assert session.data == {'test': True}
예제 #23
0
 def test_compatibility(self, req_session):
     session = PoorSession(req_session)
     assert session.data == {'test': True}
예제 #24
0
 def test_destroy(self):
     session = PoorSession(SECRET_KEY)
     session.destroy()
     headers = session.header()
     assert "; expires=" in headers[0][1]
예제 #25
0
 def test_lax(self):
     session = PoorSession(SECRET_KEY, same_site="Lax")
     headers = session.header()
     assert "; SameSite=Lax" in headers[0][1]
예제 #26
0
 def test_expires(self):
     session = PoorSession(SECRET_KEY, expires=10)
     headers = session.header()
     assert "; expires=" in headers[0][1]
예제 #27
0
 def test_default(self):
     session = PoorSession(SECRET_KEY)
     headers = session.header()
     assert "; SameSite" not in headers[0][1]