pass authnid_client directly to Login handler and other small cleanup

This commit is contained in:
dandds 2018-06-12 15:57:27 -04:00
parent 34f3c7776b
commit 261a00adb2
4 changed files with 15 additions and 15 deletions

View File

@ -15,6 +15,7 @@ from atst.api_client import ApiClient
ENV = os.getenv("TORNADO_ENV", "dev") ENV = os.getenv("TORNADO_ENV", "dev")
def make_app(config): def make_app(config):
authz_client = ApiClient(config["default"]["AUTHZ_BASE_URL"]) authz_client = ApiClient(config["default"]["AUTHZ_BASE_URL"])
@ -22,7 +23,12 @@ def make_app(config):
routes = [ routes = [
url(r"/", Home, {"page": "login"}, name="main"), url(r"/", Home, {"page": "login"}, name="main"),
url(r"/login", Login, {"page": "login"}, name="login"), url(
r"/login",
Login,
{"authnid_client": authnid_client},
name="login",
),
url(r"/home", MainHandler, {"page": "home"}, name="home"), url(r"/home", MainHandler, {"page": "home"}, name="home"),
url( url(
r"/workspaces", r"/workspaces",
@ -54,16 +60,18 @@ def make_app(config):
cookie_secret=config["default"]["COOKIE_SECRET"], cookie_secret=config["default"]["COOKIE_SECRET"],
debug=config['default'].getboolean('DEBUG') debug=config['default'].getboolean('DEBUG')
) )
app.authnid_client = authnid_client
return app return app
def make_config(): def make_config():
BASE_CONFIG_FILENAME = os.path.join(os.path.dirname(__file__), "../config/base.ini") BASE_CONFIG_FILENAME = os.path.join(
os.path.dirname(__file__),
"../config/base.ini"
)
ENV_CONFIG_FILENAME = os.path.join( ENV_CONFIG_FILENAME = os.path.join(
os.path.dirname(__file__), os.path.dirname(__file__),
"../config/", "../config/",
"{}.ini".format(ENV.lower()), "{}.ini".format(ENV.lower())
) )
config = ConfigParser() config = ConfigParser()

View File

@ -1,5 +1,4 @@
import os import os
import functools
from webassets import Environment, Bundle from webassets import Environment, Bundle
import tornado.web import tornado.web
from atst.home import home from atst.home import home

View File

@ -4,8 +4,8 @@ from atst.handler import BaseHandler
class Login(BaseHandler): class Login(BaseHandler):
def initialize(self, page): def initialize(self, authnid_client):
self.page = page self.authnid_client = authnid_client
@tornado.gen.coroutine @tornado.gen.coroutine
def get(self): def get(self):
@ -24,7 +24,7 @@ class Login(BaseHandler):
@tornado.gen.coroutine @tornado.gen.coroutine
def _validate_login_token(self, token): def _validate_login_token(self, token):
try: try:
response = yield self.application.authnid_client.post( response = yield self.authnid_client.post(
"/api/v1/validate", json={"token": token} "/api/v1/validate", json={"token": token}
) )
return response.code == 200 return response.code == 200

View File

@ -4,13 +4,6 @@ import tornado.web
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
class MockApiResponse():
def __init__(self, code, json):
self.code = code
self.json = json
@pytest.mark.gen_test @pytest.mark.gen_test
def test_redirects_when_not_logged_in(http_client, base_url): def test_redirects_when_not_logged_in(http_client, base_url):
response = yield http_client.fetch( response = yield http_client.fetch(