handle auth via redirect with parameter
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import pytest
|
||||
import tornado.web
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from atst.handler import validate_login_token
|
||||
|
||||
|
||||
class MockApiResponse():
|
||||
@@ -11,27 +10,6 @@ class MockApiResponse():
|
||||
self.json = json
|
||||
|
||||
|
||||
@pytest.mark.gen_test
|
||||
def test_successful_validate_login_token(monkeypatch, app):
|
||||
monkeypatch.setattr(
|
||||
"atst.api_client.ApiClient.get",
|
||||
lambda x,
|
||||
y,
|
||||
json=None: MockApiResponse(200, {"status": "success"}),
|
||||
)
|
||||
assert validate_login_token(app.authnid_client, "abc-123")
|
||||
|
||||
|
||||
@pytest.mark.gen_test
|
||||
def test_unsuccessful_validate_login_token(monkeypatch, app):
|
||||
monkeypatch.setattr(
|
||||
"atst.api_client.ApiClient.get",
|
||||
lambda x,y,json=None: MockApiResponse(401, {"status": "error"}),
|
||||
)
|
||||
valid = yield validate_login_token(app.authnid_client, "abc-123")
|
||||
assert not valid
|
||||
|
||||
|
||||
@pytest.mark.gen_test
|
||||
def test_redirects_when_not_logged_in(http_client, base_url):
|
||||
response = yield http_client.fetch(
|
||||
@@ -39,22 +17,24 @@ def test_redirects_when_not_logged_in(http_client, base_url):
|
||||
)
|
||||
assert response.code == 302
|
||||
assert response.error
|
||||
assert response.headers["Location"] == "/login"
|
||||
assert response.headers["Location"] == "/"
|
||||
|
||||
|
||||
@pytest.mark.gen_test
|
||||
def test_login_with_valid_bearer_token(app, monkeypatch, http_client, base_url):
|
||||
with ThreadPoolExecutor(max_workers=1) as executor:
|
||||
monkeypatch.setattr(
|
||||
"atst.handler.validate_login_token",
|
||||
"atst.handlers.login.Login._validate_login_token",
|
||||
lambda c,t: executor.submit(lambda: True),
|
||||
)
|
||||
response = yield http_client.fetch(
|
||||
base_url + "/home", headers={"Cookie": "bearer-token=anything"}
|
||||
base_url + "/login?bearer-token=abc-123",
|
||||
follow_redirects=False,
|
||||
raise_error=False
|
||||
)
|
||||
assert response.headers["Set-Cookie"].startswith("atst")
|
||||
assert response.code == 200
|
||||
assert not response.error
|
||||
assert response.headers['Location'] == '/home'
|
||||
assert response.code == 302
|
||||
|
||||
|
||||
@pytest.mark.gen_test
|
||||
|
Reference in New Issue
Block a user