"""Tests for checklist 2.1 — URL segment validation. Covers: - Unit tests for _SLUG_RE regex (owner/repo slugs) - Unit tests for _BRANCH_RE regex (branch names) - Integration tests verifying FastAPI enforces the patterns via 422 """ from __future__ import annotations import re import pytest from httpx import AsyncClient from musehub.api.validation import _SLUG_RE, _BRANCH_RE, _FILE_PATH_RE # --------------------------------------------------------------------------- # Unit tests — _SLUG_RE # --------------------------------------------------------------------------- class TestSlugRegexRejects: """Characters and patterns that must be blocked by _SLUG_RE.""" def test_rejects_dotdot(self) -> None: assert re.fullmatch(_SLUG_RE, "..") is None def test_rejects_traversal_path(self) -> None: assert re.fullmatch(_SLUG_RE, "../../etc/passwd") is None def test_rejects_null_byte(self) -> None: assert re.fullmatch(_SLUG_RE, "null\x00byte") is None def test_rejects_script_tag(self) -> None: assert re.fullmatch(_SLUG_RE, "