Initial commit: hardened DeerFlow factory
Vendored deer-flow upstream (bytedance/deer-flow) plus prompt-injection hardening: - New deerflow.security package: content_delimiter, html_cleaner, sanitizer (8 layers — invisible chars, control chars, symbols, NFC, PUA, tag chars, horizontal whitespace collapse with newline/tab preservation, length cap) - New deerflow.community.searx package: web_search, web_fetch, image_search backed by a private SearX instance, every external string sanitized and wrapped in <<<EXTERNAL_UNTRUSTED_CONTENT>>> delimiters - All native community web providers (ddg_search, tavily, exa, firecrawl, jina_ai, infoquest, image_search) replaced with hard-fail stubs that raise NativeWebToolDisabledError at import time, so a misconfigured tool.use path fails loud rather than silently falling back to unsanitized output - Native client back-doors (jina_client.py, infoquest_client.py) stubbed too - Native-tool tests quarantined under tests/_disabled_native/ (collect_ignore_glob via local conftest.py) - Sanitizer Layer 7 fix: only collapse horizontal whitespace, preserve newlines and tabs so list/table structure survives - Hardened runtime config.yaml references only the searx-backed tools - Factory overlay (backend/) kept in sync with deer-flow tree as a reference / source See HARDENING.md for the full audit trail and verification steps.
This commit is contained in:
99
deer-flow/backend/tests/test_provisioner_kubeconfig.py
Normal file
99
deer-flow/backend/tests/test_provisioner_kubeconfig.py
Normal file
@@ -0,0 +1,99 @@
|
||||
"""Regression tests for provisioner kubeconfig path handling."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
def test_wait_for_kubeconfig_rejects_directory(tmp_path, provisioner_module):
|
||||
"""Directory mount at kubeconfig path should fail fast with clear error."""
|
||||
kubeconfig_dir = tmp_path / "config_dir"
|
||||
kubeconfig_dir.mkdir()
|
||||
|
||||
provisioner_module.KUBECONFIG_PATH = str(kubeconfig_dir)
|
||||
|
||||
try:
|
||||
provisioner_module._wait_for_kubeconfig(timeout=1)
|
||||
raise AssertionError("Expected RuntimeError for directory kubeconfig path")
|
||||
except RuntimeError as exc:
|
||||
assert "directory" in str(exc)
|
||||
|
||||
|
||||
def test_wait_for_kubeconfig_accepts_file(tmp_path, provisioner_module):
|
||||
"""Regular file mount should pass readiness wait."""
|
||||
kubeconfig_file = tmp_path / "config"
|
||||
kubeconfig_file.write_text("apiVersion: v1\n")
|
||||
|
||||
provisioner_module.KUBECONFIG_PATH = str(kubeconfig_file)
|
||||
|
||||
# Should return immediately without raising.
|
||||
provisioner_module._wait_for_kubeconfig(timeout=1)
|
||||
|
||||
|
||||
def test_init_k8s_client_rejects_directory_path(tmp_path, provisioner_module):
|
||||
"""KUBECONFIG_PATH that resolves to a directory should be rejected."""
|
||||
kubeconfig_dir = tmp_path / "config_dir"
|
||||
kubeconfig_dir.mkdir()
|
||||
|
||||
provisioner_module.KUBECONFIG_PATH = str(kubeconfig_dir)
|
||||
|
||||
try:
|
||||
provisioner_module._init_k8s_client()
|
||||
raise AssertionError("Expected RuntimeError for directory kubeconfig path")
|
||||
except RuntimeError as exc:
|
||||
assert "expected a file" in str(exc)
|
||||
|
||||
|
||||
def test_init_k8s_client_uses_file_kubeconfig(tmp_path, monkeypatch, provisioner_module):
|
||||
"""When file exists, provisioner should load kubeconfig file path."""
|
||||
kubeconfig_file = tmp_path / "config"
|
||||
kubeconfig_file.write_text("apiVersion: v1\n")
|
||||
|
||||
called: dict[str, object] = {}
|
||||
|
||||
def fake_load_kube_config(config_file: str):
|
||||
called["config_file"] = config_file
|
||||
|
||||
monkeypatch.setattr(
|
||||
provisioner_module.k8s_config,
|
||||
"load_kube_config",
|
||||
fake_load_kube_config,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
provisioner_module.k8s_client,
|
||||
"CoreV1Api",
|
||||
lambda *args, **kwargs: "core-v1",
|
||||
)
|
||||
|
||||
provisioner_module.KUBECONFIG_PATH = str(kubeconfig_file)
|
||||
|
||||
result = provisioner_module._init_k8s_client()
|
||||
|
||||
assert called["config_file"] == str(kubeconfig_file)
|
||||
assert result == "core-v1"
|
||||
|
||||
|
||||
def test_init_k8s_client_falls_back_to_incluster_when_missing(tmp_path, monkeypatch, provisioner_module):
|
||||
"""When kubeconfig file is missing, in-cluster config should be attempted."""
|
||||
missing_path = tmp_path / "missing-config"
|
||||
|
||||
calls: dict[str, int] = {"incluster": 0}
|
||||
|
||||
def fake_load_incluster_config():
|
||||
calls["incluster"] += 1
|
||||
|
||||
monkeypatch.setattr(
|
||||
provisioner_module.k8s_config,
|
||||
"load_incluster_config",
|
||||
fake_load_incluster_config,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
provisioner_module.k8s_client,
|
||||
"CoreV1Api",
|
||||
lambda *args, **kwargs: "core-v1",
|
||||
)
|
||||
|
||||
provisioner_module.KUBECONFIG_PATH = str(missing_path)
|
||||
|
||||
result = provisioner_module._init_k8s_client()
|
||||
|
||||
assert calls["incluster"] == 1
|
||||
assert result == "core-v1"
|
||||
Reference in New Issue
Block a user