A free open source IT asset/license management system
Harden asset checkout validation
Marcus Moore1d0d14876c71
diff --git a/app/Http/Requests/AssetCheckoutRequest.php b/app/Http/Requests/AssetCheckoutRequest.phpindex c8245682a2..004813c118 100644--- a/app/Http/Requests/AssetCheckoutRequest.php+++ b/app/Http/Requests/AssetCheckoutRequest.php@@ -24,9 +24,9 @@ class AssetCheckoutRequest extends Request$settings = \App\Models\Setting::getSettings();$rules = [- 'assigned_user' => 'required_without_all:assigned_asset,assigned_location',- 'assigned_asset' => 'required_without_all:assigned_user,assigned_location',- 'assigned_location' => 'required_without_all:assigned_user,assigned_asset',+ 'assigned_user' => 'numeric|nullable|required_without_all:assigned_asset,assigned_location',+ 'assigned_asset' => 'numeric|nullable|required_without_all:assigned_user,assigned_location',+ 'assigned_location' => 'numeric|nullable|required_without_all:assigned_user,assigned_asset','status_id' => 'exists:status_labels,id,deployable,1','checkout_to_type' => 'required|in:asset,location,user','checkout_at' => [diff --git a/tests/Feature/Checkouts/Ui/AssetCheckoutTest.php b/tests/Feature/Checkouts/Ui/AssetCheckoutTest.phpindex f268a9385e..68191a3e85 100644--- a/tests/Feature/Checkouts/Ui/AssetCheckoutTest.php+++ b/tests/Feature/Checkouts/Ui/AssetCheckoutTest.php@@ -177,16 +177,23 @@ class AssetCheckoutTest extends TestCase$asset = Asset::factory()->create();$admin = User::factory()->checkoutAssets()->create();+ $defaultFieldsAlwaysIncludedInUIFormSubmission = [+ 'assigned_user' => null,+ 'assigned_asset' => null,+ 'assigned_location' => null,+ ];+$this->actingAs($admin)- ->post(route('hardware.checkout.store', $asset), [+ ->post(route('hardware.checkout.store', $asset), array_merge($defaultFieldsAlwaysIncludedInUIFormSubmission, ['checkout_to_type' => $type,- 'assigned_' . $type => $target->id,+ // overwrite the value from the default fields set above+ 'assigned_' . $type => (string) $target->id,'name' => 'Changed Name',- 'status_id' => $newStatus->id,+ 'status_id' => (string) $newStatus->id,'checkout_at' => '2024-03-18','expected_checkin' => '2024-03-28','note' => 'An awesome note',- ]);+ ]));$asset->refresh();$this->assertTrue($asset->assignedTo()->is($target));