From c9c255b3a83a25e4b7065752a90c73a116cb1afa Mon Sep 17 00:00:00 2001 From: Mateusz Mandera Date: Sun, 29 Jan 2023 23:57:09 +0100 Subject: [PATCH] auth: Improve JsonableError in get_..._jwt_authentication_request. --- zerver/tests/test_auth_backends.py | 4 +++- zerver/views/auth.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py index 4ac8015225..0ed68901e7 100644 --- a/zerver/tests/test_auth_backends.py +++ b/zerver/tests/test_auth_backends.py @@ -5445,7 +5445,9 @@ class TestJWTLogin(ZulipTestCase): with self.settings(JWT_AUTH_KEYS={"acme": {"key": "key", "algorithms": ["HS256"]}}): data = {"json_web_token": "not relevant"} result = self.client_post("/accounts/login/jwt/", data) - self.assert_json_error_contains(result, "Auth key for this subdomain not found", 400) + self.assert_json_error_contains( + result, "JWT authentication is not enabled for this organization", 400 + ) def test_login_failure_when_key_is_missing(self) -> None: with self.settings(JWT_AUTH_KEYS={"zulip": {"key": "key", "algorithms": ["HS256"]}}): diff --git a/zerver/views/auth.py b/zerver/views/auth.py index 8b41046f6a..a7a023a3bc 100644 --- a/zerver/views/auth.py +++ b/zerver/views/auth.py @@ -483,7 +483,7 @@ def get_email_and_realm_from_jwt_authentication_request( key = settings.JWT_AUTH_KEYS[realm.subdomain]["key"] algorithms = settings.JWT_AUTH_KEYS[realm.subdomain]["algorithms"] except KeyError: - raise JsonableError(_("Auth key for this subdomain not found")) + raise JsonableError(_("JWT authentication is not enabled for this organization")) try: json_web_token = request.POST["json_web_token"]