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(security): make the uuid alias boundary test actually run (#7553)

Masyarakat AI Indonesia - FMD70d1d7b1c3db
diff --git a/tests/security/test_collection_id_xss.py b/tests/security/test_collection_id_xss.py
index ee9df8c9ef..22dea71716 100644
--- a/tests/security/test_collection_id_xss.py
+++ b/tests/security/test_collection_id_xss.py
@@ -115,8 +115,8 @@ def test_uuid_malformed_aliases_are_rejected():
"""
real = str(uuid.uuid4())
still_bad = [
- real + "x", # trailing junk (33 chars > 32)
- real[:8] + "z" + real[9:], # non-hex inside a group (33 chars)
+ real + "x", # trailing junk (36 hex digits + 1 junk -> 33, over 32)
+ real[:8] + "z" + real[9:], # non-hex inside a group (36 chars)
" " + real + "x", # padded beyond 32 chars
real * 2, # doubled
]
@@ -126,7 +126,31 @@ def test_uuid_malformed_aliases_are_rejected():
assert exc_info.value.status_code == 404
-def test_uuid_accepted_aliases_match_cpython_uuid():
+# One fresh UUID-derived alias set per collection: 31 hex digits plus a pad
+# keeps a space-padded alias at the accepted length; " " + real would be 37
+# chars, which uuid.UUID rejects for its length and which used to skip this
+# whole test (#7540).
+_HEX31 = str(uuid.uuid4()).replace("-", "")[:31]
+
+_ACCEPTED_ALIASES = [
+ (" " + _HEX31, "leading space: int(..., 16) strips, canonicalises"),
+ (_HEX31 + " ", "trailing space: same"),
+ ("𝟏" * 32, "Unicode MATHEMATICAL BOLD DIGIT 1"),
+ ("١٢" * 16, "Arabic-Indic digits"),
+]
+
+
+ ("alias", "label"),
+ _ACCEPTED_ALIASES,
+ ids=[
+ "leading-space-pad",
+ "trailing-space-pad",
+ "bold-digit-1",
+ "arabic-indic-digits",
+ ],
+)
+def test_uuid_accepted_aliases_match_cpython_uuid(alias, label):
"""Pins the exact set the validator accepts: CPython's uuid.UUID.
The shared helper `web/utils/path_ids.py` and the local twin in
@@ -135,22 +159,15 @@ def test_uuid_accepted_aliases_match_cpython_uuid():
This test pins the boundary explicitly so future Python upgrades
that change ``uuid.UUID``'s accepted set trip the suite.
"""
- real = str(uuid.uuid4())
- accepted_aliases = [
- " " + real, # leading space: int(..., 16) strips, canonicalises
- real + " ", # trailing space: same
- "𝟏" * 32, # Unicode MATHEMATICAL BOLD DIGIT 1
- "١٢" * 16, # Arabic-Indic digits
- ]
- for alias in accepted_aliases:
- # uuid.UUID itself must accept; otherwise the test is stale
- try:
- uuid.UUID(alias)
- except ValueError:
- pytest.skip(f"uuid.UUID no longer accepts {alias!r} on this Python")
- # and so must the validator
- result = _validated_collection_id(alias)
- assert result == str(uuid.UUID(alias))
+ # uuid.UUID itself must accept; otherwise this case is stale on this
+ # Python, so skip it and let each remaining case report (#7540).
+ try:
+ canonical = uuid.UUID(alias)
+ except ValueError:
+ pytest.skip(f"uuid.UUID no longer accepts {alias!r} on this Python")
+ # and so must the validator
+ result = _validated_collection_id(alias)
+ assert result == str(canonical)
def test_both_collection_page_routes_validate():