decorator: Fix exception format for invalid API key.

This exception class was clearly missing the part where `role` gets
stored, which was intended to be inherited from
InvalidZulipServerError.

This fixes an unnecessary 500 error in the push notifications bouncer.
This commit is contained in:
Tim Abbott 2018-04-25 21:36:34 -07:00
parent b411bc050e
commit 2fa58fe9ad
2 changed files with 13 additions and 1 deletions

View File

@ -185,7 +185,7 @@ class InvalidZulipServerError(JsonableError):
def msg_format() -> Text:
return "Zulip server auth failure: {role} is not registered"
class InvalidZulipServerKeyError(JsonableError):
class InvalidZulipServerKeyError(InvalidZulipServerError):
@staticmethod
def msg_format() -> Text:
return "Zulip server auth failure: key does not match role {role}"

View File

@ -139,6 +139,18 @@ class PushBouncerNotificationTest(BouncerTestCase):
'token': token})
self.assert_json_error(result, "Must validate with valid Zulip server API key")
# We do a bit of hackery here to the API_KEYS cache just to
# make the code simple for sending an incorrect API key.
from zerver.lib.test_classes import API_KEYS
API_KEYS[self.server_uuid] = 'invalid'
result = self.api_post(self.server_uuid, endpoint, {'user_id': user_id,
'token_kind': token_kind,
'token': token})
self.assert_json_error(result, "Zulip server auth failure: key does not match role 1234-abcd",
status_code=401)
del API_KEYS[self.server_uuid]
def test_remote_push_user_endpoints(self) -> None:
endpoints = [
('/api/v1/remotes/push/register', 'register'),