A free open source IT asset/license management system
Fixed gate
snipe0ed9fb047abf
diff --git a/app/Http/Controllers/CustomFieldsController.php b/app/Http/Controllers/CustomFieldsController.phpindex 93c8cd5177..be9ae11f5f 100644--- a/app/Http/Controllers/CustomFieldsController.php+++ b/app/Http/Controllers/CustomFieldsController.php@@ -67,6 +67,7 @@ class CustomFieldsController extends Controller*/public function create(Request $request): View{+ $this->authorize('view', CustomField::class);$this->authorize('create', CustomField::class);$fieldsets = CustomFieldset::get();@@ -89,6 +90,7 @@ class CustomFieldsController extends Controller*/public function store(CustomFieldRequest $request): RedirectResponse{+ $this->authorize('view', CustomField::class);$this->authorize('create', CustomField::class);$show_in_email = $request->input('show_in_email', 0);diff --git a/tests/Feature/CustomFields/Ui/CreateCustomFieldsTest.php b/tests/Feature/CustomFields/Ui/CreateCustomFieldsTest.phpnew file mode 100644index 0000000000..d102659c5e--- /dev/null+++ b/tests/Feature/CustomFields/Ui/CreateCustomFieldsTest.php@@ -0,0 +1,47 @@+<?php++namespace Tests\Feature\CustomFields\Ui;++use App\Models\User;+use Tests\TestCase;++class CreateCustomFieldsTest extends TestCase+{+ public function test_user_without_view_permission_cannot_reach_create_page()+ {+ // The menu entry already requires customfields.view; the create page+ // and store action should match so a user can't bypass by typing the+ // URL directly. Defense-in-depth tie-in with the XSS report on the+ // custom-field name column.+ $this->actingAs(User::factory()->createCustomFields()->create())+ ->get(route('fields.create'))+ ->assertForbidden();+ }++ public function test_user_without_view_permission_cannot_post_to_store()+ {+ $this->actingAs(User::factory()->createCustomFields()->create())+ ->post(route('fields.store'), [+ 'name' => 'TestField',+ 'element' => 'text',+ 'format' => 'ANY',+ ])+ ->assertForbidden();++ $this->assertDatabaseMissing('custom_fields', ['name' => 'TestField']);+ }++ public function test_user_with_view_and_create_can_reach_create_page()+ {+ $this->actingAs(User::factory()->viewCustomFields()->createCustomFields()->create())+ ->get(route('fields.create'))+ ->assertOk();+ }++ public function test_superuser_can_reach_create_page()+ {+ $this->actingAs(User::factory()->superuser()->create())+ ->get(route('fields.create'))+ ->assertOk();+ }+}