feat: enhance web engine view with profile isolation and add cache clearing functionality
Some checks failed
Tests & Quality Checks / Test on Python 3.11 (push) Has been cancelled
Tests & Quality Checks / Test on Python 3.12 (push) Has been cancelled
Tests & Quality Checks / Test on Python 3.11-1 (push) Has been cancelled
Tests & Quality Checks / Test on Python 3.12-1 (push) Has been cancelled
Tests & Quality Checks / Test on Python 3.10 (push) Has been cancelled
Tests & Quality Checks / Test on Python 3.11-2 (push) Has been cancelled
Tests & Quality Checks / Test on Python 3.12-2 (push) Has been cancelled
Tests & Quality Checks / Build Artifacts (push) Has been cancelled
Tests & Quality Checks / Build Artifacts-1 (push) Has been cancelled

This commit is contained in:
claudi 2026-03-03 10:22:14 +01:00
parent ba0594c260
commit 705969cdba
5 changed files with 136 additions and 50 deletions

View file

@ -316,7 +316,7 @@ class TestMainWindowSignals:
qtbot.addWidget(window)
with patch.object(window, "_on_drag_started") as mock_handler:
window.drag_interceptor.drag_started.emit(["/path/to/file"])
window.drag_interceptor.drag_started.emit("/path/to/file", "Z:\\local\\file")
mock_handler.assert_called_once()
def test_drag_failed_signal_connection(self, qtbot, sample_config):
@ -325,7 +325,7 @@ class TestMainWindowSignals:
qtbot.addWidget(window)
with patch.object(window, "_on_drag_failed") as mock_handler:
window.drag_interceptor.drag_failed.emit("Error message")
window.drag_interceptor.drag_failed.emit("https://example.com/file", "File not found")
mock_handler.assert_called_once()

View file

@ -8,6 +8,20 @@ from PySide6.QtWebEngineCore import QWebEngineNavigationRequest
from webdrop_bridge.ui.restricted_web_view import RestrictedWebEngineView
def _create_mock_request(url: str) -> MagicMock:
"""Create properly mocked navigation request.
Args:
url: URL string to mock
Returns:
Properly mocked QWebEngineNavigationRequest
"""
request = MagicMock(spec=QWebEngineNavigationRequest)
request.url = MagicMock(return_value=QUrl(url))
return request
class TestRestrictedWebEngineView:
"""Test URL whitelist enforcement."""
@ -16,8 +30,7 @@ class TestRestrictedWebEngineView:
view = RestrictedWebEngineView([])
# Mock navigation request
request = MagicMock(spec=QWebEngineNavigationRequest)
request.url = QUrl("https://example.com/page")
request = _create_mock_request("https://example.com/page")
# Should not reject any URL
view._on_navigation_requested(request)
@ -27,8 +40,7 @@ class TestRestrictedWebEngineView:
"""Test that None allowed_urls means no restrictions."""
view = RestrictedWebEngineView(None)
request = MagicMock(spec=QWebEngineNavigationRequest)
request.url = QUrl("https://blocked.com/page")
request = _create_mock_request("https://blocked.com/page")
view._on_navigation_requested(request)
request.reject.assert_not_called()
@ -37,8 +49,7 @@ class TestRestrictedWebEngineView:
"""Test exact domain matching."""
view = RestrictedWebEngineView(["example.com"])
request = MagicMock(spec=QWebEngineNavigationRequest)
request.url = QUrl("https://example.com/page")
request = _create_mock_request("https://example.com/page")
view._on_navigation_requested(request)
request.reject.assert_not_called()
@ -47,8 +58,7 @@ class TestRestrictedWebEngineView:
"""Test that mismatched domains are rejected."""
view = RestrictedWebEngineView(["example.com"])
request = MagicMock(spec=QWebEngineNavigationRequest)
request.url = QUrl("https://other.com/page")
request = _create_mock_request("https://other.com/page")
with patch("webdrop_bridge.ui.restricted_web_view.QDesktopServices"):
view._on_navigation_requested(request)
@ -58,8 +68,7 @@ class TestRestrictedWebEngineView:
"""Test wildcard pattern matching."""
view = RestrictedWebEngineView(["*.example.com"])
request = MagicMock(spec=QWebEngineNavigationRequest)
request.url = QUrl("https://sub.example.com/page")
request = _create_mock_request("https://sub.example.com/page")
view._on_navigation_requested(request)
request.reject.assert_not_called()
@ -68,8 +77,7 @@ class TestRestrictedWebEngineView:
"""Test that non-matching wildcard patterns are rejected."""
view = RestrictedWebEngineView(["*.example.com"])
request = MagicMock(spec=QWebEngineNavigationRequest)
request.url = QUrl("https://example.org/page")
request = _create_mock_request("https://example.org/page")
with patch("webdrop_bridge.ui.restricted_web_view.QDesktopServices"):
view._on_navigation_requested(request)
@ -79,8 +87,7 @@ class TestRestrictedWebEngineView:
"""Test that localhost is allowed."""
view = RestrictedWebEngineView(["localhost"])
request = MagicMock(spec=QWebEngineNavigationRequest)
request.url = QUrl("http://localhost:8000/page")
request = _create_mock_request("http://localhost:8000/page")
view._on_navigation_requested(request)
request.reject.assert_not_called()
@ -89,8 +96,7 @@ class TestRestrictedWebEngineView:
"""Test that file:// URLs are always allowed."""
view = RestrictedWebEngineView(["example.com"])
request = MagicMock(spec=QWebEngineNavigationRequest)
request.url = QUrl("file:///var/www/index.html")
request = _create_mock_request("file:///var/www/index.html")
view._on_navigation_requested(request)
request.reject.assert_not_called()
@ -100,20 +106,17 @@ class TestRestrictedWebEngineView:
view = RestrictedWebEngineView(["example.com", "test.org"])
# First allowed URL
request1 = MagicMock(spec=QWebEngineNavigationRequest)
request1.url = QUrl("https://example.com/page")
request1 = _create_mock_request("https://example.com/page")
view._on_navigation_requested(request1)
request1.reject.assert_not_called()
# Second allowed URL
request2 = MagicMock(spec=QWebEngineNavigationRequest)
request2.url = QUrl("https://test.org/page")
request2 = _create_mock_request("https://test.org/page")
view._on_navigation_requested(request2)
request2.reject.assert_not_called()
# Non-allowed URL
request3 = MagicMock(spec=QWebEngineNavigationRequest)
request3.url = QUrl("https://blocked.com/page")
request3 = _create_mock_request("https://blocked.com/page")
with patch("webdrop_bridge.ui.restricted_web_view.QDesktopServices"):
view._on_navigation_requested(request3)
request3.reject.assert_called_once()
@ -122,15 +125,13 @@ class TestRestrictedWebEngineView:
"""Test that rejected URLs open in system browser."""
view = RestrictedWebEngineView(["allowed.com"])
request = MagicMock(spec=QWebEngineNavigationRequest)
request.url = QUrl("https://blocked.com/page")
request = _create_mock_request("https://blocked.com/page")
with patch(
"webdrop_bridge.ui.restricted_web_view.QDesktopServices.openUrl"
) as mock_open:
with patch("webdrop_bridge.ui.restricted_web_view.QDesktopServices.openUrl") as mock_open:
view._on_navigation_requested(request)
request.reject.assert_called_once()
mock_open.assert_called_once_with(request.url)
# Check that openUrl was called with a QUrl
mock_open.assert_called_once()
class TestURLAllowedLogic:
@ -167,12 +168,12 @@ class TestURLAllowedLogic:
# Wildcard *.example.com will match sub.example.com
assert view._is_url_allowed(QUrl("https://sub.example.com/page")) is True
# *.example.com will also match example.com (fnmatch behavior)
assert view._is_url_allowed(QUrl("https://example.com/page")) is True
# But not other domains
assert view._is_url_allowed(QUrl("https://other.org/page")) is False
# localhost should work
assert view._is_url_allowed(QUrl("http://localhost:3000")) is True

View file

@ -44,42 +44,49 @@ class TestSettingsDialogInitialization:
qtbot.addWidget(dialog)
assert dialog.tabs is not None
assert dialog.tabs.count() == 5 # Paths, URLs, Logging, Window, Profiles
assert dialog.tabs.count() == 6 # Web Source, Paths, URLs, Logging, Window, Profiles
def test_dialog_has_web_source_tab(self, qtbot, sample_config):
"""Test Web Source tab exists."""
dialog = SettingsDialog(sample_config)
qtbot.addWidget(dialog)
assert dialog.tabs.tabText(0) == "Web Source"
def test_dialog_has_paths_tab(self, qtbot, sample_config):
"""Test Paths tab exists."""
dialog = SettingsDialog(sample_config)
qtbot.addWidget(dialog)
assert dialog.tabs.tabText(0) == "Paths"
assert dialog.tabs.tabText(1) == "Paths"
def test_dialog_has_urls_tab(self, qtbot, sample_config):
"""Test URLs tab exists."""
dialog = SettingsDialog(sample_config)
qtbot.addWidget(dialog)
assert dialog.tabs.tabText(1) == "URLs"
assert dialog.tabs.tabText(2) == "URLs"
def test_dialog_has_logging_tab(self, qtbot, sample_config):
"""Test Logging tab exists."""
dialog = SettingsDialog(sample_config)
qtbot.addWidget(dialog)
assert dialog.tabs.tabText(2) == "Logging"
assert dialog.tabs.tabText(3) == "Logging"
def test_dialog_has_window_tab(self, qtbot, sample_config):
"""Test Window tab exists."""
dialog = SettingsDialog(sample_config)
qtbot.addWidget(dialog)
assert dialog.tabs.tabText(3) == "Window"
assert dialog.tabs.tabText(4) == "Window"
def test_dialog_has_profiles_tab(self, qtbot, sample_config):
"""Test Profiles tab exists."""
dialog = SettingsDialog(sample_config)
qtbot.addWidget(dialog)
assert dialog.tabs.tabText(4) == "Profiles"
assert dialog.tabs.tabText(5) == "Profiles"
class TestPathsTab: