Skip to content

A free open source IT asset/license management system

Fixed #19693 - added apple’s built in MDM for AxM adapter

snipe47742dd976b4
diff --git a/app/SyncAdapters/AppleBusinessManager/AppleBusinessManagerAdapter.php b/app/SyncAdapters/AppleBusinessManager/AppleBusinessManagerAdapter.php
index 436ebe77ce..02ee185ebe 100644
--- a/app/SyncAdapters/AppleBusinessManager/AppleBusinessManagerAdapter.php
+++ b/app/SyncAdapters/AppleBusinessManager/AppleBusinessManagerAdapter.php
@@ -253,6 +253,19 @@ class AppleBusinessManagerAdapter extends SyncAdapter
'abm_released_from_org' => ['label_key' => 'admin/settings/sync_adapters.abm_extra_released_from_org'],
'abm_org_status' => ['label_key' => 'admin/settings/sync_adapters.abm_extra_org_status'],
'abm_activation_lock_enabled' => ['label_key' => 'admin/settings/sync_adapters.abm_extra_activation_lock_enabled', 'type' => 'boolean'],
+ // Apple Business Manager's built-in MDM (formerly Apple
+ // Business Essentials). Native slots (hostname, os,
+ // osVersion, lastSeen, primaryMac, imei, meid) are
+ // overridden from the MDM detail endpoint when we have it
+ // since MDM is runtime truth. The extras below are the
+ // MDM-only fields that don't correspond to native slots.
+ 'abm_mdm_file_vault_enabled' => ['label_key' => 'admin/settings/sync_adapters.abm_extra_mdm_file_vault_enabled', 'type' => 'boolean'],
+ 'abm_mdm_firewall_enabled' => ['label_key' => 'admin/settings/sync_adapters.abm_extra_mdm_firewall_enabled', 'type' => 'boolean'],
+ 'abm_mdm_device_lock_status' => ['label_key' => 'admin/settings/sync_adapters.abm_extra_mdm_device_lock_status'],
+ 'abm_mdm_lost_mode_status' => ['label_key' => 'admin/settings/sync_adapters.abm_extra_mdm_lost_mode_status'],
+ 'abm_mdm_device_erase_status' => ['label_key' => 'admin/settings/sync_adapters.abm_extra_mdm_device_erase_status'],
+ 'abm_mdm_storage_total' => ['label_key' => 'admin/settings/sync_adapters.abm_extra_mdm_storage_total'],
+ 'abm_mdm_storage_free' => ['label_key' => 'admin/settings/sync_adapters.abm_extra_mdm_storage_free'],
];
}
@@ -363,6 +376,32 @@ class AppleBusinessManagerAdapter extends SyncAdapter
// unless the admin has mapped the extra.
$enrichWithActivationLock = $this->hasMappedActivationLockField();
+ // Apple Business Manager's built-in MDM (formerly Apple
+ // Business Essentials). The list endpoint is one call per sync
+ // run and gives us hostname + os, so we always fetch it.
+ // Build a serial -> mdmDevice basic-info map for the join.
+ // Best-effort: failures leave the map empty and records stay
+ // un-enriched.
+ $serialToMdmDevice = [];
+ try {
+ foreach ($client->mdmDevices() as $mdmDevice) {
+ $serial = (string) ($mdmDevice['id'] ?? '');
+ if ($serial !== '') {
+ $serialToMdmDevice[$serial] = $mdmDevice;
+ }
+ }
+ } catch (\Throwable $e) {
+ \Log::channel('sync-adapters')->warning(sprintf(
+ '%s mdmDevices list fetch failed: %s',
+ $this->name(),
+ $e->getMessage(),
+ ));
+ }
+
+ // Detail endpoint is one call per MDM-enrolled device, so it's
+ // gated behind at least one MDM-detail extra being mapped.
+ $enrichWithMdmDetail = $this->hasMappedMdmDeviceDetailFields();
+
// Allowed product families (lower-cased for comparison).
// Empty means "all families".
$allowedFamilies = $this->allowedProductFamilies();
@@ -386,6 +425,13 @@ class AppleBusinessManagerAdapter extends SyncAdapter
if ($enrichWithActivationLock) {
$record = $this->enrichRecordWithActivationLock($record, $client);
}
+ $mdmDevice = $serialToMdmDevice[$record->hardwareSerial] ?? null;
+ if ($mdmDevice !== null) {
+ $record = $this->enrichRecordWithMdmDeviceBasics($record, $mdmDevice);
+ if ($enrichWithMdmDetail) {
+ $record = $this->enrichRecordWithMdmDeviceDetail($record, $client);
+ }
+ }
if ($pullImages) {
$imagesHandled = $this->ensureModelImage($record, $imagesHandled);
}
@@ -588,6 +634,28 @@ class AppleBusinessManagerAdapter extends SyncAdapter
return $target !== '' && $target !== 'skip';
}
+ /**
+ * Gate for the MDM device-detail enrichment. True when the admin
+ * has mapped any of the detail-endpoint-only extras (FileVault,
+ * firewall, lock/lost/erase status, storage). The list-endpoint
+ * enrichment (hostname + os) always runs regardless since the list
+ * fetch is one call total.
+ */
+ private function hasMappedMdmDeviceDetailFields(): bool
+ {
+ foreach (array_keys($this->extraFields()) as $key) {
+ if (! str_starts_with($key, 'abm_mdm_')) {
+ continue;
+ }
+ $target = $this->mappingFor($key);
+ if ($target !== '' && $target !== 'skip') {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
/**
* Fetch AppleCare coverage for one asset, pick the most relevant
* plan, and merge its fields into the record's extras. On empty
@@ -694,6 +762,145 @@ class AppleBusinessManagerAdapter extends SyncAdapter
);
}
+ /**
+ * Merge the cheap MDM-list-endpoint fields onto the record.
+ * Populates hostname (deviceName) and os (derived from
+ * productFamily). Called only when we have a matching mdmDevice
+ * for this record's serial.
+ *
+ * @param array<string, mixed> $mdmDevice
+ */
+ private function enrichRecordWithMdmDeviceBasics(HostInventoryRecord $record, array $mdmDevice): HostInventoryRecord
+ {
+ $attrs = $mdmDevice['attributes'] ?? [];
+ $deviceName = Arr::get($attrs, 'deviceName');
+ $family = (string) Arr::get($attrs, 'productFamily', '');
+
+ return new HostInventoryRecord(
+ sourceKey: $record->sourceKey,
+ sourceId: $record->sourceId,
+ hostname: is_string($deviceName) && $deviceName !== '' ? $deviceName : $record->hostname,
+ hardwareSerial: $record->hardwareSerial,
+ hardwareModel: $record->hardwareModel,
+ manufacturer: $record->manufacturer,
+ primaryMac: $record->primaryMac,
+ primaryIp: $record->primaryIp,
+ os: self::osFromProductFamily($family) ?? $record->os,
+ osVersion: $record->osVersion,
+ lastSeen: $record->lastSeen,
+ assetTag: $record->assetTag,
+ assignedUserEmail: $record->assignedUserEmail,
+ assignedUserName: $record->assignedUserName,
+ vendorGroupId: $record->vendorGroupId,
+ extra: $record->extra,
+ );
+ }
+
+ /**
+ * Fetch and merge the per-device MDM detail endpoint fields.
+ * Runtime data wins: MDM's osVersion, lastCheckInDateTime, MAC
+ * addresses, imei, meid override whatever the orgDevices path
+ * populated. FileVault, firewall, lock/lost/erase statuses, and
+ * storage go into extras. On empty or failed responses return
+ * the un-enriched record so a transient MDM detail-endpoint issue
+ * doesn't stall the sync.
+ */
+ private function enrichRecordWithMdmDeviceDetail(HostInventoryRecord $record, AppleBusinessManagerClient $client): HostInventoryRecord
+ {
+ try {
+ $detail = $client->mdmDeviceDetails($record->hardwareSerial);
+ } catch (\Throwable $e) {
+ \Log::channel('sync-adapters')->warning(sprintf(
+ '%s mdmDevice detail fetch failed for device %s: %s',
+ $this->name(),
+ $record->sourceId,
+ $e->getMessage(),
+ ));
+
+ return $record;
+ }
+
+ $attrs = $detail['attributes'] ?? [];
+ if (! is_array($attrs) || $attrs === []) {
+ return $record;
+ }
+
+ $extra = $record->extra;
+ $extra['abm_mdm_file_vault_enabled'] = Arr::get($attrs, 'isFileVaultEnabled');
+ $extra['abm_mdm_firewall_enabled'] = Arr::get($attrs, 'isFirewallEnabled');
+ $extra['abm_mdm_device_lock_status'] = Arr::get($attrs, 'deviceLockStatus');
+ $extra['abm_mdm_lost_mode_status'] = Arr::get($attrs, 'lostModeStatus');
+ $extra['abm_mdm_device_erase_status'] = Arr::get($attrs, 'deviceEraseStatus');
+ $extra['abm_mdm_storage_total'] = Arr::get($attrs, 'storageTotalCapacity');
+ $extra['abm_mdm_storage_free'] = Arr::get($attrs, 'storageFreeCapacity');
+
+ // Prefer MDM values for the shared extras (Wi-Fi/Ethernet MACs
+ // etc.) when the detail endpoint has them. orgDevices values
+ // stay as fallbacks.
+ foreach (['wifiMacAddress' => 'abm_wifi_mac',
+ 'bluetoothMacAddress' => 'abm_bluetooth_mac',
+ 'ethernetMacAddress' => 'abm_ethernet_mac',
+ 'imei' => 'abm_imei',
+ 'meid' => 'abm_meid',
+ ] as $mdmKey => $extraKey) {
+ $val = Arr::get($attrs, $mdmKey);
+ if ($val !== null && $val !== '') {
+ $extra[$extraKey] = $val;
+ }
+ }
+
+ // MDM's runtime data overrides the orgDevices values for
+ // native slots when populated.
+ $wifiMac = Arr::get($attrs, 'wifiMacAddress');
+ $ethernetMac = Arr::get($attrs, 'ethernetMacAddress');
+ $osVersion = Arr::get($attrs, 'osVersion');
+ $lastCheckIn = Arr::get($attrs, 'lastCheckInDateTime');
+
+ return new HostInventoryRecord(
+ sourceKey: $record->sourceKey,
+ sourceId: $record->sourceId,
+ hostname: $record->hostname,
+ hardwareSerial: $record->hardwareSerial,
+ hardwareModel: $record->hardwareModel,
+ manufacturer: $record->manufacturer,
+ // Prefer Wi-Fi, fall back to Ethernet (desktops without
+ // Wi-Fi), then whatever the orgDevices path set.
+ primaryMac: (is_string($wifiMac) && $wifiMac !== '')
+ ? $wifiMac
+ : ((is_string($ethernetMac) && $ethernetMac !== '') ? $ethernetMac : $record->primaryMac),
+ primaryIp: $record->primaryIp,
+ os: $record->os,
+ osVersion: (is_string($osVersion) && $osVersion !== '') ? $osVersion : $record->osVersion,
+ lastSeen: (is_string($lastCheckIn) && $lastCheckIn !== '')
+ ? \Carbon\Carbon::parse($lastCheckIn)
+ : $record->lastSeen,
+ assetTag: $record->assetTag,
+ assignedUserEmail: $record->assignedUserEmail,
+ assignedUserName: $record->assignedUserName,
+ vendorGroupId: $record->vendorGroupId,
+ extra: $extra,
+ );
+ }
+
+ /**
+ * Apple's productFamily enum to the runtime OS name customers
+ * expect to see in the assets table. Returns null for families
+ * without a well-known OS name so callers can leave the field
+ * alone rather than blanking it.
+ */
+ private static function osFromProductFamily(string $family): ?string
+ {
+ return match ($family) {
+ 'Mac' => 'macOS',
+ 'iPhone' => 'iOS',
+ 'iPad' => 'iPadOS',
+ 'AppleTV' => 'tvOS',
+ 'Watch' => 'watchOS',
+ 'Vision' => 'visionOS',
+ default => null,
+ };
+ }
+
/**
* Pick the most relevant AppleCare coverage plan for a device.
* A device can carry multiple overlapping plans (renewals,
diff --git a/app/SyncAdapters/AppleBusinessManager/AppleBusinessManagerClient.php b/app/SyncAdapters/AppleBusinessManager/AppleBusinessManagerClient.php
index 7134f4aadb..e7ec23c7bd 100644
--- a/app/SyncAdapters/AppleBusinessManager/AppleBusinessManagerClient.php
+++ b/app/SyncAdapters/AppleBusinessManager/AppleBusinessManagerClient.php
@@ -114,6 +114,58 @@ class AppleBusinessManagerClient
return $response['data'] ?? [];
}
+ /**
+ * List every device enrolled in Apple Business Manager's built-in
+ * MDM (formerly Apple Business Essentials, now folded into AxM).
+ * Cheap: one call per sync run. The id on each entry IS the
+ * device's serial number, so the adapter joins straight to
+ * orgDevices by serial. Records that don't appear here just
+ * aren't enrolled in the built-in MDM and stay un-enriched.
+ *
+ * @return iterable<int, array<string, mixed>>
+ */
+ public function mdmDevices(int $pageSize = 100): iterable
+ {
+ $cursor = null;
+
+ do {
+ $params = ['limit' => $pageSize];
+ if (is_string($cursor)) {
+ $params['cursor'] = $cursor;
+ }
+
+ $response = $this->request()
+ ->get('/v1/mdmDevices', $params)
+ ->throw()
+ ->json();
+
+ foreach ($response['data'] ?? [] as $device) {
+ yield $device;
+ }
+
+ $cursor = $response['meta']['paging']['nextCursor'] ?? null;
+ } while (is_string($cursor) && $cursor !== '');
+ }
+
+ /**
+ * Fetch runtime detail for one MDM-enrolled device: osVersion,
+ * lastCheckInDateTime, MAC addresses, storage, security posture
+ * (FileVault, firewall, lock/lost/erase statuses). One call per
+ * device, so gated behind hasMappedMdmDeviceDetailFields() at
+ * the adapter side.
+ *
+ * @return array<string, mixed>
+ */
+ public function mdmDeviceDetails(string $serial): array
+ {
+ $response = $this->request()
+ ->get('/v1/mdmDevices/'.$serial.'/details')
+ ->throw()
+ ->json();
+
+ return $response['data'] ?? [];
+ }
+
/**
* Build a device-id -> MDM server name map by walking every MDM
* server's device linkages. Devices unassigned to any MDM server
diff --git a/resources/lang/en-US/admin/settings/sync_adapters.php b/resources/lang/en-US/admin/settings/sync_adapters.php
index 2ac473489a..4cefa23ba9 100644
--- a/resources/lang/en-US/admin/settings/sync_adapters.php
+++ b/resources/lang/en-US/admin/settings/sync_adapters.php
@@ -398,4 +398,11 @@ return [
'abm_extra_released_from_org' => 'AxM Released from Org',
'abm_extra_org_status' => 'AxM Org Status',
'abm_extra_activation_lock_enabled' => 'AxM Activation Lock Enabled',
+ 'abm_extra_mdm_file_vault_enabled' => 'AxM MDM FileVault Enabled',
+ 'abm_extra_mdm_firewall_enabled' => 'AxM MDM Firewall Enabled',
+ 'abm_extra_mdm_device_lock_status' => 'AxM MDM Device Lock Status',
+ 'abm_extra_mdm_lost_mode_status' => 'AxM MDM Lost Mode Status',
+ 'abm_extra_mdm_device_erase_status' => 'AxM MDM Device Erase Status',
+ 'abm_extra_mdm_storage_total' => 'AxM MDM Storage Total',
+ 'abm_extra_mdm_storage_free' => 'AxM MDM Storage Free',
];
diff --git a/tests/Feature/SyncAdapters/AppleBusinessManager/MdmDeviceEnrichmentTest.php b/tests/Feature/SyncAdapters/AppleBusinessManager/MdmDeviceEnrichmentTest.php
new file mode 100644
index 0000000000..9129360639
--- /dev/null
+++ b/tests/Feature/SyncAdapters/AppleBusinessManager/MdmDeviceEnrichmentTest.php
@@ -0,0 +1,238 @@
+<?php
+
+namespace Tests\Feature\SyncAdapters\AppleBusinessManager;
+
+use App\Models\CustomField;
+use App\Models\Statuslabel;
+use App\Models\SyncAdapterConfig;
+use App\Models\SyncAdapterInstance;
+use App\SyncAdapters\AppleBusinessManager\AppleBusinessManagerAdapter;
+use Illuminate\Support\Facades\Crypt;
+use Illuminate\Support\Facades\Http;
+use Tests\TestCase;
+
+class MdmDeviceEnrichmentTest extends TestCase
+{
+ private string $privateKeyPem;
+
+ protected function setUp(): void
+ {
+ parent::setUp();
+ Statuslabel::factory()->rtd()->create();
+
+ $key = openssl_pkey_new([
+ 'private_key_type' => OPENSSL_KEYTYPE_EC,
+ 'curve_name' => 'prime256v1',
+ ]);
+ $pem = '';
+ openssl_pkey_export($key, $pem);
+ $this->privateKeyPem = $pem;
+ }
+
+ public function test_mdm_list_endpoint_populates_hostname_and_os()
+ {
+ // The list endpoint is always fetched. Even without any MDM
+ // detail extras mapped, we should populate hostname (deviceName)
+ // and os (derived from productFamily).
+ $adapter = $this->configuredAdapter();
+
+ Http::fake([
+ 'account.apple.com/*' => Http::response(['access_token' => 'stub-bearer']),
+ 'api-business.apple.com/v1/mdmServers' => Http::response(['data' => []]),
+ 'api-business.apple.com/v1/mdmDevices*' => Http::response([
+ 'data' => [
+ [
+ 'id' => 'SN-abm-guid-a',
+ 'type' => 'mdmDevice',
+ 'attributes' => [
+ 'deviceName' => 'ada-mbp',
+ 'productFamily' => 'Mac',
+ 'serialNumber' => 'SN-abm-guid-a',
+ ],
+ ],
+ ],
+ ]),
+ 'api-business.apple.com/v1/orgDevices*' => Http::response([
+ 'data' => [$this->minimalAbmDevice('abm-guid-a', 'SN-abm-guid-a')],
+ ]),
+ ]);
+
+ $record = iterator_to_array($adapter->pull())[0];
+ $this->assertSame('ada-mbp', $record->hostname);
+ $this->assertSame('macOS', $record->os);
+ }
+
+ public function test_pull_does_not_fetch_mdm_detail_when_no_detail_field_is_mapped()
+ {
+ // The detail endpoint is one call per device. Skip it when the
+ // admin hasn't mapped any of the MDM detail-only extras.
+ $adapter = $this->configuredAdapter();
+
+ Http::fake([
+ 'account.apple.com/*' => Http::response(['access_token' => 'stub-bearer']),
+ 'api-business.apple.com/v1/mdmServers' => Http::response(['data' => []]),
+ 'api-business.apple.com/v1/mdmDevices?*' => Http::response([
+ 'data' => [[
+ 'id' => 'SN-abm-guid-a',
+ 'type' => 'mdmDevice',
+ 'attributes' => ['deviceName' => 'ada-mbp', 'productFamily' => 'Mac'],
+ ]],
+ ]),
+ 'api-business.apple.com/v1/orgDevices*' => Http::response([
+ 'data' => [$this->minimalAbmDevice('abm-guid-a', 'SN-abm-guid-a')],
+ ]),
+ ]);
+
+ iterator_to_array($adapter->pull());
+
+ Http::assertNotSent(function ($request) {
+ return str_contains($request->url(), '/mdmDevices/SN-abm-guid-a/details');
+ });
+ }
+
+ public function test_pull_fetches_mdm_detail_when_a_detail_field_is_mapped()
+ {
+ $customField = CustomField::factory()->create(['element' => 'checkbox', 'name' => 'FileVault']);
+ $adapter = $this->configuredAdapter();
+ $instance = SyncAdapterInstance::where('slug', 'abm')->firstOrFail();
+ SyncAdapterConfig::put($instance->id, 'mapping.abm_mdm_file_vault_enabled', 'custom:'.$customField->id);
+
+ Http::fake([
+ 'account.apple.com/*' => Http::response(['access_token' => 'stub-bearer']),
+ 'api-business.apple.com/v1/mdmServers' => Http::response(['data' => []]),
+ 'api-business.apple.com/v1/mdmDevices?*' => Http::response([
+ 'data' => [[
+ 'id' => 'SN-abm-guid-a',
+ 'type' => 'mdmDevice',
+ 'attributes' => ['deviceName' => 'ada-mbp', 'productFamily' => 'Mac'],
+ ]],
+ ]),
+ 'api-business.apple.com/v1/mdmDevices/SN-abm-guid-a/details' => Http::response([
+ 'data' => [
+ 'id' => 'SN-abm-guid-a',
+ 'type' => 'mdmDeviceDetail',
+ 'attributes' => [
+ 'osVersion' => '15.1.1',
+ 'lastCheckInDateTime' => '2026-09-20T14:22:00Z',
+ 'wifiMacAddress' => 'AA:BB:CC:00:11:22',
+ 'ethernetMacAddress' => 'AA:BB:CC:00:11:33',
+ 'isFileVaultEnabled' => true,
+ 'isFirewallEnabled' => false,
+ 'deviceLockStatus' => 'UNLOCKED',
+ 'lostModeStatus' => 'DISABLED',
+ 'deviceEraseStatus' => 'NORMAL',
+ 'storageTotalCapacity' => 494,
+ 'storageFreeCapacity' => 353,
+ ],
+ ],
+ ]),
+ 'api-business.apple.com/v1/orgDevices*' => Http::response([
+ 'data' => [$this->minimalAbmDevice('abm-guid-a', 'SN-abm-guid-a')],
+ ]),
+ ]);
+
+ $record = iterator_to_array($adapter->pull())[0];
+
+ // Native slots overridden from MDM runtime data.
+ $this->assertSame('15.1.1', $record->osVersion);
+ $this->assertSame('AA:BB:CC:00:11:22', $record->primaryMac);
+ $this->assertNotNull($record->lastSeen);
+ $this->assertSame('2026-09-20', $record->lastSeen->toDateString());
+
+ // MDM-only extras populated.
+ $this->assertTrue($record->extra['abm_mdm_file_vault_enabled']);
+ $this->assertFalse($record->extra['abm_mdm_firewall_enabled']);
+ $this->assertSame('UNLOCKED', $record->extra['abm_mdm_device_lock_status']);
+ $this->assertSame('DISABLED', $record->extra['abm_mdm_lost_mode_status']);
+ $this->assertSame('NORMAL', $record->extra['abm_mdm_device_erase_status']);
+ $this->assertSame(494, $record->extra['abm_mdm_storage_total']);
+ $this->assertSame(353, $record->extra['abm_mdm_storage_free']);
+ }
+
+ public function test_ethernet_mac_used_when_wifi_missing()
+ {
+ // Desktops without Wi-Fi (Mac Studio, Mac Pro) still report an
+ // Ethernet MAC. When Wi-Fi is null, fall back to Ethernet for
+ // the native primaryMac slot.
+ $customField = CustomField::factory()->create(['element' => 'checkbox', 'name' => 'FileVault']);
+ $adapter = $this->configuredAdapter();
+ $instance = SyncAdapterInstance::where('slug', 'abm')->firstOrFail();
+ SyncAdapterConfig::put($instance->id, 'mapping.abm_mdm_file_vault_enabled', 'custom:'.$customField->id);
+
+ Http::fake([
+ 'account.apple.com/*' => Http::response(['access_token' => 'stub-bearer']),
+ 'api-business.apple.com/v1/mdmServers' => Http::response(['data' => []]),
+ 'api-business.apple.com/v1/mdmDevices?*' => Http::response([
+ 'data' => [[
+ 'id' => 'SN-mac-studio',
+ 'type' => 'mdmDevice',
+ 'attributes' => ['deviceName' => 'studio-01', 'productFamily' => 'Mac'],
+ ]],
+ ]),
+ 'api-business.apple.com/v1/mdmDevices/SN-mac-studio/details' => Http::response([
+ 'data' => [
+ 'id' => 'SN-mac-studio',
+ 'type' => 'mdmDeviceDetail',
+ 'attributes' => [
+ 'wifiMacAddress' => null,
+ 'ethernetMacAddress' => 'AA:BB:CC:00:11:99',
+ ],
+ ],
+ ]),
+ 'api-business.apple.com/v1/orgDevices*' => Http::response([
+ 'data' => [$this->minimalAbmDevice('mac-studio-guid', 'SN-mac-studio')],
+ ]),
+ ]);
+
+ $record = iterator_to_array($adapter->pull())[0];
+ $this->assertSame('AA:BB:CC:00:11:99', $record->primaryMac);
+ }
+
+ public function test_records_without_a_matching_mdm_device_stay_un_enriched()
+ {
+ // 146/152 in the reporter's tenant were MDM-enrolled. The
+ // remaining 6 have no mdmDevice record. They should sync
+ // cleanly with the orgDevices values instead of crashing or
+ // dropping.
+ $adapter = $this->configuredAdapter();
+
+ Http::fake([
+ 'account.apple.com/*' => Http::response(['access_token' => 'stub-bearer']),
+ 'api-business.apple.com/v1/mdmServers' => Http::response(['data' => []]),
+ 'api-business.apple.com/v1/mdmDevices?*' => Http::response(['data' => []]),
+ 'api-business.apple.com/v1/orgDevices*' => Http::response([
+ 'data' => [$this->minimalAbmDevice('non-mdm-guid', 'SN-non-mdm')],
+ ]),
+ ]);
+
+ $record = iterator_to_array($adapter->pull())[0];
+ $this->assertNull($record->hostname);
+ $this->assertNull($record->os);
+ }
+
+ private function configuredAdapter(): AppleBusinessManagerAdapter
+ {
+ $instance = SyncAdapterInstance::where('slug', 'abm')->firstOrFail();
+ SyncAdapterConfig::put($instance->id, 'mode', 'business');
+ SyncAdapterConfig::put($instance->id, 'client_id', 'stub-client-id');
+ SyncAdapterConfig::put($instance->id, 'key_id', 'stub-key-id');
+ SyncAdapterConfig::put($instance->id, 'private_key', Crypt::encrypt($this->privateKeyPem));
+
+ return new AppleBusinessManagerAdapter($instance->fresh());
+ }
+
+ /**
+ * @return array<string, mixed>
+ */
+ private function minimalAbmDevice(string $id, string $serial): array
+ {
+ return [
+ 'id' => $id,
+ 'attributes' => [
+ 'serialNumber' => $serial,
+ 'partNumber' => 'MK1E3LL/A',
+ 'productFamily' => 'Mac',
+ ],
+ ];
+ }
+}