Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ The `file_uri` and `file_sha256` attributes of the data asset endpoints are not

Zentral uses version 10 of the Apple device assignment protocol now, and not version 3. Apple sends more device attributes with it. The web console and the DEP device endpoints show them: the Wi-Fi, Bluetooth and Ethernet MAC addresses, the EID, the IMEI and MEID numbers, the MDM migration deadline, and if the device replaces another one. The list endpoint has a new `is_replacement_device` filter.

The MDM migration deadline is the one Apple reports. Apple keeps reporting it when it is removed in Apple Business Manager, and clears it only when the device changes MDM server, so Zentral shows it until then too. A refresh of the device keeps it: Apple leaves it out of the device details.

Only the devices that a synchronization reports get the new attributes. A delta synchronization reports the devices that changed, so a full synchronization (`?full_sync=true`) is necessary to get the attributes of all the devices. It posts one `dep_device_change` event per device, one time only: the new attributes get their value, and the `os` of an iPad changes from `iOS` to `iPadOS`.

Apple can throttle the assignment of the default enrollment. Zentral counts the throttled devices apart from the failed ones now, and assigns them again after the delay Apple gives.
Expand Down
120 changes: 120 additions & 0 deletions tests/mdm/test_dep.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
assign_dep_virtual_server_default_enrollment,
define_dep_profile,
iter_unassigned_dep_device_serial_numbers,
refresh_dep_device,
sync_dep_virtual_server_devices,
)
from zentral.contrib.mdm.dep_client import (
Expand Down Expand Up @@ -599,6 +600,125 @@ def device_iterator():
self.assertEqual(dep_device.last_op_date, datetime(2026, 8, 24, 12, 0, 0))
self.assertFalse(dep_device.is_deleted())

# MDM migration deadline

def force_dep_device_with_migration_deadline(self, server):
dep_device = force_dep_device(server=server, profile_status=DEPDevice.PROFILE_STATUS_EMPTY)
DEPDevice.objects.filter(pk=dep_device.pk).update(mdm_migration_deadline=datetime(2026, 9, 24, 22, 0, 0),
last_op_date=None)
dep_device.refresh_from_db()
return dep_device

@patch("zentral.contrib.mdm.dep.DEPClient.from_dep_token")
def test_sync_dep_virtual_server_devices_mdm_server_change_clears_the_migration_deadline(self, from_dep_token):
server = self.force_synced_server()
dep_device = self.force_dep_device_with_migration_deadline(server)

def device_iterator():
# the device moved to another MDM server
yield from [{'op_date': '2026-09-25T08:00:00Z',
'op_type': 'deleted',
'serial_number': dep_device.serial_number}]
return get_random_string(12)

client = Mock()
client.sync_devices.return_value = CursorIterator(device_iterator())
from_dep_token.return_value = client
list(sync_dep_virtual_server_devices(server))
dep_device.refresh_from_db()
self.assertEqual(dep_device.last_op_type, DEPDevice.OP_TYPE_DELETED)
self.assertIsNone(dep_device.mdm_migration_deadline)

@patch("zentral.contrib.mdm.dep.DEPClient.from_dep_token")
def test_sync_dep_virtual_server_devices_keeps_the_migration_deadline(self, from_dep_token):
server = self.force_synced_server()
dep_device = self.force_dep_device_with_migration_deadline(server)

def device_iterator():
yield from [{'op_date': '2026-09-25T08:00:00Z',
'op_type': 'modified',
'profile_status': 'empty',
'serial_number': dep_device.serial_number}]
return get_random_string(12)

client = Mock()
client.sync_devices.return_value = CursorIterator(device_iterator())
from_dep_token.return_value = client
list(sync_dep_virtual_server_devices(server))
dep_device.refresh_from_db()
self.assertEqual(dep_device.last_op_type, DEPDevice.OP_TYPE_MODIFIED)
self.assertEqual(dep_device.mdm_migration_deadline, datetime(2026, 9, 24, 22, 0, 0))

@patch("zentral.contrib.mdm.dep.DEPClient.from_dep_virtual_server")
def test_assign_dep_virtual_server_default_enrollment_keeps_the_migration_deadline(self, from_dep_virtual_server):
server, enrollment = self.force_server_with_default_enrollment()
dep_device = self.force_dep_device_with_migration_deadline(server)
client = Mock()
client.get_device_batch_size.return_value = DEVICE_BATCH_SIZE
client.assign_profile.return_value = {"devices": {dep_device.serial_number: "SUCCESS"}}
client.get_devices.return_value = {
dep_device.serial_number: {
"profile_uuid": str(enrollment.uuid).upper().replace("-", ""),
"profile_status": "assigned",
"profile_assign_time": "2026-09-24T10:45:02Z",
}
}
from_dep_virtual_server.return_value = client

self.assertEqual(assign_dep_virtual_server_default_enrollment(server)["assigned"], 1)
dep_device.refresh_from_db()
self.assertEqual(dep_device.enrollment, enrollment)
self.assertEqual(dep_device.mdm_migration_deadline, datetime(2026, 9, 24, 22, 0, 0))

@patch("zentral.contrib.mdm.dep.DEPClient.from_dep_virtual_server")
def test_assign_dep_device_profile_keeps_the_migration_deadline(self, from_dep_virtual_server):
server, enrollment = self.force_server_with_default_enrollment()
dep_device = self.force_dep_device_with_migration_deadline(server)
client = Mock()
client.assign_profile.return_value = {"devices": {dep_device.serial_number: "SUCCESS"}}
client.get_devices.return_value = {
dep_device.serial_number: {
"profile_uuid": str(enrollment.uuid).upper().replace("-", ""),
"profile_status": "assigned",
"profile_assign_time": "2026-09-24T10:45:02Z",
}
}
from_dep_virtual_server.return_value = client

assign_dep_device_profile(dep_device, enrollment)
dep_device.refresh_from_db()
self.assertEqual(dep_device.enrollment, enrollment)
self.assertEqual(dep_device.mdm_migration_deadline, datetime(2026, 9, 24, 22, 0, 0))

@patch("zentral.contrib.mdm.dep.DEPClient.from_dep_virtual_server")
def test_refresh_dep_device_keeps_the_migration_deadline(self, from_dep_virtual_server):
dep_device = self.force_dep_device_with_migration_deadline(force_dep_virtual_server())
client = Mock()
client.get_devices.return_value = {
dep_device.serial_number: {"profile_status": "empty",
"serial_number": dep_device.serial_number}
}
from_dep_virtual_server.return_value = client

refresh_dep_device(dep_device)
dep_device.refresh_from_db()
self.assertEqual(dep_device.mdm_migration_deadline, datetime(2026, 9, 24, 22, 0, 0))

@patch("zentral.contrib.mdm.dep.DEPClient.from_dep_virtual_server")
def test_refresh_dep_device_updates_the_migration_deadline(self, from_dep_virtual_server):
dep_device = self.force_dep_device_with_migration_deadline(force_dep_virtual_server())
client = Mock()
client.get_devices.return_value = {
dep_device.serial_number: {"mdm_migration_deadline": "2026-09-24T23:00:00Z",
"profile_status": "empty",
"serial_number": dep_device.serial_number}
}
from_dep_virtual_server.return_value = client

refresh_dep_device(dep_device)
dep_device.refresh_from_db()
self.assertEqual(dep_device.mdm_migration_deadline, datetime(2026, 9, 24, 23, 0, 0))

# events

def force_synced_server(self):
Expand Down
10 changes: 8 additions & 2 deletions zentral/contrib/mdm/dep.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ def dep_device_update_dict(device, known_enrollments=None):
if known_enrollments is None:
known_enrollments = {}
update_d = {"enrollment": None,
"mdm_migration_deadline": None,
"profile_uuid": None,
"profile_assign_time": None,
"profile_push_time": None,
Expand All @@ -175,6 +174,14 @@ def dep_device_update_dict(device, known_enrollments=None):

update_d["is_replacement_device"] = bool(device.get("is_replacement_device"))

# Apple leaves the migration deadline out of the device details even when there is one, and keeps
# reporting it in the device lists after it is removed in Apple Business Manager. Only a change of
# MDM server clears it, so an absent key leaves it alone, and a deleted operation clears it.
if "mdm_migration_deadline" in device:
update_d["mdm_migration_deadline"] = parser.parse(device["mdm_migration_deadline"])
elif device.get("op_type") == DEPDevice.OP_TYPE_DELETED:
update_d["mdm_migration_deadline"] = None

# Apple reports this one only with a deleted operation, so an absent key must leave it alone
# rather than clear it. Left out of the update dict, it is left out of the update statement.
if "released_by_replacement" in device:
Expand Down Expand Up @@ -205,7 +212,6 @@ def dep_device_update_dict(device, known_enrollments=None):

# datetime nullable attributes
for attr in ("device_assigned_date",
"mdm_migration_deadline",
"profile_assign_time",
"profile_push_time"):
try:
Expand Down
Loading