Skip to content

Commit

Permalink
Fix: don't accept password login requests if password auth is disabled (
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse authored Jan 28, 2022
1 parent 2b5d1c0 commit 12c4750
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion redash/handlers/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ def login(org_slug=None):
if current_user.is_authenticated:
return redirect(next_path)

if request.method == "POST":

if request.method == "POST" and current_org.get_setting("auth_password_login_enabled"):
try:
org = current_org._get_current_object()
user = models.User.get_by_email_and_org(request.form["email"], org)
Expand All @@ -214,6 +215,10 @@ def login(org_slug=None):
flash("Wrong email or password.")
except NoResultFound:
flash("Wrong email or password.")
elif request.method == "POST" and not current_org.get_setting("auth_password_login_enabled"):
flash("Password login is not enabled for your organization.")



google_auth_url = get_google_auth_url(next_path)

Expand Down
16 changes: 16 additions & 0 deletions tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,22 @@ def test_user_already_loggedin(self):
self.assertEqual(rv.status_code, 302)
self.assertFalse(login_user_mock.called)

def test_correct_user_and_password_when_password_login_disabled(self):
user = self.factory.user
user.hash_password("password")

self.db.session.add(user)
self.db.session.commit()

self.factory.org.set_setting("auth_password_login_enabled", False)

with patch("redash.handlers.authentication.login_user") as login_user_mock:
rv = self.client.post(
"/default/login", data={"email": user.email, "password": "password"}
)
self.assertEqual(rv.status_code, 200)
self.assertIn("Password login is not enabled for your organization", str(rv.data))


class TestLogout(BaseTestCase):
def test_logout_when_not_loggedin(self):
Expand Down

0 comments on commit 12c4750

Please sign in to comment.