Strengthen weak-assertion / false-confidence tests:
- test_alfcrypto: replace the tautological ctx_init determinism check
with an independent golden vector, and add a golden Topaz decrypt
vector that does not rely on the test's own inverse helper (so a
systematic cipher bug is caught, not just round-trip symmetry). Pin
the PC1 bad-key assertion to match="Bad key length", and load
alfcrypto via the dedrm package so the test exercises the same module
object that topazextract/mobidedrm import.
- test_mobidedrm: pin the PC1 bad-key assertion to the guard message.
- test_topazextract: make the path-traversal regression rely on the
depth-independent positive oracle (the sanitised file must land inside
outdir, which fails against the pre-fix code) plus an exact-contents
check, instead of brittle parent-path negatives.
- test_erdr2pml: narrow the import skip to only the missing-cgi case so
a genuinely broken module fails loudly instead of silently skipping.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
"""Tests for mobidedrm helpers."""
|
|
|
|
import pytest
|
|
|
|
import dedrm_test_utils as U
|
|
|
|
md = U.load("mobidedrm", package="dedrm")
|
|
|
|
|
|
def test_pc1_roundtrip():
|
|
key = bytes(range(16))
|
|
plaintext = b"cookie-data-1234"
|
|
ciphertext = md.PC1(key, plaintext, decryption=False)
|
|
assert ciphertext != plaintext
|
|
assert md.PC1(key, ciphertext, decryption=True) == plaintext
|
|
|
|
|
|
def test_pc1_rejects_bad_key_length():
|
|
with pytest.raises(Exception, match="Bad key length"):
|
|
md.PC1(b"\x00" * 8, b"data............", decryption=False)
|
|
|
|
|
|
def test_trailing_data_entries():
|
|
buf = b"XXXX" + bytes([0x82])
|
|
# bit 1 set -> one size entry encoded in the final byte (0x82 -> 2)
|
|
assert md.getSizeOfTrailingDataEntries(buf, len(buf), 0b10) == 2
|
|
# no flags -> no trailing data
|
|
assert md.getSizeOfTrailingDataEntries(buf, len(buf), 0) == 0
|
|
# bit 0 set -> multibyte entry: (last_byte & 3) + 1
|
|
assert md.getSizeOfTrailingDataEntries(b"ABCDE", 5, 1) == 2
|
|
|
|
|
|
def test_crc32_known_vector():
|
|
assert md.crc32(b"test") == 4181434640
|