Add URL whitelist enforcement for Kiosk-mode and enhance configuration management

- Introduced `allowed_urls` in configuration to specify whitelisted domains/patterns.
- Implemented `RestrictedWebEngineView` to enforce URL restrictions in the web view.
- Updated `MainWindow` to utilize the new restricted web view and added navigation toolbar.
- Enhanced unit tests for configuration and restricted web view to cover new functionality.
This commit is contained in:
claudi 2026-01-28 11:33:37 +01:00
parent 6bef2f6119
commit 86034358b7
6 changed files with 529 additions and 33 deletions

View file

@ -46,6 +46,7 @@ class TestConfigFromEnv:
f"LOG_LEVEL=DEBUG\n"
f"LOG_FILE={tmp_path / 'test.log'}\n"
f"ALLOWED_ROOTS={root1},{root2}\n"
f"ALLOWED_URLS=example.com,*.test.org\n"
f"WEBAPP_URL=http://localhost:8000\n"
f"WINDOW_WIDTH=1200\n"
f"WINDOW_HEIGHT=800\n"
@ -58,6 +59,7 @@ class TestConfigFromEnv:
assert config.app_version == "2.0.0"
assert config.log_level == "DEBUG"
assert config.allowed_roots == [root1.resolve(), root2.resolve()]
assert config.allowed_urls == ["example.com", "*.test.org"]
assert config.webapp_url == "http://localhost:8000"
assert config.window_width == 1200
assert config.window_height == 800
@ -146,3 +148,39 @@ class TestConfigValidation:
assert len(config.allowed_roots) == 2
assert config.allowed_roots[0] == dir1.resolve()
assert config.allowed_roots[1] == dir2.resolve()
def test_allowed_urls_empty(self, tmp_path):
"""Test that empty ALLOWED_URLS means no URL restriction."""
env_file = tmp_path / ".env"
env_file.write_text("ALLOWED_URLS=\n")
config = Config.from_env(str(env_file))
assert config.allowed_urls == []
def test_allowed_urls_single(self, tmp_path):
"""Test loading single allowed URL."""
env_file = tmp_path / ".env"
env_file.write_text("ALLOWED_URLS=example.com\n")
config = Config.from_env(str(env_file))
assert config.allowed_urls == ["example.com"]
def test_allowed_urls_multiple(self, tmp_path):
"""Test loading multiple allowed URLs."""
env_file = tmp_path / ".env"
env_file.write_text("ALLOWED_URLS=example.com,*.test.org,localhost\n")
config = Config.from_env(str(env_file))
assert config.allowed_urls == ["example.com", "*.test.org", "localhost"]
def test_allowed_urls_with_whitespace(self, tmp_path):
"""Test that whitespace is trimmed from allowed URLs."""
env_file = tmp_path / ".env"
env_file.write_text("ALLOWED_URLS= example.com , test.org \n")
config = Config.from_env(str(env_file))
assert config.allowed_urls == ["example.com", "test.org"]