Files
JMR-devandClaude Opus 4.8 d407298be4 Update tests for shared helpers and fix test nits
- Cover the new utilities helpers (unpad, crc32, checksumPid type
  preservation, pidFromSerial, safe_join) and drop the now-redundant
  per-module crc32 tests.
- Rename test_unpad_removes_pkcs7_padding to reflect that unpad only
  trusts the trailing pad-length byte rather than validating PKCS#7.
- Replace the KOBO_HASH_KEYS change-detector with a test that documents
  the intentional value pin and checks the ASCII-salt contract.
- Note kgenpids' hybrid import in the test-loader docstring.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24 09:18:01 -05:00

46 lines
1.4 KiB
Python

"""Tests for the Obok (Kobo) plugin core."""
import io
import dedrm_test_utils as U
obok = U.load("obok")
def test_unpad_strips_trailing_pad_length():
# obok.unpad trusts the final byte as the pad length; it is not a validating
# PKCS#7 implementation, so the name reflects what it actually does.
assert obok.unpad(b"data\x04\x04\x04\x04") == b"data"
def test_kobo_hash_keys_are_stable_ascii_salts():
# These four salts are baked into Kobo's userkey derivation
# (sha256(hash + macaddr) -> deviceid). Pinning the exact values is
# intentional: a silent typo here would break decryption for every user, so
# we want a hard regression guard rather than only a shape check.
keys = obok.KOBO_HASH_KEYS
assert keys == ["88b3a2e13", "XzUhGYdFp", "NoCanLook", "QJhwzAtXL"]
# The derivation feeds each salt to ``.encode('ascii')``; pin that contract.
for k in keys:
assert isinstance(k, str) and k
k.encode("ascii")
class _FakeStream:
encoding = "utf-8"
def __init__(self):
self.buffer = io.BytesIO()
def test_safeunbuffered_encodes_str():
fake = _FakeStream()
obok.SafeUnbuffered(fake).write("héllo")
assert fake.buffer.getvalue() == "héllo".encode("utf-8")
def test_safeunbuffered_passes_bytes_through():
fake = _FakeStream()
obok.SafeUnbuffered(fake).write(b"\x00\x01\x02")
assert fake.buffer.getvalue() == b"\x00\x01\x02"