fall back to regular tornado authentication decorator

This commit is contained in:
dandds 2018-06-12 15:13:22 -04:00
parent 4e61b08330
commit 34f3c7776b
7 changed files with 16 additions and 23 deletions

View File

@ -20,19 +20,6 @@ helpers = {
'assets': assets
}
def authenticated(method):
@functools.wraps(method)
def wrapper(self, *args, **kwargs):
if not self.current_user:
if self.request.method in ("GET", "HEAD"):
url = self.get_login_url()
self.redirect(url)
return
else:
raise tornado.web.HTTPError(403)
return method(self, *args, **kwargs)
return wrapper
class BaseHandler(tornado.web.RequestHandler):
def get_template_namespace(self):

View File

@ -1,4 +1,4 @@
from atst.handler import BaseHandler, authenticated
from atst.handler import BaseHandler
class Dev(BaseHandler):
def initialize(self, action):

View File

@ -1,11 +1,12 @@
import atst
from atst.handler import BaseHandler, authenticated
import tornado
from atst.handler import BaseHandler
class MainHandler(BaseHandler):
def initialize(self, page):
self.page = page
@authenticated
@tornado.web.authenticated
def get(self):
self.render( '%s.html.to' % self.page, page = self.page )

View File

@ -1,4 +1,5 @@
from atst.handler import BaseHandler, authenticated
import tornado
from atst.handler import BaseHandler
mock_requests = [
{
@ -31,6 +32,6 @@ class Request(BaseHandler):
def initialize(self, page):
self.page = page
@authenticated
@tornado.web.authenticated
def get(self):
self.render('requests.html.to', page = self.page, requests = mock_requests )

View File

@ -1,4 +1,5 @@
from atst.handler import BaseHandler, authenticated
import tornado
from atst.handler import BaseHandler
class RequestNew(BaseHandler):
screens = [
@ -22,7 +23,7 @@ class RequestNew(BaseHandler):
def initialize(self, page):
self.page = page
@authenticated
@tornado.web.authenticated
def get(self, screen = 1):
self.render( 'requests/screen-%d.html.to' % int(screen),
page = self.page,

View File

@ -1,4 +1,5 @@
from atst.handler import BaseHandler, authenticated
from atst.handler import BaseHandler
import tornado
import tornado.gen
mock_workspaces = [
@ -19,6 +20,6 @@ class Workspace(BaseHandler):
self.authz_client = authz_client
@tornado.gen.coroutine
@authenticated
@tornado.web.authenticated
def get(self):
self.render( 'workspaces.html.to', page = self.page, workspaces = mock_workspaces )

View File

@ -1,3 +1,4 @@
import re
import pytest
import tornado.web
from concurrent.futures import ThreadPoolExecutor
@ -15,9 +16,10 @@ def test_redirects_when_not_logged_in(http_client, base_url):
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 response.headers["Location"] == "/"
assert re.match('/\??', location)
@pytest.mark.gen_test