Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite UI redirection loop after deactivating an active user #35486

Merged
merged 10 commits into from
Nov 7, 2023
7 changes: 5 additions & 2 deletions airflow/www/extensions/init_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import logging
from importlib import import_module

from flask import g, redirect
from flask import g, redirect, request

from airflow.configuration import conf
from airflow.exceptions import AirflowConfigException, AirflowException
Expand Down Expand Up @@ -69,5 +69,8 @@ def init_api_experimental_auth(app):
def init_check_user_active(app):
@app.before_request
def check_user_active():
url_logout = get_auth_manager().get_url_logout()
if request.path == url_logout:
return
if get_auth_manager().is_logged_in() and not g.user.is_active:
return redirect(get_auth_manager().get_url_logout())
return redirect(url_logout)
9 changes: 9 additions & 0 deletions tests/www/views/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,12 @@ def test_check_active_user(app, user_client):
resp = user_client.get("/home")
assert resp.status_code == 302
assert "/logout" in resp.headers.get("Location")


def test_check_deactivated_user_redirected_to_login(app, user_client):
with app.test_request_context():
user = app.appbuilder.sm.find_user(username="test_user")
user.active = False
resp = user_client.get("/home", follow_redirects=True)
assert resp.status_code == 200
assert "/login" in resp.request.url