A free open source IT asset/license management system
Sync Adapters: Fixed #19917 - create assets checkbox always saving as true
snipe80fdb9a29dc2
diff --git a/app/SyncAdapters/SyncAdapter.php b/app/SyncAdapters/SyncAdapter.phpindex e3d410ad84..48d1c17305 100644--- a/app/SyncAdapters/SyncAdapter.php+++ b/app/SyncAdapters/SyncAdapter.php@@ -897,14 +897,11 @@ abstract class SyncAdapter);// Opt-out: skip asset creation on pull when the vendor record- // has no existing Snipe-IT counterpart. Default on so existing- // installs keep the "vendor row with no match creates a fresh- // asset" behavior. Off = update rows already linked via- // asset_external_sources, log and skip anything with no match.+ // has no existing Snipe-IT counterpart.SyncAdapterConfig::put($this->instance->id,'create_snipeit_assets_on_pull',- $request->boolean($slug.'_create_snipeit_assets_on_pull', true) ? '1' : '0',+ $request->boolean($slug . '_create_snipeit_assets_on_pull') ? '1' : '0',);// Per-device enrichment opt-in. Only persisted for adaptersdiff --git a/tests/Feature/SyncAdapters/Intune/IntuneSettingsPageTest.php b/tests/Feature/SyncAdapters/Intune/IntuneSettingsPageTest.phpindex 7b86993810..c3bce95a6b 100644--- a/tests/Feature/SyncAdapters/Intune/IntuneSettingsPageTest.php+++ b/tests/Feature/SyncAdapters/Intune/IntuneSettingsPageTest.php@@ -59,6 +59,52 @@ class IntuneSettingsPageTest extends TestCase$this->assertSame('plaintext-client-secret', Crypt::decrypt($storedSecret));}+ public function test_unchecking_create_snipeit_assets_on_pull_persists_as_off()+ {+ // Regression for #19917. The write-side default on+ // $request->boolean(..., true) flipped unchecked checkboxes back+ // to '1' on every save, silently re-enabling asset creation. The+ // "default on when never set" semantic lives on the read side+ // (createsSnipeitAssetsOnPull), so the write side must honor the+ // submitted value as-is.+ $intune = SyncAdapterInstance::where('slug', 'intune')->firstOrFail();+ SyncAdapterConfig::put($intune->id, 'create_snipeit_assets_on_pull', '1');++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('settings.adapters.save', $intune), [+ 'intune_url' => 'https://graph.microsoft.com',+ 'intune_tenant_id' => 'contoso.onmicrosoft.com',+ 'intune_client_id' => '00000000-0000-0000-0000-000000000001',+ 'intune_client_secret' => 'plaintext-client-secret',+ 'intune_default_category_id' => Category::factory()->create()->id,+ 'intune_default_status_id' => Statuslabel::factory()->rtd()->create()->id,+ // Checkbox absent, mirroring an unchecked form submit.+ ])+ ->assertRedirect(route('settings.adapters.index', ['adapter' => $intune->slug]));++ $this->assertSame('0', SyncAdapterConfig::get($intune->id, 'create_snipeit_assets_on_pull'));+ }++ public function test_checking_create_snipeit_assets_on_pull_persists_as_on()+ {+ $intune = SyncAdapterInstance::where('slug', 'intune')->firstOrFail();+ SyncAdapterConfig::put($intune->id, 'create_snipeit_assets_on_pull', '0');++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('settings.adapters.save', $intune), [+ 'intune_url' => 'https://graph.microsoft.com',+ 'intune_tenant_id' => 'contoso.onmicrosoft.com',+ 'intune_client_id' => '00000000-0000-0000-0000-000000000001',+ 'intune_client_secret' => 'plaintext-client-secret',+ 'intune_default_category_id' => Category::factory()->create()->id,+ 'intune_default_status_id' => Statuslabel::factory()->rtd()->create()->id,+ 'intune_create_snipeit_assets_on_pull' => '1',+ ])+ ->assertRedirect(route('settings.adapters.index', ['adapter' => $intune->slug]));++ $this->assertSame('1', SyncAdapterConfig::get($intune->id, 'create_snipeit_assets_on_pull'));+ }+public function test_blank_credentials_on_save_fail_validation(){$intune = SyncAdapterInstance::where('slug', 'intune')->firstOrFail();