Skip to content

Commit b83993c

Browse files
committed
Adds support for large iOS device tokens
- Changed max_length for registration_id to 200 from 64 - Added tests for 100 bytes device tokens - Changed Validation condition check in APNSDeviceSerializer - Changes to comments and readme - Added migrations
1 parent 6988afd commit b83993c

File tree

5 files changed

+43
-7
lines changed

5 files changed

+43
-7
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ ViewSets are available for both APNS and GCM devices in two permission flavors:
175175
- Permissions are ``IsAuthenticated`` and custom permission ``IsOwner``, which will only allow the ``request.user`` to get and update devices that belong to that user
176176
- Requires a user to be authenticated, so all devices will be associated with a user
177177

178-
When creating an ``APNSDevice``, the ``registration_id`` is validated to be a 64-character hexadecimal string.
178+
When creating an ``APNSDevice``, the ``registration_id`` is validated to be a 64-character or 200-character hexadecimal string. Since 2016, device tokens are to be increased from 32 bytes to 100 bytes.
179179

180180
Routes can be added one of two ways:
181181

push_notifications/api/rest_framework.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ class Meta(DeviceSerializerMixin.Meta):
4747
model = APNSDevice
4848

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

52-
if hex_re.match(value) is None or len(value) != 64:
53+
if hex_re.match(value) is None or len(value) not in (64, 200):
5354
raise ValidationError("Registration ID (device token) is invalid")
5455

5556
return value
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.9.1 on 2016-01-06 08:50
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('push_notifications', '0001_initial'),
12+
]
13+
14+
operations = [
15+
migrations.AlterField(
16+
model_name='apnsdevice',
17+
name='registration_id',
18+
field=models.CharField(max_length=200, unique=True, verbose_name='Registration ID'),
19+
),
20+
]

push_notifications/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def send_message(self, message, **kwargs):
8080
class APNSDevice(Device):
8181
device_id = models.UUIDField(verbose_name=_("Device ID"), blank=True, null=True, db_index=True,
8282
help_text="UDID / UIDevice.identifierForVendor()")
83-
registration_id = models.CharField(verbose_name=_("Registration ID"), max_length=64, unique=True)
83+
registration_id = models.CharField(verbose_name=_("Registration ID"), max_length=200, unique=True)
8484

8585
objects = APNSDeviceManager()
8686

tests/test_rest_framework.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,38 @@
66

77
class APNSDeviceSerializerTestCase(TestCase):
88
def test_validation(self):
9-
# valid data - upper case
9+
# valid data - 32 bytes upper case
1010
serializer = APNSDeviceSerializer(data={
1111
"registration_id": "AEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAE",
1212
"name": "Apple iPhone 6+",
1313
"device_id": "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
1414
})
1515
self.assertTrue(serializer.is_valid())
1616

17-
# valid data - lower case
17+
# valid data - 32 bytes lower case
1818
serializer = APNSDeviceSerializer(data={
1919
"registration_id": "aeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeae",
2020
"name": "Apple iPhone 6+",
2121
"device_id": "ffffffffffffffffffffffffffffffff",
2222
})
2323
self.assertTrue(serializer.is_valid())
2424

25+
# valid data - 100 bytes upper case
26+
serializer = APNSDeviceSerializer(data={
27+
"registration_id": "AEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAE",
28+
"name": "Apple iPhone 6+",
29+
"device_id": "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
30+
})
31+
self.assertTrue(serializer.is_valid())
32+
33+
# valid data - 100 bytes lower case
34+
serializer = APNSDeviceSerializer(data={
35+
"registration_id": "aeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeae",
36+
"name": "Apple iPhone 6+",
37+
"device_id": "ffffffffffffffffffffffffffffffff",
38+
})
39+
self.assertTrue(serializer.is_valid())
40+
2541
# invalid data - device_id, registration_id
2642
serializer = APNSDeviceSerializer(data={
2743
"registration_id": "invalid device token contains no hex",
@@ -102,4 +118,3 @@ def test_device_id_validation_value_between_signed_unsigned_64b_int_maximums(sel
102118
"device_id": "e87a4e72d634997c",
103119
})
104120
self.assertTrue(serializer.is_valid())
105-

0 commit comments

Comments
 (0)