TestPathValidation Class — langchain Architecture
Architecture documentation for the TestPathValidation class in test_anthropic_tools.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 9599afe1_8f2e_3733_d25a_c88263c5beba["TestPathValidation"] ed6269fc_1a0e_6b64_f39f_7fdd1e5bcdc1["test_anthropic_tools.py"] 9599afe1_8f2e_3733_d25a_c88263c5beba -->|defined in| ed6269fc_1a0e_6b64_f39f_7fdd1e5bcdc1 197e3c5b_e452_7cc3_3c4a_c8624399625b["test_basic_path_normalization()"] 9599afe1_8f2e_3733_d25a_c88263c5beba -->|method| 197e3c5b_e452_7cc3_3c4a_c8624399625b cd281996_3ab9_a665_33f3_7192025038ae["test_path_traversal_blocked()"] 9599afe1_8f2e_3733_d25a_c88263c5beba -->|method| cd281996_3ab9_a665_33f3_7192025038ae ad7b811c_8e18_660c_351b_524e108f597a["test_allowed_prefixes()"] 9599afe1_8f2e_3733_d25a_c88263c5beba -->|method| ad7b811c_8e18_660c_351b_524e108f597a be7d0b10_b401_d01d_8733_10f5174645c8["test_memories_prefix()"] 9599afe1_8f2e_3733_d25a_c88263c5beba -->|method| be7d0b10_b401_d01d_8733_10f5174645c8
Relationship Graph
Source Code
libs/partners/anthropic/tests/unit_tests/middleware/test_anthropic_tools.py lines 17–63
class TestPathValidation:
"""Test path validation and security."""
def test_basic_path_normalization(self) -> None:
"""Test basic path normalization."""
assert _validate_path("/foo/bar") == "/foo/bar"
assert _validate_path("foo/bar") == "/foo/bar"
assert _validate_path("/foo//bar") == "/foo/bar"
assert _validate_path("/foo/./bar") == "/foo/bar"
def test_path_traversal_blocked(self) -> None:
"""Test that path traversal attempts are blocked."""
with pytest.raises(ValueError, match="Path traversal not allowed"):
_validate_path("/foo/../etc/passwd")
with pytest.raises(ValueError, match="Path traversal not allowed"):
_validate_path("../etc/passwd")
with pytest.raises(ValueError, match="Path traversal not allowed"):
_validate_path("~/.ssh/id_rsa")
def test_allowed_prefixes(self) -> None:
"""Test path prefix validation."""
# Should pass
assert (
_validate_path("/workspace/file.txt", allowed_prefixes=["/workspace"])
== "/workspace/file.txt"
)
# Should fail
with pytest.raises(ValueError, match="Path must start with"):
_validate_path("/etc/passwd", allowed_prefixes=["/workspace"])
with pytest.raises(ValueError, match="Path must start with"):
_validate_path(
"/workspacemalicious/file.txt", allowed_prefixes=["/workspace/"]
)
def test_memories_prefix(self) -> None:
"""Test /memories prefix validation for memory tools."""
assert (
_validate_path("/memories/notes.txt", allowed_prefixes=["/memories"])
== "/memories/notes.txt"
)
with pytest.raises(ValueError, match="Path must start with"):
_validate_path("/other/notes.txt", allowed_prefixes=["/memories"])
Source
Frequently Asked Questions
What is the TestPathValidation class?
TestPathValidation is a class in the langchain codebase, defined in libs/partners/anthropic/tests/unit_tests/middleware/test_anthropic_tools.py.
Where is TestPathValidation defined?
TestPathValidation is defined in libs/partners/anthropic/tests/unit_tests/middleware/test_anthropic_tools.py at line 17.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free