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

A deactivated server shouldn't be updated like that - we want to return
an error.
This commit is contained in:
Mateusz Mandera 2023-12-15 14:29:21 +01:00 committed by Tim Abbott
parent 53f40133eb
commit d351353126
2 changed files with 24 additions and 7 deletions

View File

@ -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)

View File

@ -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})