clipwright/tests/test_media_path_guard.py
pedro-bento 83ad1feaba
All checks were successful
CI / backend-tests (pull_request) Successful in 30s
CI / frontend-build (pull_request) Successful in 29s
refactor: move backend into the clipwright package
Restructure the 37 root-level Python modules into a proper package:
  clipwright/{core,api,pipeline,layouts,media,integrations,tools}

- Rewrite every local import (module-level and deferred) to absolute
  clipwright.<group>.<mod> form; no legacy root shims or re-exports.
- Add clipwright/core/paths.py and route fonts/assets/cookies through it.
- Entry points: uvicorn clipwright.api.app:app; jobs run as
  python -m clipwright.pipeline.main; probe as -m ...quality_probe.
- child_env() appends REPO_ROOT to PYTHONPATH so the -m workers work.
- transcribe_backends: sys.modules key now clipwright.media.scene_detection.
- Tooling: root pyproject.toml (pytest pythonpath=[.], ruff), shared
  requirements-test.txt, CI installs it, Docker PYTHONPATH=/app.
- Tests: all imports/fakes/source-scans repointed; new tests/test_package_layout.py
  enforces no root modules, docstring-only __init__, and no legacy imports.
- Docs/comments updated for the new layout.

Backend: 744 passed, 19 skipped. Frontend lint+build green.
2026-10-04 20:40:38 +01:00

54 lines
2.2 KiB
Python

"""/videos must hand out deliverables, not the whole working directory.
The mount was a plain StaticFiles over OUTPUT_DIR, so anyone holding a job id
(it travels in every clip URL) could also fetch `.owner` (a user uuid),
`.resume.json` (the customer's own webhook_secret), `.transcript_checkpoint.json`
and `<title>_metadata.json`, which carries the full transcript of their video.
All four were verified served, unauthenticated, against production on
7-sep-2026. media_auth shipped the allowlist in 96f0139 but nothing imported it.
This is the path half only: the clips and the untouched source video in the
same directory are still public to whoever has the job id.
"""
import pytest
media_auth = pytest.importorskip("clipwright.api.media_auth")
restoring_static = pytest.importorskip("clipwright.api.restoring_static")
class TestTheGuardIsWiredIn:
def test_the_videos_mount_carries_the_allowlist(self):
app = pytest.importorskip("clipwright.api.app")
mount = next(r for r in app.app.routes
if getattr(r, "name", None) == "videos")
# app._media_guard wraps the allowlist (and adds the free-plan rule
# that refuses a marked job's clean twins, tests/test_watermark_delivery).
assert mount.app.guard is app._media_guard, \
"/videos is serving the working directory with no allowlist"
assert not app._media_guard("job/.resume.json")
assert not app._media_guard("job/x_metadata.json")
assert app._media_guard("job/x_clip_1.mp4")
class TestWhatMayLeave:
@pytest.mark.parametrize("rel", [
"job/clip_1.mp4", "job/subtitled_1_clip_1.mp4", "job/a.webm",
"job/autosubs_1.ass", "job/subs.srt", "job/thumb.jpg", "job/clips.zip",
])
def test_deliverables_pass(self, rel):
assert media_auth.is_servable(rel)
@pytest.mark.parametrize("rel", [
"job/.owner",
"job/.resume.json",
"job/.transcript_checkpoint.json",
"job/My_Video_metadata.json",
"job/clip_1.mp4.layout.json",
"job/.instance",
"../app.py",
"job/../../app.py",
"/etc/passwd",
"",
])
def test_everything_else_is_refused(self, rel):
assert not media_auth.is_servable(rel)