Skip to content

Commit

Permalink
Don't attempt delivery of notification if we have rejected pushkey (#315
Browse files Browse the repository at this point in the history
)
  • Loading branch information
H-Shay authored Aug 2, 2022
1 parent c0f43e5 commit cac851b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.d/315.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Don't attempt delivery of notification if we have rejected pushkey.
5 changes: 3 additions & 2 deletions sygnal/apnspushkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,9 @@ async def _dispatch_notification_unlimited(
if device.data:
default_payload = device.data.get("default_payload", {})
if not isinstance(default_payload, dict):
log.error(
"default_payload is malformed, this value must be a dict."
log.warning(
"Rejecting pushkey due to misconfigured default_payload, "
"please ensure that default_payload is a dict."
)
return [device.pushkey]

Expand Down
10 changes: 7 additions & 3 deletions sygnal/gcmpushkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,13 @@ async def _dispatch_notification_unlimited(

data = GcmPushkin._build_data(n, device)

# Reject pushkey if default_payload is misconfigured
# Reject pushkey(s) if default_payload is misconfigured
if data is None:
failed.append(device.pushkey)
log.warning(
"Rejecting pushkey(s) due to misconfigured default_payload, "
"please ensure that default_payload is a dict."
)
return pushkeys

headers = {
"User-Agent": ["sygnal"],
Expand Down Expand Up @@ -432,7 +436,7 @@ def _build_data(n: Notification, device: Device) -> Optional[Dict[str, Any]]:
if isinstance(default_payload, dict):
data.update(default_payload)
else:
logger.error(
logger.warning(
"default_payload was misconfigured, this value must be a dict."
)
return None
Expand Down
2 changes: 1 addition & 1 deletion tests/test_gcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def test_misformed_default_payload_rejected(self):
)

self.assertEqual(resp, {"rejected": ["badpayload"]})
self.assertEqual(gcm.num_requests, 1)
self.assertEqual(gcm.num_requests, 0)

def test_rejected(self):
"""
Expand Down

0 comments on commit cac851b

Please sign in to comment.