From 3e9558bf5e48149d1548d6c8ab6d6b0a1a130019 Mon Sep 17 00:00:00 2001 From: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Thu, 2 Apr 2026 14:54:18 -0700 Subject: [PATCH] Test a valid hmac but garbage data --- src/documents/tests/test_classifier.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/documents/tests/test_classifier.py b/src/documents/tests/test_classifier.py index 5e8195166..133dc88fe 100644 --- a/src/documents/tests/test_classifier.py +++ b/src/documents/tests/test_classifier.py @@ -385,6 +385,22 @@ class TestClassifier(DirectoriesMixin, TestCase): self.assertIsNone(load_classifier()) + def test_load_corrupt_pickle_valid_hmac(self) -> None: + """ + GIVEN: + - A classifier file with valid HMAC but unparsable pickle data + WHEN: + - An attempt is made to load the classifier + THEN: + - The ClassifierModelCorruptError is raised + """ + garbage_data = b"this is not valid pickle data" + signature = DocumentClassifier._compute_hmac(garbage_data) + Path(settings.MODEL_FILE).write_bytes(signature + garbage_data) + + with self.assertRaises(ClassifierModelCorruptError): + self.classifier.load() + def test_load_tampered_file(self) -> None: """ GIVEN: