test(wallpaper_manager): all tests done
added image_repository tests moved decode_all test to iamge_repository
This commit is contained in:
1 parent
6743772c33
commit
048654f238
3 files changed
+244
-64
No files matched your search
@@ -67,27 +67,25 @@ class EncryptionManagerTests(unittest.TestCase):
|
||||
|
||||
def test_decrypt_rejects_invalid_or_truncated_ciphertext(self) -> None:
|
||||
"""Verify malformed headers and incomplete ciphertext are rejected."""
|
||||
with TemporaryDirectory() as temporary_directory, \
|
||||
self.assertRaisesRegex(ValueError, "Hash mismatch for"):
|
||||
image_root = Path(temporary_directory)
|
||||
assets = Path(__file__).resolve().parents[1] / "assets"
|
||||
args = self.parse_args("--conf-dir", str(image_root),
|
||||
"--folder", str(image_root / "corrupt"),
|
||||
"--private-key", str(assets / "test_private_key.pem"))
|
||||
config = Config.load(args)
|
||||
shutil.copytree(assets / "corrupt" , config.img_dir)
|
||||
malformed_ciphertexts = (
|
||||
b"invalid header",
|
||||
b"Salted__12345678",
|
||||
b"Salted__12345678" + b"x" * 15,
|
||||
b"Salted__12345678" + b"x" * 17,
|
||||
)
|
||||
manager = EncryptionManager()
|
||||
|
||||
with open(config.img_dir / "00001.jpg_enc", "r+b") as f:
|
||||
f.seek(0, 2)
|
||||
size = f.tell()
|
||||
middle = size // 2
|
||||
f.seek(middle)
|
||||
byte = f.read(1)
|
||||
corrupted = bytes([byte[0] ^ 0b00000011])
|
||||
f.seek(middle)
|
||||
f.write(corrupted)
|
||||
|
||||
ImageRepository(config.img_dir).decode_all(config.private_key)
|
||||
with TemporaryDirectory() as temporary_directory:
|
||||
encrypted_file = Path(temporary_directory) / "malformed.enc"
|
||||
for ciphertext in malformed_ciphertexts:
|
||||
with self.subTest(ciphertext_length=len(ciphertext)):
|
||||
encrypted_file.write_bytes(ciphertext)
|
||||
with self.assertRaisesRegex(
|
||||
ValueError, "Invalid or truncated encrypted file"
|
||||
):
|
||||
manager.decrypt(
|
||||
encrypted_file, None, "pass:test passphrase"
|
||||
)
|
||||
|
||||
def test_passphrase_formats(self) -> None:
|
||||
"""Verify byte, literal, and passphrase-file inputs are read correctly."""
|
||||
|
||||
Reference in new issue
Block a user