Skip to content

A free open source IT asset/license management system

Added regression tests for livewire mounts

snipec66651d52931
diff --git a/tests/Feature/Livewire/AdminPersonalAccessTokensAuthorizationTest.php b/tests/Feature/Livewire/AdminPersonalAccessTokensAuthorizationTest.php
new file mode 100644
index 0000000000..524add285c
--- /dev/null
+++ b/tests/Feature/Livewire/AdminPersonalAccessTokensAuthorizationTest.php
@@ -0,0 +1,35 @@
+<?php
+
+namespace Tests\Feature\Livewire;
+
+use App\Livewire\AdminPersonalAccessTokens;
+use App\Models\User;
+use Livewire\Livewire;
+use Tests\TestCase;
+
+/**
+ * Regression coverage for the Livewire snapshot-replay authorization bypass
+ * reported by PizzaStev3 (2026-07-31). AdminPersonalAccessTokens' render()
+ * enumerates every user's personal access tokens (name, expiration,
+ * associated client, owning user). Route-level middleware on /admin/oauth
+ * (superuser) protects the initial page render but not snapshot replays to
+ * /livewire/update. boot() gate now catches both surfaces.
+ */
+class AdminPersonalAccessTokensAuthorizationTest extends TestCase
+{
+ public function test_superuser_can_mount()
+ {
+ $this->actingAs(User::factory()->superuser()->create());
+
+ Livewire::test(AdminPersonalAccessTokens::class)
+ ->assertStatus(200);
+ }
+
+ public function test_non_superuser_cannot_mount_or_replay()
+ {
+ $this->actingAs(User::factory()->create());
+
+ Livewire::test(AdminPersonalAccessTokens::class)
+ ->assertStatus(403);
+ }
+}
diff --git a/tests/Feature/Livewire/CustomFieldSetDefaultValuesForModelAuthorizationTest.php b/tests/Feature/Livewire/CustomFieldSetDefaultValuesForModelAuthorizationTest.php
new file mode 100644
index 0000000000..571046b135
--- /dev/null
+++ b/tests/Feature/Livewire/CustomFieldSetDefaultValuesForModelAuthorizationTest.php
@@ -0,0 +1,41 @@
+<?php
+
+namespace Tests\Feature\Livewire;
+
+use App\Livewire\CustomFieldSetDefaultValuesForModel;
+use App\Models\AssetModel;
+use App\Models\User;
+use Livewire\Livewire;
+use Tests\TestCase;
+
+/**
+ * Regression coverage for the Livewire snapshot-replay authorization bypass
+ * reported by PizzaStev3 (2026-07-31). The component renders custom-field
+ * default values for an AssetModel identified by model_id. Route-level
+ * middleware on the model create/edit pages requires models.edit, but
+ * snapshot replay to /livewire/update bypassed that gate. boot() gate
+ * now requires AssetModel update permission on both mount and any replayed
+ * action.
+ */
+class CustomFieldSetDefaultValuesForModelAuthorizationTest extends TestCase
+{
+ public function test_user_with_models_edit_permission_can_mount()
+ {
+ $model = AssetModel::factory()->create();
+
+ $this->actingAs(User::factory()->editAssetModels()->create());
+
+ Livewire::test(CustomFieldSetDefaultValuesForModel::class, ['model_id' => $model->id])
+ ->assertStatus(200);
+ }
+
+ public function test_user_without_models_edit_permission_cannot_mount_or_replay()
+ {
+ $model = AssetModel::factory()->create();
+
+ $this->actingAs(User::factory()->create());
+
+ Livewire::test(CustomFieldSetDefaultValuesForModel::class, ['model_id' => $model->id])
+ ->assertStatus(403);
+ }
+}
diff --git a/tests/Feature/Livewire/LdapSettingsAuthorizationTest.php b/tests/Feature/Livewire/LdapSettingsAuthorizationTest.php
new file mode 100644
index 0000000000..b0141703b0
--- /dev/null
+++ b/tests/Feature/Livewire/LdapSettingsAuthorizationTest.php
@@ -0,0 +1,35 @@
+<?php
+
+namespace Tests\Feature\Livewire;
+
+use App\Livewire\LdapSettings;
+use App\Models\User;
+use Livewire\Livewire;
+use Tests\TestCase;
+
+/**
+ * Regression coverage for the Livewire snapshot-replay authorization bypass
+ * reported by PizzaStev3 (2026-07-31). LdapSettings had an abort_unless
+ * check in mount() which only fires on the initial page render. Snapshot
+ * replay to /livewire/update went through hydrate() -> action methods
+ * without re-entering mount(). Now duplicated into boot() which fires on
+ * every Livewire request.
+ */
+class LdapSettingsAuthorizationTest extends TestCase
+{
+ public function test_superadmin_can_mount()
+ {
+ $this->actingAs(User::factory()->firstAdmin()->create());
+
+ Livewire::test(LdapSettings::class)
+ ->assertStatus(200);
+ }
+
+ public function test_non_superadmin_cannot_mount_or_replay()
+ {
+ $this->actingAs(User::factory()->create());
+
+ Livewire::test(LdapSettings::class)
+ ->assertStatus(403);
+ }
+}
diff --git a/tests/Feature/Livewire/LocationScopeCheckAuthorizationTest.php b/tests/Feature/Livewire/LocationScopeCheckAuthorizationTest.php
new file mode 100644
index 0000000000..08e61319c1
--- /dev/null
+++ b/tests/Feature/Livewire/LocationScopeCheckAuthorizationTest.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Tests\Feature\Livewire;
+
+use App\Livewire\LocationScopeCheck;
+use App\Models\User;
+use Livewire\Livewire;
+use Tests\TestCase;
+
+/**
+ * Regression coverage for the Livewire snapshot-replay authorization bypass
+ * reported by PizzaStev3 (2026-07-31). LocationScopeCheck::check_locations()
+ * surfaces cross-tenant FMCS-mismatch data. Route-level middleware on
+ * /admin/settings (superuser) protects the initial page render but not
+ * snapshot replays to /livewire/update. boot() gate now catches both.
+ */
+class LocationScopeCheckAuthorizationTest extends TestCase
+{
+ public function test_superuser_can_mount()
+ {
+ $this->actingAs(User::factory()->superuser()->create());
+
+ Livewire::test(LocationScopeCheck::class)
+ ->assertStatus(200);
+ }
+
+ public function test_non_superuser_cannot_mount_or_replay()
+ {
+ $this->actingAs(User::factory()->create());
+
+ Livewire::test(LocationScopeCheck::class)
+ ->assertStatus(403);
+ }
+}
diff --git a/tests/Feature/Livewire/SlackSettingsFormAuthorizationTest.php b/tests/Feature/Livewire/SlackSettingsFormAuthorizationTest.php
new file mode 100644
index 0000000000..b3bf94d52e
--- /dev/null
+++ b/tests/Feature/Livewire/SlackSettingsFormAuthorizationTest.php
@@ -0,0 +1,35 @@
+<?php
+
+namespace Tests\Feature\Livewire;
+
+use App\Livewire\SlackSettingsForm;
+use App\Models\User;
+use Livewire\Livewire;
+use Tests\TestCase;
+
+/**
+ * Regression coverage for the Livewire snapshot-replay authorization bypass
+ * reported by PizzaStev3 (2026-07-31). SlackSettingsForm had no
+ * per-request authorization and exposed webhook mutation methods
+ * (testWebhook, clearSettings, submit) plus render()-time disclosure of
+ * the configured webhook_endpoint/channel. boot() gate now blocks both
+ * mount and any replay under a non-superuser session.
+ */
+class SlackSettingsFormAuthorizationTest extends TestCase
+{
+ public function test_superuser_can_mount()
+ {
+ $this->actingAs(User::factory()->superuser()->create());
+
+ Livewire::test(SlackSettingsForm::class)
+ ->assertStatus(200);
+ }
+
+ public function test_non_superuser_cannot_mount_or_replay()
+ {
+ $this->actingAs(User::factory()->create());
+
+ Livewire::test(SlackSettingsForm::class)
+ ->assertStatus(403);
+ }
+}