mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-29 12:35:13 +00:00
fix(drm): keep the input when a cbcs, ClearKey, stripe or segment decrypt fails
This commit is contained in:
@@ -45,6 +45,39 @@ def test_decrypt_round_trip(tmp_path: Path) -> None:
|
||||
assert list(tmp_path.iterdir()) == [path]
|
||||
|
||||
|
||||
def refuse_replace(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
def refuse(self: Path, target: Path) -> None:
|
||||
raise PermissionError(target)
|
||||
|
||||
monkeypatch.setattr(Path, "replace", refuse)
|
||||
|
||||
|
||||
def fail_chunk(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
def fail(self: BlowfishStripe, chunk: bytes) -> bytes:
|
||||
raise ValueError("bad chunk")
|
||||
|
||||
monkeypatch.setattr(BlowfishStripe, "decrypt_chunk", fail)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("break_step", "raises"),
|
||||
[pytest.param(fail_chunk, ValueError, id="decrypt"), pytest.param(refuse_replace, PermissionError, id="replace")],
|
||||
)
|
||||
def test_a_failed_decrypt_keeps_the_input(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, break_step: Any, raises: type[BaseException]
|
||||
) -> None:
|
||||
path = tmp_path / "track.flac"
|
||||
path.write_bytes(stripe_encrypt(os.urandom(CHUNK * 4)))
|
||||
original = path.read_bytes()
|
||||
break_step(monkeypatch)
|
||||
|
||||
with pytest.raises(raises):
|
||||
BlowfishStripe(KEY).decrypt(path)
|
||||
|
||||
assert path.read_bytes() == original
|
||||
assert list(tmp_path.iterdir()) == [path]
|
||||
|
||||
|
||||
def test_short_trailing_chunk_untouched(tmp_path: Path) -> None:
|
||||
# the last stripe starts at CHUNK * 3 and holds only 100 bytes, so it stays clear
|
||||
plain = os.urandom(CHUNK * 3 + 100)
|
||||
|
||||
Reference in New Issue
Block a user