Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow APNS tokens of variable length. #678

Merged
merged 1 commit into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions push_notifications/api/rest_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ class Meta(DeviceSerializerMixin.Meta):
model = APNSDevice

def validate_registration_id(self, value):
# iOS device tokens are 256-bit hexadecimal (64 characters). In 2016 Apple is increasing
# iOS device tokens to 100 bytes hexadecimal (200 characters).

if hex_re.match(value) is None or len(value) not in (64, 200):
# https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622958-application
# As of 02/2023 APNS tokens (registration_id) "are of variable length. Do not hard-code their size."

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# As of 02/2023 APNS tokens (registration_id) "are of variable length. Do not hard-code their size."
# As of 02/2023, APNs device tokens (registration_id) are of variable length. Do not hard-code their size.

if hex_re.match(value) is None:
raise ValidationError("Registration ID (device token) is invalid")

return value
Expand Down
8 changes: 8 additions & 0 deletions tests/test_rest_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def test_validation(self):
})
self.assertTrue(serializer.is_valid())

# valid data - 200 bytes mixed case
serializer = APNSDeviceSerializer(data={
"registration_id": "aE" * 200,
"name": "Apple iPhone 6+",
"device_id": "ffffffffffffffffffffffffffffffff",
})
self.assertTrue(serializer.is_valid())

# invalid data - device_id, registration_id
serializer = APNSDeviceSerializer(data={
"registration_id": "invalid device token contains no hex",
Expand Down