fix(drm): keep the input when a cbcs, ClearKey, stripe or segment decrypt fails

This commit is contained in:
imSp4rky
2026-11-28 18:27:40 -07:00
parent 79cc16d290
commit 5a2680d63d
8 changed files with 214 additions and 36 deletions
+37
View File
@@ -125,6 +125,43 @@ def test_segment_decrypter_keys_from_the_init_segment(tmp_path: Path, stub_mp4de
assert f"1:{KEY}" in decrypter.key_args
@POSIX_STUBS
@pytest.mark.parametrize(
("output", "stderr", "raises"),
[
pytest.param(
b"partial", "ERROR: failed to process the file (-10)\n", subprocess.CalledProcessError, id="exit-0-error"
),
pytest.param(None, "", RuntimeError, id="exit-0-no-output"),
pytest.param(b"", "", RuntimeError, id="exit-0-empty-output"),
],
)
def test_a_failed_segment_decrypt_keeps_the_segment(
tmp_path: Path,
mp4decrypt_writes: Callable[[bytes | None, int, str], None],
output: bytes | None,
stderr: str,
raises: type[BaseException],
) -> None:
mp4decrypt_writes(output, 0, stderr)
drm = _widevine(A)
drm.content_keys[A] = KEY
segment_dir = tmp_path / "segments"
segment_dir.mkdir()
segment = segment_dir / "000.mp4"
segment.write_bytes(b"segment-0")
(segment_dir / "000.mp4.dec").write_bytes(b"stale")
decrypter = SegmentDecrypter(drm, movie(encv(A)), tmp_path / "work", workers=1)
decrypter.submit(segment)
with pytest.raises(raises) as caught:
decrypter.finish()
assert segment.read_bytes() == b"segment-0"
assert list(segment_dir.iterdir()) == [segment]
assert categorize_exception(caught.value).error_code == APIErrorCode.DRM_ERROR
@pytest.mark.parametrize(("key_kid", "usable"), [(A, True), (B, False)], ids=["track-kid-keyed", "other-kid-only"])
def test_segment_decrypt_needs_a_key_for_a_kidless_track(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, key_kid: UUID, usable: bool