Skip to content

A free open source IT asset/license management system

Redirect if the app is in demo mode

snipedf41ac66b608
diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php
index 1692602b2b..90af98c62e 100644
--- a/app/Http/Controllers/SettingsController.php
+++ b/app/Http/Controllers/SettingsController.php
@@ -1178,6 +1178,14 @@ class SettingsController extends Controller
return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error'));
}
+ // Check we're not on the public demo, and redirect without saving if we are.
+ // Otherwise this could mess with the demo API explorer
+ if (config('app.lock_passwords')) {
+ return redirect()
+ ->to(route('settings.oauth.index') . '#api-request-filters')
+ ->with('error', trans('general.feature_disabled'));
+ }
+
$setting->block_api_user_agents = $request->boolean('block_api_user_agents');
$blockedUserAgents = trim((string) $request->input('blocked_api_user_agents', ''));
$setting->blocked_api_user_agents = $blockedUserAgents === '' ? null : $blockedUserAgents;
diff --git a/tests/Feature/Settings/ApiRequestFiltersTest.php b/tests/Feature/Settings/ApiRequestFiltersTest.php
index 12484829c5..f7d197a77c 100644
--- a/tests/Feature/Settings/ApiRequestFiltersTest.php
+++ b/tests/Feature/Settings/ApiRequestFiltersTest.php
@@ -102,6 +102,32 @@ class ApiRequestFiltersTest extends TestCase
$this->assertSame("curl/\nfoo-client/", $fresh->blocked_api_user_agents);
}
+ public function test_post_is_blocked_when_app_is_in_demo_mode()
+ {
+ config(['app.lock_passwords' => true]);
+
+ Setting::getSettings()->forceFill([
+ 'block_api_user_agents' => false,
+ 'blocked_api_user_agents' => null,
+ 'block_blank_api_user_agents' => false,
+ ])->save();
+
+ $this->actingAs(User::factory()->superuser()->create())
+ ->post(route('settings.oauth.request_filters.save'), [
+ 'block_api_user_agents' => '1',
+ 'blocked_api_user_agents' => "curl/\nfoo-client/",
+ 'block_blank_api_user_agents' => '1',
+ ])
+ ->assertRedirect()
+ ->assertSessionHas('error');
+
+ // Nothing should have changed.
+ $fresh = Setting::getSettings()->fresh();
+ $this->assertFalse($fresh->block_api_user_agents);
+ $this->assertNull($fresh->blocked_api_user_agents);
+ $this->assertFalse($fresh->block_blank_api_user_agents);
+ }
+
public function test_post_without_master_flag_treats_it_as_false()
{
Setting::getSettings()->forceFill(['block_api_user_agents' => true])->save();