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.

push_notifs: Require ios_app_id on register at bouncer, too.

Greg Price1b2178f55888
diff --git a/api_docs/changelog.md b/api_docs/changelog.md
index 046aa276a26..9f085b37455 100644
--- a/api_docs/changelog.md
+++ b/api_docs/changelog.md
@@ -27,6 +27,12 @@ format used by the Zulip server that they are interacting with.
Previously it defaulted to the server setting `ZULIP_IOS_APP_ID`,
defaulting to "org.zulip.Zulip".
+* `POST /remotes/server/register`: The `ios_app_id` parameter is now
+ required when `kind` is 1, i.e. when registering an APNs token.
+ Previously it was ignored, and the push bouncer effectively
+ assumed its value was the server setting `APNS_TOPIC`,
+ defaulting to "org.zulip.Zulip".
+
**Feature level 222**
* [`GET /events`](/api/get-events): When a user is deactivated or
diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py
index bb860811467..4f80cfe340a 100644
--- a/zerver/tests/test_push_notifications.py
+++ b/zerver/tests/test_push_notifications.py
@@ -500,6 +500,31 @@ class PushBouncerNotificationTest(BouncerTestCase):
401,
)
+ def test_register_require_ios_app_id(self) -> None:
+ endpoint = "/api/v1/remotes/push/register"
+ args = {"user_id": 11, "token": "1122"}
+
+ result = self.uuid_post(
+ self.server_uuid,
+ endpoint,
+ {**args, "token_kind": PushDeviceToken.APNS},
+ )
+ self.assert_json_error(result, "Missing ios_app_id")
+
+ result = self.uuid_post(
+ self.server_uuid,
+ endpoint,
+ {**args, "token_kind": PushDeviceToken.APNS, "ios_app_id": "example.app"},
+ )
+ self.assert_json_success(result)
+
+ result = self.uuid_post(
+ self.server_uuid,
+ endpoint,
+ {**args, "token_kind": PushDeviceToken.GCM},
+ )
+ self.assert_json_success(result)
+
def test_register_device_deduplication(self) -> None:
hamlet = self.example_user("hamlet")
token = "111222"
diff --git a/zilencer/views.py b/zilencer/views.py
index 971b48c85cd..4dac17c6ebb 100644
--- a/zilencer/views.py
+++ b/zilencer/views.py
@@ -165,6 +165,8 @@ def register_remote_push_device(
ios_app_id: Optional[str] = REQ(default=None),
) -> HttpResponse:
validate_bouncer_token_request(token, token_kind)
+ if token_kind == RemotePushDeviceToken.APNS and ios_app_id is None:
+ raise JsonableError(_("Missing ios_app_id"))
if user_id is None and user_uuid is None:
raise JsonableError(_("Missing user_id or user_uuid"))