Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions lexical-graph/tests/unit/storage/graph/test_graph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,37 @@ def test_empty_filters_list_or_condition_returns_empty_string(self):
)
result = parse_metadata_filters_recursive(filters)
assert result == ''


class TestEscapeCypherLabelBoundary:
"""Boundary test cases for escape_cypher_label."""

def test_escape_cypher_label_empty_string(self):
result = escape_cypher_label("")
assert isinstance(result, str)

def test_escape_cypher_label_non_string_type_error(self):
with pytest.raises(TypeError):
escape_cypher_label(12345) # type: ignore


class TestParseMetadataFiltersRecursiveBoundary:
"""Boundary and nested filter cases for parse_metadata_filters_recursive."""

def test_parse_metadata_filters_three_level_nesting(self):
nested_filter = {
"AND": [
{"category": {"eq": "finance"}},
{"OR": [{"status": {"eq": "active"}}, {"priority": {"gte": 5}}]},
]
}
result = parse_metadata_filters_recursive(nested_filter)
assert result is not None


class TestFormatterForTypeBoundary:
"""Boundary test cases for formatter_for_type."""

def test_formatter_for_type_empty_string(self):
result = formatter_for_type("")
assert result is not None
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,17 @@ def test_numeric_value_not_quoted(self):
"""A numeric value is emitted unquoted alongside a backtick-quoted key."""
clause = _clause('count', 5, operator=FilterOperator.GT)
assert "source.`count` > 5" in clause


class TestValueEscapingBreakoutPayloads:
"""Adversarial and breakout payload tests for Cypher value escaping."""

def test_escape_cypher_payload_breakout_backtick_quote(self):
payload = "` MATCH (n) DETACH DELETE n; //"
escaped = escape_cypher_label(payload)
assert "\`" in escaped or "``" in escaped or escaped != payload

def test_escape_cypher_payload_unicode_null_bytes(self):
payload = "label\x00_admin"
escaped = escape_cypher_label(payload)
assert "\x00" not in escaped or isinstance(escaped, str)
Loading