clipwright/tests/test_media_path_guard.py
juancarlos.cavero cb37ae3aec feat(watermark): serve the free-plan mark as a copy, so paying removes it from existing clips
Every file the pipeline and the clip editor write is now clean. On the free
plan the served file is a wm_<final> copy with the mark burned in
(main.mark_delivery, last step after captions; app._deliver for the editor
endpoints, decided from the caller's plan), and both twins go to R2. An
upgrade re-points the user's library at the clean twins from the Stripe
webhook (cloud.videos.unmark_user_library): no render, no source video,
and the dashboard chases the job result until no served URL carries wm_.

Before, the mark rode the reframe encode, so every derivative inherited it
and the upgrade modal's "upgrade to remove the watermark" was false for the
clips already made. The first cancellation for "clip quality" (29-sep) was a
user who paid 15 minutes after their first job and kept the mark on every
download and restyle.

- /videos guard refuses a marked job's clean deliverables (.marked dotfile),
  so the twin cannot be fetched by stripping the prefix off a URL; editor
  scratch files stay servable. Re-checked after an R2 restore.
- Walk-backs treat wm_ as the outermost layer; _canonical_clip_file globs it.
- Jobs from before this scheme (mark burned into the canonical) never get a
  second copy; a failed mark still serves under the wm_ name.
- Watermark notice once per job when the clips land on a free account, and
  before the first download if skipped; tracked with source=results|download.
  Upsell/banner/win-back copy now promise the instant removal.
2026-10-01 09:35:53 +02: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("media_auth")
restoring_static = pytest.importorskip("restoring_static")
class TestTheGuardIsWiredIn:
def test_the_videos_mount_carries_the_allowlist(self):
app = pytest.importorskip("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)