Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
remote_server: Handle invalid server uuid being given authing to API.
Mateusz Mandera868ed17661c2
diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.pyindex 367b7932d99..fb6f63eb019 100644--- a/zerver/tests/test_push_notifications.py+++ b/zerver/tests/test_push_notifications.py@@ -241,6 +241,20 @@ class PushBouncerNotificationTest(BouncerTestCase):del self.API_KEYS[self.server_uuid]+ self.API_KEYS["invalid_uuid"] = "invalid"+ result = self.uuid_post(+ "invalid_uuid",+ endpoint,+ dict(user_id=user_id, token_kind=token_kind, token=token),+ subdomain="zulip",+ )+ self.assert_json_error(+ result,+ "Zulip server auth failure: invalid_uuid is not registered -- did you run `manage.py register_server`?",+ status_code=401,+ )+ del self.API_KEYS["invalid_uuid"]+credentials_uuid = str(uuid.uuid4())credentials = "{}:{}".format(credentials_uuid, "invalid")api_auth = "Basic " + base64.b64encode(credentials.encode()).decode()diff --git a/zilencer/models.py b/zilencer/models.pyindex 0cc0089f924..10d3495faed 100644--- a/zilencer/models.py+++ b/zilencer/models.py@@ -3,6 +3,7 @@ from typing import List, Tuplefrom uuid import UUIDfrom django.conf import settings+from django.core.exceptions import ValidationErrorfrom django.db import modelsfrom analytics.models import BaseCount@@ -12,7 +13,10 @@ from zerver.models import AbstractPushDeviceToken, AbstractRealmAuditLogdef get_remote_server_by_uuid(uuid: str) -> "RemoteZulipServer":- return RemoteZulipServer.objects.get(uuid=uuid)+ try:+ return RemoteZulipServer.objects.get(uuid=uuid)+ except ValidationError:+ raise RemoteZulipServer.DoesNotExist()class RemoteZulipServer(models.Model):