Scope gallery image endpoints by owner (#3001)

This commit is contained in:
Vykos
2026-06-07 12:51:21 +02:00
committed by GitHub
parent f2a79aaf5c
commit 67aeea4f8b
3 changed files with 192 additions and 57 deletions
+6 -29
View File
@@ -1,34 +1,11 @@
import ast
from pathlib import Path
def test_gallery_url_normalization_bug():
# Read and parse the actual source file
source_path = Path("routes/gallery_routes.py")
assert source_path.exists(), "gallery_routes.py could not be found"
source = source_path.read_text(encoding="utf-8")
tree = ast.parse(source)
# Locate the comparison node within harmonize_image that references ep.base_url and base
compare_node = None
for node in ast.walk(tree):
if isinstance(node, ast.Compare):
segment = ast.get_source_segment(source, node) or ""
if "ep.base_url" in segment and "base" in segment and "_norm_url" not in segment:
compare_node = node
break
assert compare_node is not None, "Could not find the ep.base_url vs base comparison inside gallery_routes.py"
# Compile the compare node into an expression
expr = ast.Expression(body=compare_node)
compiled_code = compile(expr, "<string>", "eval")
from routes.gallery_routes import _normalize_image_endpoint_base
def check_match(ep_url: str, base_url: str) -> bool:
class MockEP:
def __init__(self, url):
self.base_url = url
return eval(compiled_code, {}, {"ep": MockEP(ep_url), "base": base_url})
return (
_normalize_image_endpoint_base(ep_url)
== _normalize_image_endpoint_base(base_url)
)
# Test cases that SHOULD NOT match under a correct implementation
# (Buggy rstrip('/v1') logic incorrectly treats these as equal)