A free open source IT asset/license management system
Test fixes
snipedfcedad3c0fa
diff --git a/app/Notifications/CheckinAccessoryNotification.php b/app/Notifications/CheckinAccessoryNotification.phpindex 3f472c3a21..e158a53990 100644--- a/app/Notifications/CheckinAccessoryNotification.php+++ b/app/Notifications/CheckinAccessoryNotification.php@@ -31,11 +31,9 @@ class CheckinAccessoryNotification extends Notification implements ShouldQueuepublic function __construct(public Accessory $item,public $target,- User $admin,+ public User $admin,public $note- )- {- }+ ) {}/*** Get the notification's delivery channels.diff --git a/tests/Feature/Checkins/Ui/BulkAssetCheckinTest.php b/tests/Feature/Checkins/Ui/BulkAssetCheckinTest.phpindex 9bc5248172..3b41496ffd 100644--- a/tests/Feature/Checkins/Ui/BulkAssetCheckinTest.php+++ b/tests/Feature/Checkins/Ui/BulkAssetCheckinTest.php@@ -159,7 +159,11 @@ class BulkAssetCheckinTest extends TestCasepublic function test_bulk_checkin_rejects_location_from_another_company_under_fmcs(){- $this->settings->enableMultipleFullCompanySupport();+ // Location tenant-scoping under FMCS is opt-in via+ // scope_locations_fmcs (off by default). This assertion depends+ // on that scoping actively hiding the cross-company location,+ // so enable it explicitly.+ $this->settings->enableScopedLocationsWithFullMultipleCompanySupport();[$companyA, $companyB] = Company::factory()->count(2)->create();diff --git a/tests/Feature/Locations/Api/LocationsFmcsScopingTest.php b/tests/Feature/Locations/Api/LocationsFmcsScopingTest.phpindex 2b0fefbd96..fcef60621a 100644--- a/tests/Feature/Locations/Api/LocationsFmcsScopingTest.php+++ b/tests/Feature/Locations/Api/LocationsFmcsScopingTest.php@@ -11,14 +11,28 @@ use Tests\TestCase;/*** Verifies FMCS scoping rules for the location index and selectlist endpoints.*+ * Location scoping under FMCS is opt-in via the scope_locations_fmcs+ * setting. That setting is off by default (has been since it was added+ * in 2023_02_27_092130_add_scope_locations_setting), which reflects the+ * install-time reality that most installs want Locations shared across+ * tenants. Company::scopeCompanyablesDirectly() honors the setting for+ * the locations table so read-side scope semantics match the write-side+ * gate on LocationsController::store and the checkout-time gate in+ * CompanyableTrait::canCheckoutTo() (both of which have honored the+ * setting since they were added).+ ** Rules under test:- * 1. FMCS OFF → all locations visible to any authorized user regardless of company- * 2. FMCS ON, user has companies → only locations whose company_id matches one of the user's companies- * 3. FMCS ON, user has companies → locations with NULL company_id are NOT visible- * 4. FMCS ON, user has companies → locations in OTHER companies are NOT visible- * 5. FMCS ON, user has NO companies → only locations with NULL company_id are visible- * 6. FMCS ON, user has NO companies → locations with a company_id are NOT visible- * 7. scope_locations_fmcs does not change visibility; rules 2-6 hold with or without it+ * 1. FMCS OFF → all locations visible to any authorized user (baseline)+ * 2. FMCS ON, scope_locations_fmcs OFF → all locations visible regardless of company+ * 3. FMCS ON, scope_locations_fmcs ON, user has companies → only same-company locations visible+ * 4. FMCS ON, scope_locations_fmcs ON, user has companies → null-company locations NOT visible+ * 5. FMCS ON, scope_locations_fmcs ON, user has NO companies → only null-company locations visible+ * 6. FMCS ON, scope_locations_fmcs ON, user has NO companies → company-scoped locations NOT visible+ *+ * Rules 3-6 gate on scope_locations_fmcs = 1 because opting into+ * location scoping under FMCS is what enables tenant isolation for the+ * locations table. Without it, Snipe-IT treats locations as global+ * config records shared across every tenant.*/class LocationsFmcsScopingTest extends TestCase{@@ -65,7 +79,7 @@ class LocationsFmcsScopingTest extends TestCase}// ------------------------------------------------------------------------ // FMCS OFF+ // FMCS OFF (baseline)// -----------------------------------------------------------------------public function test_fmcs_off_user_sees_all_locations_on_index()@@ -107,12 +121,60 @@ class LocationsFmcsScopingTest extends TestCase}// ------------------------------------------------------------------------ // FMCS ON — user WITH companies+ // FMCS ON, scope_locations_fmcs OFF (default) — locations stay shared// ------------------------------------------------------------------------ public function test_fmcs_on_user_with_company_sees_own_company_location_on_index()+ public function test_fmcs_on_location_scoping_off_user_sees_all_locations_on_index()+ {+ // The customer FD-57180 configuration: FMCS on, location scoping+ // off, floater off. All locations must be visible to a scoped+ // admin because they've opted out of location-level tenant+ // isolation via the setting.+ $this->settings->enableMultipleFullCompanySupport();+ $this->settings->disableFloaterMode();++ $companyA = Company::factory()->create();+ $companyB = Company::factory()->create();++ $locationA = Location::factory()->create(['company_id' => $companyA->id]);+ $locationB = Location::factory()->create(['company_id' => $companyB->id]);+ $locationNull = Location::factory()->create(['company_id' => null]);++ $user = $this->userInCompany($companyA);+ $ids = $this->indexIds($user);++ $this->assertContains($locationA->id, $ids, 'Own-company location should be visible');+ $this->assertContains($locationB->id, $ids, 'Other-company location should be visible when scope_locations_fmcs off');+ $this->assertContains($locationNull->id, $ids, 'Null-company location should be visible when scope_locations_fmcs off');+ }++ public function test_fmcs_on_location_scoping_off_user_sees_all_locations_on_selectlist(){$this->settings->enableMultipleFullCompanySupport();+ $this->settings->disableFloaterMode();++ $companyA = Company::factory()->create();+ $companyB = Company::factory()->create();++ $locationA = Location::factory()->create(['company_id' => $companyA->id]);+ $locationB = Location::factory()->create(['company_id' => $companyB->id]);+ $locationNull = Location::factory()->create(['company_id' => null]);++ $user = $this->userInCompany($companyA);+ $ids = $this->selectlistIds($user);++ $this->assertContains($locationA->id, $ids, 'Own-company location should be in selectlist');+ $this->assertContains($locationB->id, $ids, 'Other-company location should be in selectlist when scope_locations_fmcs off');+ $this->assertContains($locationNull->id, $ids, 'Null-company location should be in selectlist when scope_locations_fmcs off');+ }++ // -----------------------------------------------------------------------+ // FMCS ON, scope_locations_fmcs ON — user WITH companies+ // -----------------------------------------------------------------------++ public function test_fmcs_on_user_with_company_sees_own_company_location_on_index()+ {+ $this->settings->enableScopedLocationsWithFullMultipleCompanySupport();$company = Company::factory()->create();$location = Location::factory()->create(['company_id' => $company->id]);@@ -124,7 +186,7 @@ class LocationsFmcsScopingTest extends TestCasepublic function test_fmcs_on_user_with_company_cannot_see_other_company_location_on_index(){- $this->settings->enableMultipleFullCompanySupport();+ $this->settings->enableScopedLocationsWithFullMultipleCompanySupport();$companyA = Company::factory()->create();$companyB = Company::factory()->create();@@ -138,19 +200,20 @@ class LocationsFmcsScopingTest extends TestCasepublic function test_fmcs_on_user_with_company_cannot_see_null_company_location_on_index(){- $this->settings->enableMultipleFullCompanySupport();+ $this->settings->enableScopedLocationsWithFullMultipleCompanySupport();+ $this->settings->disableFloaterMode();$company = Company::factory()->create();$locationNull = Location::factory()->create(['company_id' => null]);$user = $this->userInCompany($company);$this->assertNotContains($locationNull->id, $this->indexIds($user),- 'Location with no company should not be visible to company-scoped user');+ 'Location with no company should not be visible to company-scoped user in strict mode');}public function test_fmcs_on_user_with_company_sees_own_company_location_on_selectlist(){- $this->settings->enableMultipleFullCompanySupport();+ $this->settings->enableScopedLocationsWithFullMultipleCompanySupport();$company = Company::factory()->create();$location = Location::factory()->create(['company_id' => $company->id]);@@ -162,7 +225,7 @@ class LocationsFmcsScopingTest extends TestCasepublic function test_fmcs_on_user_with_company_cannot_see_other_company_location_on_selectlist(){- $this->settings->enableMultipleFullCompanySupport();+ $this->settings->enableScopedLocationsWithFullMultipleCompanySupport();$companyA = Company::factory()->create();$companyB = Company::factory()->create();@@ -176,23 +239,25 @@ class LocationsFmcsScopingTest extends TestCasepublic function test_fmcs_on_user_with_company_cannot_see_null_company_location_on_selectlist(){- $this->settings->enableMultipleFullCompanySupport();+ $this->settings->enableScopedLocationsWithFullMultipleCompanySupport();+ $this->settings->disableFloaterMode();$company = Company::factory()->create();$locationNull = Location::factory()->create(['company_id' => null]);$user = $this->userInCompany($company);$this->assertNotContains($locationNull->id, $this->selectlistIds($user),- 'Location with no company should not appear in selectlist for company-scoped user');+ 'Location with no company should not appear in selectlist for company-scoped user in strict mode');}// ------------------------------------------------------------------------ // FMCS ON — user with NO companies+ // FMCS ON, scope_locations_fmcs ON — user with NO companies// -----------------------------------------------------------------------public function test_fmcs_on_user_with_no_company_sees_null_company_locations_on_index(){- $this->settings->enableMultipleFullCompanySupport();+ $this->settings->enableScopedLocationsWithFullMultipleCompanySupport();+ $this->settings->disableFloaterMode();$locationNull = Location::factory()->create(['company_id' => null]);$user = $this->userWithNoCompany();@@ -203,7 +268,8 @@ class LocationsFmcsScopingTest extends TestCasepublic function test_fmcs_on_user_with_no_company_cannot_see_company_locations_on_index(){- $this->settings->enableMultipleFullCompanySupport();+ $this->settings->enableScopedLocationsWithFullMultipleCompanySupport();+ $this->settings->disableFloaterMode();$company = Company::factory()->create();$location = Location::factory()->create(['company_id' => $company->id]);@@ -215,7 +281,8 @@ class LocationsFmcsScopingTest extends TestCasepublic function test_fmcs_on_user_with_no_company_sees_null_company_locations_on_selectlist(){- $this->settings->enableMultipleFullCompanySupport();+ $this->settings->enableScopedLocationsWithFullMultipleCompanySupport();+ $this->settings->disableFloaterMode();$locationNull = Location::factory()->create(['company_id' => null]);$user = $this->userWithNoCompany();@@ -226,7 +293,8 @@ class LocationsFmcsScopingTest extends TestCasepublic function test_fmcs_on_user_with_no_company_cannot_see_company_locations_on_selectlist(){- $this->settings->enableMultipleFullCompanySupport();+ $this->settings->enableScopedLocationsWithFullMultipleCompanySupport();+ $this->settings->disableFloaterMode();$company = Company::factory()->create();$location = Location::factory()->create(['company_id' => $company->id]);@@ -235,42 +303,4 @@ class LocationsFmcsScopingTest extends TestCase$this->assertNotContains($location->id, $this->selectlistIds($user),'Location with a company should not appear in selectlist for user with no company');}-- // ------------------------------------------------------------------------ // scope_locations_fmcs does not change visibility rules- // ------------------------------------------------------------------------- public function test_scope_locations_fmcs_does_not_change_visibility_for_user_with_company()- {- $this->settings->enableScopedLocationsWithFullMultipleCompanySupport();-- $companyA = Company::factory()->create();- $companyB = Company::factory()->create();-- $locationA = Location::factory()->create(['company_id' => $companyA->id]);- $locationB = Location::factory()->create(['company_id' => $companyB->id]);- $locationNull = Location::factory()->create(['company_id' => null]);-- $user = $this->userInCompany($companyA);- $ids = $this->indexIds($user);-- $this->assertContains($locationA->id, $ids, 'Own-company location should still be visible');- $this->assertNotContains($locationB->id, $ids, 'Other-company location should still be hidden');- $this->assertNotContains($locationNull->id, $ids, 'Null-company location should still be hidden from company-scoped user');- }-- public function test_scope_locations_fmcs_does_not_change_visibility_for_user_with_no_company()- {- $this->settings->enableScopedLocationsWithFullMultipleCompanySupport();-- $company = Company::factory()->create();- $locationNull = Location::factory()->create(['company_id' => null]);- $locationA = Location::factory()->create(['company_id' => $company->id]);-- $user = $this->userWithNoCompany();- $ids = $this->indexIds($user);-- $this->assertContains($locationNull->id, $ids, 'Null-company location should still be visible to no-company user');- $this->assertNotContains($locationA->id, $ids, 'Company location should still be hidden from no-company user');- }}diff --git a/tests/Unit/CompanyScopingTest.php b/tests/Unit/CompanyScopingTest.phpindex 7e2a22d0b9..a69d8ec48d 100644--- a/tests/Unit/CompanyScopingTest.php+++ b/tests/Unit/CompanyScopingTest.php@@ -10,7 +10,6 @@ use App\Models\Consumable;use App\Models\Department;use App\Models\License;use App\Models\LicenseSeat;-use App\Models\Location;use App\Models\Maintenance;use App\Models\User;use Illuminate\Database\Eloquent\Model;@@ -21,14 +20,20 @@ class CompanyScopingTest extends TestCase{/*** Every companyable model that stores its own company_id on a real- * column (as opposed to Users, which uses the company_user pivot).- * These all go through the same branch of Company::scopeCompanyablesDirectly- * and should share identical strict / floater behavior. Adding a model- * to this list runs the whole DataProvider matrix against it.+ * column AND is unconditionally tenant-scoped under FMCS. Adding a+ * model to this list runs the whole DataProvider matrix against it.*- * Users are covered by test_user_scoping_matrix. Company, Actionlog,- * and ConsumableAssignment are companyable but not first-class list- * targets so they're out of scope for the provider matrix.+ * Users are covered by test_user_scoping_matrix (pivot semantics).+ * Company, Actionlog, and ConsumableAssignment are companyable but+ * not first-class list targets so they're out of scope for the+ * provider matrix.+ *+ * Location is DELIBERATELY excluded: location scoping under FMCS is+ * opt-in via the scope_locations_fmcs setting (off by default), so+ * Location does not share the same strict/floater matrix as the+ * always-scoped models. Location's own coverage lives in+ * tests/Feature/Fmcs/LocationScopingSettingTest.php and+ * tests/Feature/Locations/Api/LocationsFmcsScopingTest.php.*/public static function models(): array{@@ -39,7 +44,6 @@ class CompanyScopingTest extends TestCase'Consumables' => [Consumable::class],'Departments' => [Department::class],'Licenses' => [License::class],- 'Locations' => [Location::class],];}