From 08da0da549f2f3f2df1f654592290ab03c6ad11e Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Sep 18 2018 14:59:44 +0000 Subject: Break infinite redirect loop When AUTH is set to fas, if the user has not sign the FPCA and tries accessing a page requiring authentication and FPCA, they get redirected to the index page, from there to the user's dashboard that requires authentication and FPCA and the loop is triggered. Fixes https://pagure.io/pagure/issue/3611 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/ui/app.py b/pagure/ui/app.py index fcf0ca1..4639798 100644 --- a/pagure/ui/app.py +++ b/pagure/ui/app.py @@ -58,7 +58,9 @@ def _filter_acls(repos, acl, user): def index(): """ Front page of the application. """ - if authenticated() and flask.request.path == "/": + if authenticated() and flask.request.path == "/" \ + and not flask.session.get("_requires_fpca", False): + flask.request.from_index = True return flask.redirect(flask.url_for("ui_ns.userdash_projects")) sorting = flask.request.args.get("sorting") or None @@ -986,6 +988,7 @@ def userprofile_groups(username): def new_project(): """ Form to create a new project. """ + user = pagure.lib.search_user( flask.g.session, username=flask.g.fas_user.username ) diff --git a/pagure/utils.py b/pagure/utils.py index a1d74c0..43433c8 100644 --- a/pagure/utils.py +++ b/pagure/utils.py @@ -205,11 +205,11 @@ def login_required(function): If the auth system is ``fas`` it will also require that the user sign the FPCA. """ - auth_method = pagure_config.get("PAGURE_AUTH", None) @wraps(function) def decorated_function(*args, **kwargs): """ Decorated function, actually does the work. """ + auth_method = pagure_config.get("PAGURE_AUTH", None) if flask.session.get("_justloggedout", False): return flask.redirect(flask.url_for("ui_ns.index")) elif not authenticated(): @@ -217,6 +217,7 @@ def login_required(function): flask.url_for("auth_login", next=flask.request.url) ) elif auth_method == "fas" and not flask.g.fas_user.cla_done: + flask.session["_requires_fpca"] = True flask.flash( flask.Markup( 'You must Home - Pagure', output_text) + self.assertIn( + ' You must sign the FPCA (Fedora Project Contributor Agreement) ' + 'to use pagure', output_text) + class PagureFlaskAppNoDocstests(tests.Modeltests): """ Tests for flask app controller of pagure """