do not redirect in get_current_user

This commit is contained in:
dandds 2018-07-09 13:50:36 -04:00
parent 061d245193
commit b7d191a8eb
2 changed files with 13 additions and 1 deletions

View File

@ -23,7 +23,7 @@ class BaseHandler(tornado.web.RequestHandler):
try: try:
session = self.application.sessions.get_session(cookie) session = self.application.sessions.get_session(cookie)
except SessionNotFoundError: except SessionNotFoundError:
return self.redirect("/login") return None
else: else:
return None return None

View File

@ -19,6 +19,18 @@ def test_redirects_when_not_logged_in(http_client, base_url):
assert re.match("/\??", location) assert re.match("/\??", location)
@pytest.mark.gen_test
def test_redirects_when_session_does_not_exist(monkeypatch, http_client, base_url):
monkeypatch.setattr("atst.handlers.main.MainHandler.get_secure_cookie", lambda s,c: 'stale cookie!')
response = yield http_client.fetch(
base_url + "/home", raise_error=False, follow_redirects=False
)
location = response.headers["Location"]
assert response.code == 302
assert response.error
assert re.match("/\??", location)
@pytest.mark.gen_test @pytest.mark.gen_test
def test_login_with_valid_bearer_token(app, monkeypatch, http_client, base_url): def test_login_with_valid_bearer_token(app, monkeypatch, http_client, base_url):
monkeypatch.setattr("atst.handlers.login.Login._fetch_user_info", _fetch_user_info) monkeypatch.setattr("atst.handlers.login.Login._fetch_user_info", _fetch_user_info)