Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

test(notifications): regression coverage for service_url redaction and egress-refusal log redaction (#5806)

LearningCircuit8bf5df892440
diff --git a/tests/notifications/test_egress_refusal_log_redaction.py b/tests/notifications/test_egress_refusal_log_redaction.py
new file mode 100644
index 0000000000..ba243ad19b
--- /dev/null
+++ b/tests/notifications/test_egress_refusal_log_redaction.py
@@ -0,0 +1,72 @@
+"""Regression: an egress-refused notification URL must be logged redacted.
+
+``_filter_urls_by_egress_policy`` audit-logs URLs it refuses. A raw
+http/https notification URL can carry a token in its path or query
+(Slack/webhook-style), so logging the raw value slips a secret past the
+name-based sensitive-logging hook. The refusal log must record only
+``scheme://host`` via ``redact_url_for_log``.
+"""
+
+from types import SimpleNamespace
+
+from loguru import logger
+
+from local_deep_research.notifications.manager import NotificationManager
+from local_deep_research.security.egress import policy as egress_policy
+
+
+_TOKEN = "S3cretWebhookToken1234567890"
+_REFUSED_URL = (
+ f"https://hooks.example.com/services/T000/B000/{_TOKEN}?auth={_TOKEN}"
+)
+
+
+def test_refused_url_is_redacted_in_audit_log(mocker):
+ """The refusal warning must not contain the token; only scheme+host."""
+ snapshot = {"search.tool": "searxng"}
+ manager = NotificationManager(
+ settings_snapshot=snapshot, user_id="test_user"
+ )
+
+ # Force a refusal decision for the http(s) URL and neutralise the
+ # snapshot->context construction so the real policy engine is bypassed.
+ fake_ctx = SimpleNamespace(scope=SimpleNamespace(value="public_only"))
+ mocker.patch.object(
+ egress_policy, "context_from_snapshot", return_value=fake_ctx
+ )
+ mocker.patch.object(
+ egress_policy,
+ "evaluate_url",
+ return_value=SimpleNamespace(allowed=False, reason="blocked host"),
+ )
+
+ records = []
+ # The package disables its own loguru namespace in __init__; enable it so
+ # the in-module audit warnings actually reach our sink. Restore in finally.
+ logger.enable("local_deep_research")
+ sink_id = logger.add(
+ lambda message: records.append(message.record),
+ level="WARNING",
+ filter=lambda r: r["extra"].get("policy_audit") is True,
+ )
+ try:
+ result = manager._filter_urls_by_egress_policy(_REFUSED_URL)
+ finally:
+ logger.remove(sink_id)
+ logger.disable("local_deep_research")
+
+ # Refused URL is dropped from the dispatch string.
+ assert result == ""
+
+ refusal = [
+ r
+ for r in records
+ if r["message"] == "notification URL refused by egress policy"
+ ]
+ assert refusal, "expected an egress-refusal audit log record"
+ logged_url = refusal[0]["extra"]["url"]
+
+ # Only scheme + host survive; no token in path or query.
+ assert logged_url == "https://hooks.example.com"
+ assert _TOKEN not in logged_url
+ assert _TOKEN not in str(refusal[0]["extra"])
diff --git a/tests/security/test_notification_service_url_redaction.py b/tests/security/test_notification_service_url_redaction.py
new file mode 100644
index 0000000000..e43f2a5360
--- /dev/null
+++ b/tests/security/test_notification_service_url_redaction.py
@@ -0,0 +1,47 @@
+"""Regression coverage for credential-bearing notification service URLs.
+
+The service_url name makes the configured value sensitive while its textarea
+control preserves explicit clearing. Use the shipped metadata so these checks
+catch losing name-based redaction without relying on a password-only override.
+"""
+
+import json
+from pathlib import Path
+
+from local_deep_research.security.data_sanitizer import DataSanitizer
+
+_KEY = "notifications.service_url"
+_SECRET = "discord://1234567890/abcdEFGH_realtoken"
+
+
+def _service_url_ui_element() -> str:
+ path = (
+ Path(__file__).resolve().parents[2]
+ / "src"
+ / "local_deep_research"
+ / "defaults"
+ / "default_settings.json"
+ )
+ return json.loads(path.read_text())[_KEY]["ui_element"]
+
+
+def test_service_url_is_sensitive_with_shipped_metadata():
+ """Removing service_url from the sensitive names must not expose it."""
+ assert (
+ DataSanitizer.is_sensitive_setting(_KEY, _service_url_ui_element())
+ is True
+ )
+
+
+def test_redact_value_masks_configured_service_url():
+ """A configured service URL is masked using its actual control type."""
+ redacted = DataSanitizer.redact_value(
+ _KEY, _service_url_ui_element(), _SECRET
+ )
+ assert redacted == DataSanitizer.REDACTION_TEXT
+ assert _SECRET not in str(redacted)
+
+
+def test_empty_service_url_passes_through():
+ """An unset value stays readable so the UI can tell configured from not."""
+ assert DataSanitizer.redact_value(_KEY, _service_url_ui_element(), "") == ""