A free open source IT asset/license management system
Fix for #19851 - Jamf Pro asset tag
snipeccb5bee452c0
diff --git a/app/SyncAdapters/Jamf/JamfAdapter.php b/app/SyncAdapters/Jamf/JamfAdapter.phpindex 3f016361f5..7c700ab604 100644--- a/app/SyncAdapters/Jamf/JamfAdapter.php+++ b/app/SyncAdapters/Jamf/JamfAdapter.php@@ -258,9 +258,9 @@ class JamfAdapter extends SyncAdapter implements PushableAdapter/*** Push Snipe-IT-authoritative fields to Jamf Pro via the newer* JSON detail endpoint. The payload uses Jamf's nested-object- * shape (assetTag lives inside userAndLocation, not at the top- * level), so sourceFieldToJamfPath() returns dotted paths that- * get assembled via Arr::set before the PATCH.+ * shape (assetTag lives inside general per the ComputerGeneralUpdate+ * schema, not userAndLocation), so sourceFieldToJamfPath() returns+ * dotted paths that get assembled via Arr::set before the PATCH.** @param array<int, string> $changedFields*/@@ -325,7 +325,12 @@ class JamfAdapter extends SyncAdapter implements PushableAdapterprivate static function sourceFieldToJamfPath(string $field): ?string{return match ($field) {- 'asset_tag' => 'userAndLocation.assetTag',+ // Jamf's ComputerGeneralUpdate schema is where assetTag+ // lives. userAndLocation does NOT accept assetTag on the+ // PATCH side (confirmed against Jamf Pro 11.32 OpenAPI+ // schema, see issue #19851). The pull side already reads+ // from general.assetTag, so push matches.+ 'asset_tag' => 'general.assetTag',default => null,};}diff --git a/app/SyncAdapters/Jamf/JamfClient.php b/app/SyncAdapters/Jamf/JamfClient.phpindex a4983f78b0..9ad76bf4c2 100644--- a/app/SyncAdapters/Jamf/JamfClient.php+++ b/app/SyncAdapters/Jamf/JamfClient.php@@ -142,8 +142,8 @@ class JamfClient/*** Update a computer's inventory detail via Jamf Pro's newer JSON- * API. Accepts a partial payload with nested objects like- * `userAndLocation` (assetTag lives at userAndLocation.assetTag).+ * API. Accepts a partial payload with nested objects like `general`+ * (assetTag lives at general.assetTag per ComputerGeneralUpdate).* Fields the caller doesn't include stay untouched.** @param array<string, mixed> $payloaddiff --git a/tests/Feature/SyncAdapters/Jamf/JamfPushTest.php b/tests/Feature/SyncAdapters/Jamf/JamfPushTest.phpindex 40b5dd5ad9..a7f39928b7 100644--- a/tests/Feature/SyncAdapters/Jamf/JamfPushTest.php+++ b/tests/Feature/SyncAdapters/Jamf/JamfPushTest.php@@ -15,9 +15,9 @@ use Tests\TestCase;/*** End-to-end coverage for the Jamf Pro push path. Verifies the- * PushableAdapter interface, the PATCH payload shape (nested- * userAndLocation.assetTag path per Jamf's inventory-detail JSON),- * and dry-run behavior.+ * PushableAdapter interface, the PATCH payload shape (asset_tag+ * writes to general.assetTag per Jamf's ComputerGeneralUpdate+ * schema), and dry-run behavior.*/class JamfPushTest extends TestCase{@@ -32,8 +32,13 @@ class JamfPushTest extends TestCase$this->assertInstanceOf(PushableAdapter::class, $this->configuredJamf());}- public function test_push_asset_tag_sends_patch_with_nested_user_and_location_path()+ public function test_push_asset_tag_writes_to_general_asset_tag_path(){+ // Regression pin for issue #19851. Jamf Pro's PATCH /api/v1/+ // computers-inventory-detail accepts assetTag only on the+ // `general` object (ComputerGeneralUpdate), never on+ // `userAndLocation`. A push to the wrong path would be a+ // silent no-op against a real tenant.$adapter = $this->configuredJamf();$instance = SyncAdapterInstance::where('slug', 'jamf')->firstOrFail();SyncAdapterConfig::put($instance->id, 'direction.asset_tag', 'push');@@ -61,7 +66,8 @@ class JamfPushTest extends TestCaseHttp::assertSent(function ($request) {return $request->method() === 'PATCH'&& str_contains($request->url(), '/api/v1/computers-inventory-detail/jamf-computer-id-42')- && ($request->data()['userAndLocation']['assetTag'] ?? null) === 'SNIPE-JAMF-42';+ && ($request->data()['general']['assetTag'] ?? null) === 'SNIPE-JAMF-42'+ && ! isset($request->data()['userAndLocation']['assetTag']);});}