Added 404 response for non-existing setting categories

- Added test to cover.
This commit is contained in:
Dan Brown 2022-03-28 11:16:20 +01:00
parent 895f656897
commit 7c12920dc8
No known key found for this signature in database
GPG key ID: 46D9F943C24A2EF9
2 changed files with 19 additions and 0 deletions

View file

@ -11,6 +11,8 @@ class SettingController extends Controller
{
protected ImageRepo $imageRepo;
protected array $settingCategories = ['features', 'customization', 'registration'];
public function __construct(ImageRepo $imageRepo)
{
$this->imageRepo = $imageRepo;
@ -21,6 +23,7 @@ class SettingController extends Controller
*/
public function index(string $category)
{
$this->ensureCategoryExists($category);
$this->checkPermission('settings-manage');
$this->setPageTitle(trans('settings.settings'));
@ -39,6 +42,7 @@ class SettingController extends Controller
*/
public function update(Request $request, string $category)
{
$this->ensureCategoryExists($category);
$this->preventAccessInDemoMode();
$this->checkPermission('settings-manage');
$this->validate($request, [
@ -73,4 +77,11 @@ class SettingController extends Controller
return redirect("/settings/${category}");
}
protected function ensureCategoryExists(string $category): void
{
if (!in_array($category, $this->settingCategories)) {
abort(404);
}
}
}

View file

@ -28,4 +28,12 @@ class SettingsTest extends TestCase
$resp->assertElementExists("form[action$=\"/settings/{$category}\"]");
}
}
public function test_not_found_setting_category_throws_404()
{
$resp = $this->asAdmin()->get('/settings/biscuits');
$resp->assertStatus(404);
$resp->assertSee('Page Not Found');
}
}