Repository: incubator-airflow Updated Branches: refs/heads/master 016c0665d -> 9c67ee842
[AIRFLOW-1021] Fix double login for new users with LDAP By adding the new user to the session and commit before merging, the correct user is returned by `load_user(userid)` instead of `None` due to no `id` assoicated with that user. Closes #2778 from wolfier/AIRFLOW-1021 Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/9c67ee84 Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/9c67ee84 Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/9c67ee84 Branch: refs/heads/master Commit: 9c67ee84296b649ccb998e5b85187b956df9a757 Parents: 016c066 Author: Alan Ma <[email protected]> Authored: Thu Jun 7 14:58:38 2018 -0700 Committer: r39132 <[email protected]> Committed: Thu Jun 7 14:58:43 2018 -0700 ---------------------------------------------------------------------- airflow/contrib/auth/backends/ldap_auth.py | 3 ++- tests/core.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/9c67ee84/airflow/contrib/auth/backends/ldap_auth.py ---------------------------------------------------------------------- diff --git a/airflow/contrib/auth/backends/ldap_auth.py b/airflow/contrib/auth/backends/ldap_auth.py index 177a6de..eefaa12 100644 --- a/airflow/contrib/auth/backends/ldap_auth.py +++ b/airflow/contrib/auth/backends/ldap_auth.py @@ -303,9 +303,10 @@ def login(self, request, session=None): user = models.User( username=username, is_superuser=False) + session.add(user) - session.merge(user) session.commit() + session.merge(user) flask_login.login_user(LdapUser(user)) session.commit() http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/9c67ee84/tests/core.py ---------------------------------------------------------------------- diff --git a/tests/core.py b/tests/core.py index 0312fed..c3adb3c 100644 --- a/tests/core.py +++ b/tests/core.py @@ -2042,6 +2042,9 @@ class WebLdapAuthTest(unittest.TestCase): response = self.login('dataprofiler', 'dataprofiler') self.assertIn('Data Profiling', response.data.decode('utf-8')) + response = self.logout() + self.assertIn('form-signin', response.data.decode('utf-8')) + response = self.login('superuser', 'superuser') self.assertIn('Connections', response.data.decode('utf-8'))
