Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

zilencer: Fix server/register failing to check if server is deactivated.

Mateusz Manderad351353126d7
diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py
index 582d2891306..a2d06789b33 100644
--- a/zerver/tests/test_push_notifications.py
+++ b/zerver/tests/test_push_notifications.py
@@ -4258,6 +4258,16 @@ class PushBouncerSignupTest(ZulipTestCase):
status_code=401,
)
+ # Now try to do a request to server/register again. Normally, this updates
+ # the server's registration details. But the server is deactivated, so it
+ # should return the corresponding error.
+ result = self.client_post("/api/v1/remotes/server/register", request)
+ self.assert_json_error(
+ result,
+ "The mobile push notification service registration for your server has been deactivated",
+ status_code=401,
+ )
+
def test_push_signup_invalid_host(self) -> None:
zulip_org_id = str(uuid.uuid4())
zulip_org_key = get_random_string(64)
diff --git a/zilencer/views.py b/zilencer/views.py
index 6aa5f0c92ac..82e9ab8f96f 100644
--- a/zilencer/views.py
+++ b/zilencer/views.py
@@ -31,7 +31,11 @@ from corporate.lib.stripe import (
)
from corporate.models import CustomerPlan, get_current_plan_by_customer
from zerver.decorator import require_post
-from zerver.lib.exceptions import JsonableError, RemoteRealmServerMismatchError
+from zerver.lib.exceptions import (
+ JsonableError,
+ RemoteRealmServerMismatchError,
+ RemoteServerDeactivatedError,
+)
from zerver.lib.push_notifications import (
InvalidRemotePushDeviceTokenError,
UserPushIdentityCompat,
@@ -149,12 +153,15 @@ def register_remote_server(
else:
if not constant_time_compare(remote_server.api_key, zulip_org_key):
raise InvalidZulipServerKeyError(zulip_org_id)
- else:
- remote_server.hostname = hostname
- remote_server.contact_email = contact_email
- if new_org_key is not None:
- remote_server.api_key = new_org_key
- remote_server.save()
+
+ if remote_server.deactivated:
+ raise RemoteServerDeactivatedError
+
+ remote_server.hostname = hostname
+ remote_server.contact_email = contact_email
+ if new_org_key is not None:
+ remote_server.api_key = new_org_key
+ remote_server.save()
return json_success(request, data={"created": created})