From 41e0275c951798bb69836ee3f8350cae45542e39 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 3 Jan 2024 12:42:36 -0600 Subject: [PATCH 01/17] `htmlentities()` --- resources/views/models/custom_fields_form.blade.php | 2 +- resources/views/models/custom_fields_form_bulk_edit.blade.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/models/custom_fields_form.blade.php b/resources/views/models/custom_fields_form.blade.php index bae98373e..90985ce77 100644 --- a/resources/views/models/custom_fields_form.blade.php +++ b/resources/views/models/custom_fields_form.blade.php @@ -9,7 +9,7 @@ @if ($field->element=='listbox') {{ Form::select($field->db_column_name(), $field->formatFieldValuesAsArray(), - Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, htmlspecialchars($item->{$field->db_column_name()}, ENT_QUOTES)) : $field->defaultValue($model->id))), ['class'=>'format select2 form-control']) }} + Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, htmlentities($item->{$field->db_column_name()})) : $field->defaultValue($model->id))), ['class'=>'format select2 form-control']) }} @elseif ($field->element=='textarea') diff --git a/resources/views/models/custom_fields_form_bulk_edit.blade.php b/resources/views/models/custom_fields_form_bulk_edit.blade.php index f30c60d33..f01815d5e 100644 --- a/resources/views/models/custom_fields_form_bulk_edit.blade.php +++ b/resources/views/models/custom_fields_form_bulk_edit.blade.php @@ -25,7 +25,7 @@ @if ($field->element=='listbox') {{ Form::select($field->db_column_name(), $field->formatFieldValuesAsArray(), - Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, htmlspecialchars($item->{$field->db_column_name()}, ENT_QUOTES)) : $field->defaultValue($model->id))), ['class'=>'format select2 form-control']) }} + Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, htmlentities($item->{$field->db_column_name()})) : $field->defaultValue($model->id))), ['class'=>'format select2 form-control']) }} @elseif ($field->element=='textarea') @if($field->is_unique) From 2b0dd8851c254e1f5aabf00ac01a4f436e836c85 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Fri, 26 Jan 2024 11:47:09 -0600 Subject: [PATCH 02/17] probably needs more testing... but should work --- app/Http/Controllers/CustomFieldsController.php | 2 +- resources/views/models/custom_fields_form.blade.php | 2 +- resources/views/models/custom_fields_form_bulk_edit.blade.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/CustomFieldsController.php b/app/Http/Controllers/CustomFieldsController.php index ffe5eceec..b109c65f7 100644 --- a/app/Http/Controllers/CustomFieldsController.php +++ b/app/Http/Controllers/CustomFieldsController.php @@ -103,7 +103,7 @@ class CustomFieldsController extends Controller "name" => trim($request->get("name")), "element" => $request->get("element"), "help_text" => $request->get("help_text"), - "field_values" => $request->get("field_values"), + "field_values" => e($request->get("field_values")), "field_encrypted" => $request->get("field_encrypted", 0), "show_in_email" => $show_in_email, "is_unique" => $request->get("is_unique", 0), diff --git a/resources/views/models/custom_fields_form.blade.php b/resources/views/models/custom_fields_form.blade.php index 90985ce77..bae98373e 100644 --- a/resources/views/models/custom_fields_form.blade.php +++ b/resources/views/models/custom_fields_form.blade.php @@ -9,7 +9,7 @@ @if ($field->element=='listbox') {{ Form::select($field->db_column_name(), $field->formatFieldValuesAsArray(), - Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, htmlentities($item->{$field->db_column_name()})) : $field->defaultValue($model->id))), ['class'=>'format select2 form-control']) }} + Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, htmlspecialchars($item->{$field->db_column_name()}, ENT_QUOTES)) : $field->defaultValue($model->id))), ['class'=>'format select2 form-control']) }} @elseif ($field->element=='textarea') diff --git a/resources/views/models/custom_fields_form_bulk_edit.blade.php b/resources/views/models/custom_fields_form_bulk_edit.blade.php index f01815d5e..f30c60d33 100644 --- a/resources/views/models/custom_fields_form_bulk_edit.blade.php +++ b/resources/views/models/custom_fields_form_bulk_edit.blade.php @@ -25,7 +25,7 @@ @if ($field->element=='listbox') {{ Form::select($field->db_column_name(), $field->formatFieldValuesAsArray(), - Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, htmlentities($item->{$field->db_column_name()})) : $field->defaultValue($model->id))), ['class'=>'format select2 form-control']) }} + Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, htmlspecialchars($item->{$field->db_column_name()}, ENT_QUOTES)) : $field->defaultValue($model->id))), ['class'=>'format select2 form-control']) }} @elseif ($field->element=='textarea') @if($field->is_unique) From 4cb804cf038bc900aeb2e081df489cde69a59cf6 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Fri, 26 Jan 2024 11:56:02 -0600 Subject: [PATCH 03/17] get rid of `e()` on store and update --- app/Http/Controllers/CustomFieldsController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/CustomFieldsController.php b/app/Http/Controllers/CustomFieldsController.php index b109c65f7..23ea9da34 100644 --- a/app/Http/Controllers/CustomFieldsController.php +++ b/app/Http/Controllers/CustomFieldsController.php @@ -103,7 +103,7 @@ class CustomFieldsController extends Controller "name" => trim($request->get("name")), "element" => $request->get("element"), "help_text" => $request->get("help_text"), - "field_values" => e($request->get("field_values")), + "field_values" => $request->get("field_values"), "field_encrypted" => $request->get("field_encrypted", 0), "show_in_email" => $show_in_email, "is_unique" => $request->get("is_unique", 0), @@ -260,7 +260,7 @@ class CustomFieldsController extends Controller $field->name = trim(e($request->get("name"))); $field->element = e($request->get("element")); - $field->field_values = e($request->get("field_values")); + $field->field_values = $request->get("field_values"); $field->user_id = Auth::id(); $field->help_text = $request->get("help_text"); $field->show_in_email = $show_in_email; From 1248260df37b28ba1d62e1498c9d562a8ab6ba23 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Fri, 26 Jan 2024 12:33:35 -0600 Subject: [PATCH 04/17] i don't think the output needs to separately escaped, the entire statement is already wrapped in `{{}}` --- resources/views/models/custom_fields_form.blade.php | 2 +- resources/views/models/custom_fields_form_bulk_edit.blade.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/models/custom_fields_form.blade.php b/resources/views/models/custom_fields_form.blade.php index bae98373e..3c49ef8f7 100644 --- a/resources/views/models/custom_fields_form.blade.php +++ b/resources/views/models/custom_fields_form.blade.php @@ -9,7 +9,7 @@ @if ($field->element=='listbox') {{ Form::select($field->db_column_name(), $field->formatFieldValuesAsArray(), - Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, htmlspecialchars($item->{$field->db_column_name()}, ENT_QUOTES)) : $field->defaultValue($model->id))), ['class'=>'format select2 form-control']) }} + Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, $item->{$field->db_column_name()}) : $field->defaultValue($model->id))), ['class'=>'format select2 form-control']) }} @elseif ($field->element=='textarea') diff --git a/resources/views/models/custom_fields_form_bulk_edit.blade.php b/resources/views/models/custom_fields_form_bulk_edit.blade.php index f30c60d33..dc0ad1f88 100644 --- a/resources/views/models/custom_fields_form_bulk_edit.blade.php +++ b/resources/views/models/custom_fields_form_bulk_edit.blade.php @@ -25,7 +25,7 @@ @if ($field->element=='listbox') {{ Form::select($field->db_column_name(), $field->formatFieldValuesAsArray(), - Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, htmlspecialchars($item->{$field->db_column_name()}, ENT_QUOTES)) : $field->defaultValue($model->id))), ['class'=>'format select2 form-control']) }} + Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, $item->{$field->db_column_name()}) : $field->defaultValue($model->id))), ['class'=>'format select2 form-control']) }} @elseif ($field->element=='textarea') @if($field->is_unique) From 0fcf2239605b3d6463b40123c8ba9e6d9d620c7d Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 12 Mar 2024 12:00:10 -0700 Subject: [PATCH 05/17] Add minimal validation for asset_tags --- app/Http/Controllers/Assets/AssetsController.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php index 0683a54e3..6054718e6 100755 --- a/app/Http/Controllers/Assets/AssetsController.php +++ b/app/Http/Controllers/Assets/AssetsController.php @@ -102,6 +102,10 @@ class AssetsController extends Controller { $this->authorize(Asset::class); + // There are a lot more rules to add here but prevents + // errors around `asset_tags` not being present below. + $this->validate($request, ['asset_tags' => ['required', 'array']]); + // Handle asset tags - there could be one, or potentially many. // This is only necessary on create, not update, since bulk editing is handled // differently From 8003615b1f1bb377afd157e74a8f9025395630f1 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 14 Mar 2024 14:15:11 -0700 Subject: [PATCH 06/17] Move InteractsWithSettings to TestCase --- tests/Feature/Api/Accessories/AccessoryCheckoutTest.php | 3 --- tests/Feature/Api/Assets/AssetCheckinTest.php | 3 --- tests/Feature/Api/Assets/AssetIndexTest.php | 3 --- tests/Feature/Api/Assets/AssetStoreTest.php | 4 ---- tests/Feature/Api/Assets/AssetsForSelectListTest.php | 3 --- tests/Feature/Api/Assets/RequestableAssetsTest.php | 3 --- tests/Feature/Api/Components/ComponentIndexTest.php | 3 --- tests/Feature/Api/Consumables/ConsumableCheckoutTest.php | 3 --- tests/Feature/Api/Consumables/ConsumablesIndexTest.php | 3 --- tests/Feature/Api/Departments/DepartmentIndexTest.php | 4 ---- tests/Feature/Api/Groups/GroupStoreTest.php | 3 --- tests/Feature/Api/Licenses/LicensesIndexTest.php | 3 --- tests/Feature/Api/Locations/LocationsForSelectListTest.php | 3 --- tests/Feature/Api/Users/UpdateUserApiTest.php | 7 ------- tests/Feature/Api/Users/UsersForSelectListTest.php | 3 --- tests/Feature/Api/Users/UsersSearchTest.php | 3 --- tests/Feature/Api/Users/UsersUpdateTest.php | 3 --- tests/Feature/Checkins/AccessoryCheckinTest.php | 3 --- tests/Feature/Checkins/AssetCheckinTest.php | 3 --- .../CheckoutAcceptances/AccessoryAcceptanceTest.php | 3 --- tests/Feature/Checkouts/AccessoryCheckoutTest.php | 3 --- tests/Feature/Checkouts/ConsumableCheckoutTest.php | 3 --- tests/Feature/Checkouts/LicenseCheckoutTest.php | 3 --- tests/Feature/DashboardTest.php | 3 --- tests/Feature/Notifications/AccessoryWebhookTest.php | 3 --- tests/Feature/Notifications/AssetWebhookTest.php | 3 --- tests/Feature/Notifications/ComponentWebhookTest.php | 4 ---- tests/Feature/Notifications/ConsumableWebhookTest.php | 3 --- tests/Feature/Notifications/LicenseWebhookTest.php | 3 --- tests/Feature/Reports/CustomReportTest.php | 4 ---- tests/Feature/Users/UpdateUserTest.php | 3 --- tests/TestCase.php | 1 + tests/Unit/AssetMaintenanceTest.php | 4 ---- tests/Unit/AssetModelTest.php | 3 --- tests/Unit/AssetTest.php | 3 --- tests/Unit/CategoryTest.php | 3 --- tests/Unit/CompanyScopingTest.php | 3 --- tests/Unit/ComponentTest.php | 3 --- tests/Unit/DepreciationTest.php | 3 --- tests/Unit/LdapTest.php | 3 --- tests/Unit/Models/Company/GetIdForCurrentUserTest.php | 3 --- tests/Unit/NotificationTest.php | 3 --- tests/Unit/SnipeModelTest.php | 3 --- 43 files changed, 1 insertion(+), 135 deletions(-) diff --git a/tests/Feature/Api/Accessories/AccessoryCheckoutTest.php b/tests/Feature/Api/Accessories/AccessoryCheckoutTest.php index d65a3ad61..854a96ada 100644 --- a/tests/Feature/Api/Accessories/AccessoryCheckoutTest.php +++ b/tests/Feature/Api/Accessories/AccessoryCheckoutTest.php @@ -7,13 +7,10 @@ use App\Models\Actionlog; use App\Models\User; use App\Notifications\CheckoutAccessoryNotification; use Illuminate\Support\Facades\Notification; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class AccessoryCheckoutTest extends TestCase { - use InteractsWithSettings; - public function testCheckingOutAccessoryRequiresCorrectPermission() { $this->actingAsForApi(User::factory()->create()) diff --git a/tests/Feature/Api/Assets/AssetCheckinTest.php b/tests/Feature/Api/Assets/AssetCheckinTest.php index 6f8daf569..add90a067 100644 --- a/tests/Feature/Api/Assets/AssetCheckinTest.php +++ b/tests/Feature/Api/Assets/AssetCheckinTest.php @@ -11,13 +11,10 @@ use App\Models\Statuslabel; use App\Models\User; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Event; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class AssetCheckinTest extends TestCase { - use InteractsWithSettings; - public function testCheckingInAssetRequiresCorrectPermission() { $this->actingAsForApi(User::factory()->create()) diff --git a/tests/Feature/Api/Assets/AssetIndexTest.php b/tests/Feature/Api/Assets/AssetIndexTest.php index 778483c1c..3175db695 100644 --- a/tests/Feature/Api/Assets/AssetIndexTest.php +++ b/tests/Feature/Api/Assets/AssetIndexTest.php @@ -6,13 +6,10 @@ use App\Models\Asset; use App\Models\Company; use App\Models\User; use Illuminate\Testing\Fluent\AssertableJson; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class AssetIndexTest extends TestCase { - use InteractsWithSettings; - public function testAssetIndexReturnsExpectedAssets() { Asset::factory()->count(3)->create(); diff --git a/tests/Feature/Api/Assets/AssetStoreTest.php b/tests/Feature/Api/Assets/AssetStoreTest.php index 92a58a500..ceae05364 100644 --- a/tests/Feature/Api/Assets/AssetStoreTest.php +++ b/tests/Feature/Api/Assets/AssetStoreTest.php @@ -9,15 +9,11 @@ use App\Models\Location; use App\Models\Statuslabel; use App\Models\Supplier; use App\Models\User; -use Carbon\Carbon; use Illuminate\Testing\Fluent\AssertableJson; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class AssetStoreTest extends TestCase { - use InteractsWithSettings; - public function testRequiresPermissionToCreateAsset() { $this->actingAsForApi(User::factory()->create()) diff --git a/tests/Feature/Api/Assets/AssetsForSelectListTest.php b/tests/Feature/Api/Assets/AssetsForSelectListTest.php index cccae38d3..3c5e1e4e7 100644 --- a/tests/Feature/Api/Assets/AssetsForSelectListTest.php +++ b/tests/Feature/Api/Assets/AssetsForSelectListTest.php @@ -5,13 +5,10 @@ namespace Tests\Feature\Api\Assets; use App\Models\Asset; use App\Models\Company; use App\Models\User; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class AssetsForSelectListTest extends TestCase { - use InteractsWithSettings; - public function testAssetsCanBeSearchedForByAssetTag() { Asset::factory()->create(['asset_tag' => '0001']); diff --git a/tests/Feature/Api/Assets/RequestableAssetsTest.php b/tests/Feature/Api/Assets/RequestableAssetsTest.php index 8649b1b00..d90e45f22 100644 --- a/tests/Feature/Api/Assets/RequestableAssetsTest.php +++ b/tests/Feature/Api/Assets/RequestableAssetsTest.php @@ -5,13 +5,10 @@ namespace Tests\Feature\Api\Assets; use App\Models\Asset; use App\Models\Company; use App\Models\User; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class RequestableAssetsTest extends TestCase { - use InteractsWithSettings; - public function testViewingRequestableAssetsRequiresCorrectPermission() { $this->actingAsForApi(User::factory()->create()) diff --git a/tests/Feature/Api/Components/ComponentIndexTest.php b/tests/Feature/Api/Components/ComponentIndexTest.php index ee83b7a46..517724a49 100644 --- a/tests/Feature/Api/Components/ComponentIndexTest.php +++ b/tests/Feature/Api/Components/ComponentIndexTest.php @@ -5,13 +5,10 @@ namespace Tests\Feature\Api\Components; use App\Models\Company; use App\Models\Component; use App\Models\User; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class ComponentIndexTest extends TestCase { - use InteractsWithSettings; - public function testComponentIndexAdheresToCompanyScoping() { [$companyA, $companyB] = Company::factory()->count(2)->create(); diff --git a/tests/Feature/Api/Consumables/ConsumableCheckoutTest.php b/tests/Feature/Api/Consumables/ConsumableCheckoutTest.php index 103be96ac..1528e65aa 100644 --- a/tests/Feature/Api/Consumables/ConsumableCheckoutTest.php +++ b/tests/Feature/Api/Consumables/ConsumableCheckoutTest.php @@ -7,13 +7,10 @@ use App\Models\Consumable; use App\Models\User; use App\Notifications\CheckoutConsumableNotification; use Illuminate\Support\Facades\Notification; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class ConsumableCheckoutTest extends TestCase { - use InteractsWithSettings; - public function testCheckingOutConsumableRequiresCorrectPermission() { $this->actingAsForApi(User::factory()->create()) diff --git a/tests/Feature/Api/Consumables/ConsumablesIndexTest.php b/tests/Feature/Api/Consumables/ConsumablesIndexTest.php index 33c10ed07..00fa43da2 100644 --- a/tests/Feature/Api/Consumables/ConsumablesIndexTest.php +++ b/tests/Feature/Api/Consumables/ConsumablesIndexTest.php @@ -5,13 +5,10 @@ namespace Tests\Feature\Api\Consumables; use App\Models\Company; use App\Models\Consumable; use App\Models\User; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class ConsumablesIndexTest extends TestCase { - use InteractsWithSettings; - public function testConsumableIndexAdheresToCompanyScoping() { [$companyA, $companyB] = Company::factory()->count(2)->create(); diff --git a/tests/Feature/Api/Departments/DepartmentIndexTest.php b/tests/Feature/Api/Departments/DepartmentIndexTest.php index 1a3884308..11ab5df9b 100644 --- a/tests/Feature/Api/Departments/DepartmentIndexTest.php +++ b/tests/Feature/Api/Departments/DepartmentIndexTest.php @@ -5,15 +5,11 @@ namespace Tests\Feature\Api\Departments; use App\Models\Company; use App\Models\Department; use App\Models\User; -use Illuminate\Routing\Route; use Illuminate\Testing\Fluent\AssertableJson; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class DepartmentIndexTest extends TestCase { - use InteractsWithSettings; - public function testViewingDepartmentIndexRequiresAuthentication() { $this->getJson(route('api.departments.index'))->assertRedirect(); diff --git a/tests/Feature/Api/Groups/GroupStoreTest.php b/tests/Feature/Api/Groups/GroupStoreTest.php index 9ffba5191..31a69fb46 100644 --- a/tests/Feature/Api/Groups/GroupStoreTest.php +++ b/tests/Feature/Api/Groups/GroupStoreTest.php @@ -4,13 +4,10 @@ namespace Tests\Feature\Api\Groups; use App\Models\Group; use App\Models\User; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class GroupStoreTest extends TestCase { - use InteractsWithSettings; - public function testStoringGroupRequiresSuperAdminPermission() { $this->actingAsForApi(User::factory()->create()) diff --git a/tests/Feature/Api/Licenses/LicensesIndexTest.php b/tests/Feature/Api/Licenses/LicensesIndexTest.php index a21a27da7..603002a09 100644 --- a/tests/Feature/Api/Licenses/LicensesIndexTest.php +++ b/tests/Feature/Api/Licenses/LicensesIndexTest.php @@ -5,13 +5,10 @@ namespace Tests\Feature\Api\Licenses; use App\Models\Company; use App\Models\License; use App\Models\User; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class LicensesIndexTest extends TestCase { - use InteractsWithSettings; - public function testLicensesIndexAdheresToCompanyScoping() { [$companyA, $companyB] = Company::factory()->count(2)->create(); diff --git a/tests/Feature/Api/Locations/LocationsForSelectListTest.php b/tests/Feature/Api/Locations/LocationsForSelectListTest.php index 4170cfc7f..bfc7fc537 100644 --- a/tests/Feature/Api/Locations/LocationsForSelectListTest.php +++ b/tests/Feature/Api/Locations/LocationsForSelectListTest.php @@ -5,13 +5,10 @@ namespace Tests\Feature\Api\Locations; use App\Models\Location; use App\Models\User; use Illuminate\Testing\Fluent\AssertableJson; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class LocationsForSelectListTest extends TestCase { - use InteractsWithSettings; - public function testGettingLocationListRequiresProperPermission() { $this->actingAsForApi(User::factory()->create()) diff --git a/tests/Feature/Api/Users/UpdateUserApiTest.php b/tests/Feature/Api/Users/UpdateUserApiTest.php index 81c115464..f58aae4a0 100644 --- a/tests/Feature/Api/Users/UpdateUserApiTest.php +++ b/tests/Feature/Api/Users/UpdateUserApiTest.php @@ -3,16 +3,10 @@ namespace Tests\Feature\Api\Users; use App\Models\User; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; -use Tests\Support\InteractsWithAuthentication; - class UpdateUserApiTest extends TestCase { - use InteractsWithSettings; - use InteractsWithAuthentication; - public function testApiUsersCanBeActivatedWithNumber() { $admin = User::factory()->superuser()->create(); @@ -64,5 +58,4 @@ class UpdateUserApiTest extends TestCase $this->assertEquals(0, $user->refresh()->activated); } - } diff --git a/tests/Feature/Api/Users/UsersForSelectListTest.php b/tests/Feature/Api/Users/UsersForSelectListTest.php index 8cdf700f0..1ebfcf72e 100644 --- a/tests/Feature/Api/Users/UsersForSelectListTest.php +++ b/tests/Feature/Api/Users/UsersForSelectListTest.php @@ -6,13 +6,10 @@ use App\Models\Company; use App\Models\User; use Illuminate\Testing\Fluent\AssertableJson; use Laravel\Passport\Passport; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class UsersForSelectListTest extends TestCase { - use InteractsWithSettings; - public function testUsersAreReturned() { $users = User::factory()->superuser()->count(3)->create(); diff --git a/tests/Feature/Api/Users/UsersSearchTest.php b/tests/Feature/Api/Users/UsersSearchTest.php index 723a115db..72f23017f 100644 --- a/tests/Feature/Api/Users/UsersSearchTest.php +++ b/tests/Feature/Api/Users/UsersSearchTest.php @@ -5,13 +5,10 @@ namespace Tests\Feature\Api\Users; use App\Models\Company; use App\Models\User; use Laravel\Passport\Passport; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class UsersSearchTest extends TestCase { - use InteractsWithSettings; - public function testCanSearchByUserFirstAndLastName() { User::factory()->create(['first_name' => 'Luke', 'last_name' => 'Skywalker']); diff --git a/tests/Feature/Api/Users/UsersUpdateTest.php b/tests/Feature/Api/Users/UsersUpdateTest.php index 953a671cf..d6e0f9e46 100644 --- a/tests/Feature/Api/Users/UsersUpdateTest.php +++ b/tests/Feature/Api/Users/UsersUpdateTest.php @@ -8,13 +8,10 @@ use App\Models\Group; use App\Models\Location; use App\Models\User; use Illuminate\Support\Facades\Hash; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class UsersUpdateTest extends TestCase { - use InteractsWithSettings; - public function testCanUpdateUserViaPatch() { $admin = User::factory()->superuser()->create(); diff --git a/tests/Feature/Checkins/AccessoryCheckinTest.php b/tests/Feature/Checkins/AccessoryCheckinTest.php index 25cd5d0d8..56030991e 100644 --- a/tests/Feature/Checkins/AccessoryCheckinTest.php +++ b/tests/Feature/Checkins/AccessoryCheckinTest.php @@ -8,13 +8,10 @@ use App\Models\User; use App\Notifications\CheckinAccessoryNotification; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Notification; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class AccessoryCheckinTest extends TestCase { - use InteractsWithSettings; - public function testCheckingInAccessoryRequiresCorrectPermission() { $accessory = Accessory::factory()->checkedOutToUser()->create(); diff --git a/tests/Feature/Checkins/AssetCheckinTest.php b/tests/Feature/Checkins/AssetCheckinTest.php index fb6d21a6a..1e6d2b995 100644 --- a/tests/Feature/Checkins/AssetCheckinTest.php +++ b/tests/Feature/Checkins/AssetCheckinTest.php @@ -11,13 +11,10 @@ use App\Models\Statuslabel; use App\Models\User; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Event; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class AssetCheckinTest extends TestCase { - use InteractsWithSettings; - public function testCheckingInAssetRequiresCorrectPermission() { $this->actingAs(User::factory()->create()) diff --git a/tests/Feature/CheckoutAcceptances/AccessoryAcceptanceTest.php b/tests/Feature/CheckoutAcceptances/AccessoryAcceptanceTest.php index a49b1167c..bdaf0e780 100644 --- a/tests/Feature/CheckoutAcceptances/AccessoryAcceptanceTest.php +++ b/tests/Feature/CheckoutAcceptances/AccessoryAcceptanceTest.php @@ -7,13 +7,10 @@ use App\Models\CheckoutAcceptance; use App\Notifications\AcceptanceAssetAcceptedNotification; use App\Notifications\AcceptanceAssetDeclinedNotification; use Notification; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class AccessoryAcceptanceTest extends TestCase { - use InteractsWithSettings; - /** * This can be absorbed into a bigger test */ diff --git a/tests/Feature/Checkouts/AccessoryCheckoutTest.php b/tests/Feature/Checkouts/AccessoryCheckoutTest.php index cbe9801cc..11224e4d1 100644 --- a/tests/Feature/Checkouts/AccessoryCheckoutTest.php +++ b/tests/Feature/Checkouts/AccessoryCheckoutTest.php @@ -7,13 +7,10 @@ use App\Models\Actionlog; use App\Models\User; use App\Notifications\CheckoutAccessoryNotification; use Illuminate\Support\Facades\Notification; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class AccessoryCheckoutTest extends TestCase { - use InteractsWithSettings; - public function testCheckingOutAccessoryRequiresCorrectPermission() { $this->actingAs(User::factory()->create()) diff --git a/tests/Feature/Checkouts/ConsumableCheckoutTest.php b/tests/Feature/Checkouts/ConsumableCheckoutTest.php index 5785d0572..e38ae96c8 100644 --- a/tests/Feature/Checkouts/ConsumableCheckoutTest.php +++ b/tests/Feature/Checkouts/ConsumableCheckoutTest.php @@ -7,13 +7,10 @@ use App\Models\Consumable; use App\Models\User; use App\Notifications\CheckoutConsumableNotification; use Illuminate\Support\Facades\Notification; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class ConsumableCheckoutTest extends TestCase { - use InteractsWithSettings; - public function testCheckingOutConsumableRequiresCorrectPermission() { $this->actingAs(User::factory()->create()) diff --git a/tests/Feature/Checkouts/LicenseCheckoutTest.php b/tests/Feature/Checkouts/LicenseCheckoutTest.php index 978fac28f..2f4f51d4a 100644 --- a/tests/Feature/Checkouts/LicenseCheckoutTest.php +++ b/tests/Feature/Checkouts/LicenseCheckoutTest.php @@ -6,13 +6,10 @@ use App\Models\Asset; use App\Models\License; use App\Models\LicenseSeat; use App\Models\User; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class LicenseCheckoutTest extends TestCase { - use InteractsWithSettings; - public function testNotesAreStoredInActionLogOnCheckoutToAsset() { $admin = User::factory()->superuser()->create(); diff --git a/tests/Feature/DashboardTest.php b/tests/Feature/DashboardTest.php index 4e9459fb0..4690a1390 100644 --- a/tests/Feature/DashboardTest.php +++ b/tests/Feature/DashboardTest.php @@ -3,13 +3,10 @@ namespace Tests\Feature; use App\Models\User; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class DashboardTest extends TestCase { - use InteractsWithSettings; - public function testUsersWithoutAdminAccessAreRedirected() { $this->actingAs(User::factory()->create()) diff --git a/tests/Feature/Notifications/AccessoryWebhookTest.php b/tests/Feature/Notifications/AccessoryWebhookTest.php index 2e3ef999b..42a48c9eb 100644 --- a/tests/Feature/Notifications/AccessoryWebhookTest.php +++ b/tests/Feature/Notifications/AccessoryWebhookTest.php @@ -11,13 +11,10 @@ use App\Notifications\CheckinAccessoryNotification; use App\Notifications\CheckoutAccessoryNotification; use Illuminate\Notifications\AnonymousNotifiable; use Illuminate\Support\Facades\Notification; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class AccessoryWebhookTest extends TestCase { - use InteractsWithSettings; - public function testAccessoryCheckoutSendsWebhookNotificationWhenSettingEnabled() { Notification::fake(); diff --git a/tests/Feature/Notifications/AssetWebhookTest.php b/tests/Feature/Notifications/AssetWebhookTest.php index 95218f98e..93da395a3 100644 --- a/tests/Feature/Notifications/AssetWebhookTest.php +++ b/tests/Feature/Notifications/AssetWebhookTest.php @@ -12,13 +12,10 @@ use App\Notifications\CheckinAssetNotification; use App\Notifications\CheckoutAssetNotification; use Illuminate\Notifications\AnonymousNotifiable; use Illuminate\Support\Facades\Notification; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class AssetWebhookTest extends TestCase { - use InteractsWithSettings; - public function targets(): array { return [ diff --git a/tests/Feature/Notifications/ComponentWebhookTest.php b/tests/Feature/Notifications/ComponentWebhookTest.php index 2e2a53521..f6aa8a668 100644 --- a/tests/Feature/Notifications/ComponentWebhookTest.php +++ b/tests/Feature/Notifications/ComponentWebhookTest.php @@ -8,14 +8,10 @@ use App\Models\Asset; use App\Models\Component; use App\Models\User; use Illuminate\Support\Facades\Notification; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class ComponentWebhookTest extends TestCase { - - use InteractsWithSettings; - public function testComponentCheckoutDoesNotSendWebhookNotification() { Notification::fake(); diff --git a/tests/Feature/Notifications/ConsumableWebhookTest.php b/tests/Feature/Notifications/ConsumableWebhookTest.php index 2815731bd..2a1126f91 100644 --- a/tests/Feature/Notifications/ConsumableWebhookTest.php +++ b/tests/Feature/Notifications/ConsumableWebhookTest.php @@ -9,13 +9,10 @@ use App\Models\User; use App\Notifications\CheckoutConsumableNotification; use Illuminate\Notifications\AnonymousNotifiable; use Illuminate\Support\Facades\Notification; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class ConsumableWebhookTest extends TestCase { - use InteractsWithSettings; - public function testConsumableCheckoutSendsWebhookNotificationWhenSettingEnabled() { Notification::fake(); diff --git a/tests/Feature/Notifications/LicenseWebhookTest.php b/tests/Feature/Notifications/LicenseWebhookTest.php index 24ec53a75..2ee14f913 100644 --- a/tests/Feature/Notifications/LicenseWebhookTest.php +++ b/tests/Feature/Notifications/LicenseWebhookTest.php @@ -12,13 +12,10 @@ use App\Notifications\CheckinLicenseSeatNotification; use App\Notifications\CheckoutLicenseSeatNotification; use Illuminate\Notifications\AnonymousNotifiable; use Illuminate\Support\Facades\Notification; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class LicenseWebhookTest extends TestCase { - use InteractsWithSettings; - public function targets(): array { return [ diff --git a/tests/Feature/Reports/CustomReportTest.php b/tests/Feature/Reports/CustomReportTest.php index dd3199212..d90e4cb2a 100644 --- a/tests/Feature/Reports/CustomReportTest.php +++ b/tests/Feature/Reports/CustomReportTest.php @@ -8,14 +8,10 @@ use App\Models\User; use Illuminate\Testing\TestResponse; use League\Csv\Reader; use PHPUnit\Framework\Assert; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; - class CustomReportTest extends TestCase { - use InteractsWithSettings; - protected function setUp(): void { parent::setUp(); diff --git a/tests/Feature/Users/UpdateUserTest.php b/tests/Feature/Users/UpdateUserTest.php index 92245059e..934fbce2b 100644 --- a/tests/Feature/Users/UpdateUserTest.php +++ b/tests/Feature/Users/UpdateUserTest.php @@ -3,13 +3,10 @@ namespace Tests\Feature\Users; use App\Models\User; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class UpdateUserTest extends TestCase { - use InteractsWithSettings; - public function testUsersCanBeActivatedWithNumber() { $admin = User::factory()->superuser()->create(); diff --git a/tests/TestCase.php b/tests/TestCase.php index 03f273ad6..9b77eeb32 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -15,6 +15,7 @@ abstract class TestCase extends BaseTestCase use CreatesApplication; use CustomTestMacros; use InteractsWithAuthentication; + use InteractsWithSettings; use LazilyRefreshDatabase; private array $globallyDisabledMiddleware = [ diff --git a/tests/Unit/AssetMaintenanceTest.php b/tests/Unit/AssetMaintenanceTest.php index 69c4c3093..46a0efdd7 100644 --- a/tests/Unit/AssetMaintenanceTest.php +++ b/tests/Unit/AssetMaintenanceTest.php @@ -2,14 +2,10 @@ namespace Tests\Unit; use App\Models\AssetMaintenance; -use Carbon\Carbon; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class AssetMaintenanceTest extends TestCase { - use InteractsWithSettings; - public function testZerosOutWarrantyIfBlank() { $c = new AssetMaintenance; diff --git a/tests/Unit/AssetModelTest.php b/tests/Unit/AssetModelTest.php index aec8edf69..4cc62e20a 100644 --- a/tests/Unit/AssetModelTest.php +++ b/tests/Unit/AssetModelTest.php @@ -4,13 +4,10 @@ namespace Tests\Unit; use App\Models\Asset; use App\Models\Category; use App\Models\AssetModel; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class AssetModelTest extends TestCase { - use InteractsWithSettings; - public function testAnAssetModelContainsAssets() { $category = Category::factory()->create([ diff --git a/tests/Unit/AssetTest.php b/tests/Unit/AssetTest.php index 7670d1075..913d9f639 100644 --- a/tests/Unit/AssetTest.php +++ b/tests/Unit/AssetTest.php @@ -5,13 +5,10 @@ use App\Models\Asset; use App\Models\AssetModel; use App\Models\Category; use Carbon\Carbon; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class AssetTest extends TestCase { - use InteractsWithSettings; - public function testAutoIncrement() { $this->settings->enableAutoIncrement(); diff --git a/tests/Unit/CategoryTest.php b/tests/Unit/CategoryTest.php index c74597b1b..387ed946e 100644 --- a/tests/Unit/CategoryTest.php +++ b/tests/Unit/CategoryTest.php @@ -4,13 +4,10 @@ namespace Tests\Unit; use App\Models\Category; use App\Models\AssetModel; use App\Models\Asset; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class CategoryTest extends TestCase { - use InteractsWithSettings; - public function testFailsEmptyValidation() { // An Asset requires a name, a qty, and a category_id. diff --git a/tests/Unit/CompanyScopingTest.php b/tests/Unit/CompanyScopingTest.php index 669dd5ed4..3923dd9f7 100644 --- a/tests/Unit/CompanyScopingTest.php +++ b/tests/Unit/CompanyScopingTest.php @@ -12,13 +12,10 @@ use App\Models\License; use App\Models\LicenseSeat; use App\Models\User; use Illuminate\Database\Eloquent\Model; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class CompanyScopingTest extends TestCase { - use InteractsWithSettings; - public function models(): array { return [ diff --git a/tests/Unit/ComponentTest.php b/tests/Unit/ComponentTest.php index 8f71057bf..df8f64771 100644 --- a/tests/Unit/ComponentTest.php +++ b/tests/Unit/ComponentTest.php @@ -5,13 +5,10 @@ use App\Models\Category; use App\Models\Company; use App\Models\Component; use App\Models\Location; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class ComponentTest extends TestCase { - use InteractsWithSettings; - public function testAComponentBelongsToACompany() { $component = Component::factory() diff --git a/tests/Unit/DepreciationTest.php b/tests/Unit/DepreciationTest.php index ed033cf44..4dd842227 100644 --- a/tests/Unit/DepreciationTest.php +++ b/tests/Unit/DepreciationTest.php @@ -5,13 +5,10 @@ use App\Models\Depreciation; use App\Models\Category; use App\Models\License; use App\Models\AssetModel; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class DepreciationTest extends TestCase { - use InteractsWithSettings; - public function testADepreciationHasModels() { $depreciation = Depreciation::factory()->create(); diff --git a/tests/Unit/LdapTest.php b/tests/Unit/LdapTest.php index c286b3849..6beb0d211 100644 --- a/tests/Unit/LdapTest.php +++ b/tests/Unit/LdapTest.php @@ -3,8 +3,6 @@ namespace Tests\Unit; use App\Models\Ldap; -use Exception; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; /** @@ -12,7 +10,6 @@ use Tests\TestCase; */ class LdapTest extends TestCase { - use InteractsWithSettings; use \phpmock\phpunit\PHPMock; public function testConnect() diff --git a/tests/Unit/Models/Company/GetIdForCurrentUserTest.php b/tests/Unit/Models/Company/GetIdForCurrentUserTest.php index 1ca88d7ca..6d77c8873 100644 --- a/tests/Unit/Models/Company/GetIdForCurrentUserTest.php +++ b/tests/Unit/Models/Company/GetIdForCurrentUserTest.php @@ -4,13 +4,10 @@ namespace Tests\Unit\Models\Company; use App\Models\Company; use App\Models\User; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class GetIdForCurrentUserTest extends TestCase { - use InteractsWithSettings; - public function testReturnsProvidedValueWhenFullCompanySupportDisabled() { $this->settings->disableMultipleFullCompanySupport(); diff --git a/tests/Unit/NotificationTest.php b/tests/Unit/NotificationTest.php index 64cf8afb0..8005759a1 100644 --- a/tests/Unit/NotificationTest.php +++ b/tests/Unit/NotificationTest.php @@ -8,13 +8,10 @@ use App\Models\Category; use Carbon\Carbon; use App\Notifications\CheckoutAssetNotification; use Illuminate\Support\Facades\Notification; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class NotificationTest extends TestCase { - use InteractsWithSettings; - public function testAUserIsEmailedIfTheyCheckoutAnAssetWithEULA() { $admin = User::factory()->superuser()->create(); diff --git a/tests/Unit/SnipeModelTest.php b/tests/Unit/SnipeModelTest.php index ad4231010..2bc81da61 100644 --- a/tests/Unit/SnipeModelTest.php +++ b/tests/Unit/SnipeModelTest.php @@ -2,13 +2,10 @@ namespace Tests\Unit; use App\Models\SnipeModel; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; class SnipeModelTest extends TestCase { - use InteractsWithSettings; - public function testSetsPurchaseDatesAppropriately() { $c = new SnipeModel; From 95ff692b14a16ad90df44d4c45b40fc8cecde082 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 14 Mar 2024 15:06:52 -0700 Subject: [PATCH 07/17] Improve InteractsWithSettings name --- ...{InteractsWithSettings.php => InitializesSettings.php} | 2 +- tests/TestCase.php | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) rename tests/Support/{InteractsWithSettings.php => InitializesSettings.php} (90%) diff --git a/tests/Support/InteractsWithSettings.php b/tests/Support/InitializesSettings.php similarity index 90% rename from tests/Support/InteractsWithSettings.php rename to tests/Support/InitializesSettings.php index a8c007018..7c08e6f89 100644 --- a/tests/Support/InteractsWithSettings.php +++ b/tests/Support/InitializesSettings.php @@ -4,7 +4,7 @@ namespace Tests\Support; use App\Models\Setting; -trait InteractsWithSettings +trait InitializesSettings { protected Settings $settings; diff --git a/tests/TestCase.php b/tests/TestCase.php index 9b77eeb32..8a3321ac6 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -8,14 +8,14 @@ use Illuminate\Foundation\Testing\TestCase as BaseTestCase; use RuntimeException; use Tests\Support\CustomTestMacros; use Tests\Support\InteractsWithAuthentication; -use Tests\Support\InteractsWithSettings; +use Tests\Support\InitializesSettings; abstract class TestCase extends BaseTestCase { use CreatesApplication; use CustomTestMacros; use InteractsWithAuthentication; - use InteractsWithSettings; + use InitializesSettings; use LazilyRefreshDatabase; private array $globallyDisabledMiddleware = [ @@ -34,9 +34,7 @@ abstract class TestCase extends BaseTestCase $this->withoutMiddleware($this->globallyDisabledMiddleware); - if (collect(class_uses_recursive($this))->contains(InteractsWithSettings::class)) { - $this->initializeSettings(); - } + $this->initializeSettings(); $this->registerCustomMacros(); } From fb648929712ab4dc7adca1b7916a549fe4896ea4 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 14 Mar 2024 16:26:27 -0700 Subject: [PATCH 08/17] Re-order --- tests/TestCase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 8a3321ac6..9bb7f56e1 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -32,10 +32,10 @@ abstract class TestCase extends BaseTestCase parent::setUp(); + $this->registerCustomMacros(); + $this->withoutMiddleware($this->globallyDisabledMiddleware); $this->initializeSettings(); - - $this->registerCustomMacros(); } } From a28bee86ba1b980db6b76a01e804e51d240c4e3b Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 14 Mar 2024 16:33:49 -0700 Subject: [PATCH 09/17] Extract method --- tests/TestCase.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 9bb7f56e1..f9f4dbae5 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -24,11 +24,7 @@ abstract class TestCase extends BaseTestCase protected function setUp(): void { - if (!file_exists(realpath(__DIR__ . '/../') . '/.env.testing')) { - throw new RuntimeException( - '.env.testing file does not exist. Aborting to avoid wiping your local database' - ); - } + $this->guardAgainstMissingEnv(); parent::setUp(); @@ -38,4 +34,13 @@ abstract class TestCase extends BaseTestCase $this->initializeSettings(); } + + private function guardAgainstMissingEnv(): void + { + if (!file_exists(realpath(__DIR__ . '/../') . '/.env.testing')) { + throw new RuntimeException( + '.env.testing file does not exist. Aborting to avoid wiping your local database.' + ); + } + } } From d1dffb84dca52101a9fd1589e47baeb3498ca8a8 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 18 Mar 2024 12:33:45 -0700 Subject: [PATCH 10/17] Remove InteractsWithSettings trait for remaining tests --- .../Notifications/Email/EmailNotificationsUponCheckinTest.php | 3 --- .../Webhooks/SlackNotificationsUponCheckinTest.php | 3 --- .../Webhooks/SlackNotificationsUponCheckoutTest.php | 3 --- 3 files changed, 9 deletions(-) diff --git a/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php index dbe79c572..4ae415f1e 100644 --- a/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php +++ b/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php @@ -7,7 +7,6 @@ use App\Models\Asset; use App\Models\User; use App\Notifications\CheckinAssetNotification; use Illuminate\Support\Facades\Notification; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; /** @@ -15,8 +14,6 @@ use Tests\TestCase; */ class EmailNotificationsUponCheckinTest extends TestCase { - use InteractsWithSettings; - protected function setUp(): void { parent::setUp(); diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php index b6bb7801a..29bf06d9d 100644 --- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php +++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php @@ -14,7 +14,6 @@ use App\Notifications\CheckinAssetNotification; use App\Notifications\CheckinLicenseSeatNotification; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Notification; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; /** @@ -22,8 +21,6 @@ use Tests\TestCase; */ class SlackNotificationsUponCheckinTest extends TestCase { - use InteractsWithSettings; - protected function setUp(): void { parent::setUp(); diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php index 550f7c5b1..048448cad 100644 --- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php +++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php @@ -16,7 +16,6 @@ use App\Notifications\CheckoutConsumableNotification; use App\Notifications\CheckoutLicenseSeatNotification; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Notification; -use Tests\Support\InteractsWithSettings; use Tests\TestCase; /** @@ -24,8 +23,6 @@ use Tests\TestCase; */ class SlackNotificationsUponCheckoutTest extends TestCase { - use InteractsWithSettings; - protected function setUp(): void { parent::setUp(); From f2a5eac2561158b15970423aabb0e8f0fbef407c Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 20 Mar 2024 23:43:05 +0000 Subject: [PATCH 11/17] Tightened up 2FA text Signed-off-by: snipe --- resources/views/users/edit.blade.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/resources/views/users/edit.blade.php b/resources/views/users/edit.blade.php index 8d24e440b..98fd99124 100755 --- a/resources/views/users/edit.blade.php +++ b/resources/views/users/edit.blade.php @@ -702,7 +702,7 @@ $(document).ready(function() { $("#two_factor_resetrow").removeClass('success'); $("#two_factor_resetrow").removeClass('danger'); $("#two_factor_resetstatus").html(''); - $("#two_factor_reseticon").html(''); + $("#two_factor_reseticon").html(' '); $.ajax({ url: '{{ route('api.users.two_factor_reset', ['id'=> $user->id]) }}', type: 'POST', @@ -715,13 +715,12 @@ $(document).ready(function() { success: function (data) { $("#two_factor_reseticon").html(''); - $("#two_factor_resetstatus").html('' + data.message); + $("#two_factor_resetstatus").html(' ' + data.message + ''); }, error: function (data) { $("#two_factor_reseticon").html(''); - $("#two_factor_reseticon").html(''); - $('#two_factor_resetstatus').text(data.message); + $("#two_factor_resetstatus").html(' ' + data.message + ''); } From bd2812cac1d3f1713e3081908e643f6e34b68945 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 20 Mar 2024 23:43:12 +0000 Subject: [PATCH 12/17] Added new string Signed-off-by: snipe --- resources/lang/en-US/general.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/lang/en-US/general.php b/resources/lang/en-US/general.php index bf1702484..9f9a0e08c 100644 --- a/resources/lang/en-US/general.php +++ b/resources/lang/en-US/general.php @@ -1,6 +1,7 @@ '2FA reset', 'accessories' => 'Accessories', 'activated' => 'Activated', 'accepted_date' => 'Date Accepted', From 1ffbdee156d417c6bfa3a8d539eff1d421eee258 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 20 Mar 2024 23:43:30 +0000 Subject: [PATCH 13/17] Updated 2FA text to not be google authenticator specific Signed-off-by: snipe --- resources/lang/en-US/admin/settings/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lang/en-US/admin/settings/general.php b/resources/lang/en-US/admin/settings/general.php index 33cfd7b41..71fb8eb2c 100644 --- a/resources/lang/en-US/admin/settings/general.php +++ b/resources/lang/en-US/admin/settings/general.php @@ -261,7 +261,7 @@ return [ 'two_factor_enrollment' => 'Two-Factor Enrollment', 'two_factor_enabled_text' => 'Enable Two Factor', 'two_factor_reset' => 'Reset Two-Factor Secret', - 'two_factor_reset_help' => 'This will force the user to enroll their device with Google Authenticator again. This can be useful if their currently enrolled device is lost or stolen. ', + 'two_factor_reset_help' => 'This will force the user to enroll their device with their authenticator app again. This can be useful if their currently enrolled device is lost or stolen. ', 'two_factor_reset_success' => 'Two factor device successfully reset', 'two_factor_reset_error' => 'Two factor device reset failed', 'two_factor_enabled_warning' => 'Enabling two-factor if it is not currently enabled will immediately force you to authenticate with a Google Auth enrolled device. You will have the ability to enroll your device if one is not currently enrolled.', From 2067b1138af7a1a010f81007c90d31112652fcba Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 20 Mar 2024 23:43:58 +0000 Subject: [PATCH 14/17] Added the log item Signed-off-by: snipe --- app/Http/Controllers/Api/UsersController.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 6d32e8b6f..cacfe7662 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -663,6 +663,16 @@ class UsersController extends Controller $user->two_factor_enrolled = 0; $user->save(); + // Log the reset + $logaction = new Actionlog(); + $logaction->target_type = User::class; + $logaction->target_id = $user->id; + $logaction->item_type = User::class; + $logaction->item_id = $user->id; + $logaction->created_at = date('Y-m-d H:i:s'); + $logaction->user_id = Auth::user()->id; + $logaction->logaction('2FA reset'); + return response()->json(['message' => trans('admin/settings/general.two_factor_reset_success')], 200); } catch (\Exception $e) { return response()->json(['message' => trans('admin/settings/general.two_factor_reset_error')], 500); From bc908b854de54eef4f6b13f1edfe326fe3c47301 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 20 Mar 2024 23:44:47 +0000 Subject: [PATCH 15/17] Added icon Signed-off-by: snipe --- app/Presenters/ActionlogPresenter.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Presenters/ActionlogPresenter.php b/app/Presenters/ActionlogPresenter.php index ddff10864..2794b6c5f 100644 --- a/app/Presenters/ActionlogPresenter.php +++ b/app/Presenters/ActionlogPresenter.php @@ -38,10 +38,14 @@ class ActionlogPresenter extends Presenter public function icon() { - + // User related icons if ($this->itemType() == 'user') { + if ($this->actionType()=='2fa reset') { + return 'fa-solid fa-mobile-screen'; + } + if ($this->actionType()=='create new') { return 'fa-solid fa-user-plus'; } @@ -61,6 +65,7 @@ class ActionlogPresenter extends Presenter if ($this->actionType()=='update') { return 'fa-solid fa-user-pen'; } + return 'fa-solid fa-user'; } From 5ed2bd0fb78fb1ca3bb485318aa40f90d1e45029 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 20 Mar 2024 23:52:22 +0000 Subject: [PATCH 16/17] Skip the normal edit observer Signed-off-by: snipe --- app/Http/Controllers/Api/UsersController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index cacfe7662..e9551d51a 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -661,7 +661,7 @@ class UsersController extends Controller $user = User::find($request->get('id')); $user->two_factor_secret = null; $user->two_factor_enrolled = 0; - $user->save(); + $user->saveQuietly(); // Log the reset $logaction = new Actionlog(); From 945e8b402fd78c5e6649d503344dc6014c443b51 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 20 Mar 2024 23:52:51 +0000 Subject: [PATCH 17/17] Only offer the 2FA reset if the user already has 2FA set up Signed-off-by: snipe --- resources/views/users/edit.blade.php | 25 ++++++++++++++----------- resources/views/users/view.blade.php | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/resources/views/users/edit.blade.php b/resources/views/users/edit.blade.php index 98fd99124..9a2a039af 100755 --- a/resources/views/users/edit.blade.php +++ b/resources/views/users/edit.blade.php @@ -499,18 +499,21 @@ @endif - -
-
- {{ trans('admin/settings/general.two_factor_reset') }} - - - + @if ((Auth::user()->isSuperUser()) && ($user->two_factor_active_and_enrolled()) && ($snipeSettings->two_factor_enabled!='0') && ($snipeSettings->two_factor_enabled!='')) + +
+ +
+

{{ trans('admin/settings/general.two_factor_reset_help') }}

+
-
-

{{ trans('admin/settings/general.two_factor_reset_help') }}

-
-
+ @endif + @endif diff --git a/resources/views/users/view.blade.php b/resources/views/users/view.blade.php index a8c24b932..3dbd9ff53 100755 --- a/resources/views/users/view.blade.php +++ b/resources/views/users/view.blade.php @@ -597,7 +597,7 @@
- @if ((Auth::user()->isSuperUser()) && ($snipeSettings->two_factor_enabled!='0') && ($snipeSettings->two_factor_enabled!='')) + @if ((Auth::user()->isSuperUser()) && ($user->two_factor_active_and_enrolled()) && ($snipeSettings->two_factor_enabled!='0') && ($snipeSettings->two_factor_enabled!=''))