]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Adjust the barcode to ASN range check and add test case to cover the check 2498/head
authorTrenton H <797416+stumpylog@users.noreply.github.com>
Tue, 24 Jan 2023 18:30:32 +0000 (10:30 -0800)
committerTrenton H <797416+stumpylog@users.noreply.github.com>
Tue, 24 Jan 2023 18:30:32 +0000 (10:30 -0800)
src/documents/consumer.py
src/documents/tests/samples/barcodes/barcode-128-asn-too-large.pdf [new file with mode: 0644]
src/documents/tests/test_barcodes.py

index c583abc6000362e41d6fb9906ebb9fd68739a80f..bc344abb9d7f8a593f74682570a439e82aec5497 100644 (file)
@@ -140,13 +140,13 @@ class Consumer(LoggingMixin):
         if not self.override_asn:
             # check not necessary in case no ASN gets set
             return
-        # Validate the range is above zero and less than int32 max
+        # Validate the range is above zero and less than uint32_t max
         # otherwise, Whoosh can't handle it in the index
-        if self.override_asn < 0 or self.override_asn > 2_147_483_647:
+        if self.override_asn < 0 or self.override_asn > 0xFF_FF_FF_FF:
             self._fail(
                 MESSAGE_ASN_RANGE,
                 f"Not consuming {self.filename}: "
-                "Given ASN is out of range [0, 2147483647]",
+                f"Given ASN {self.override_asn} is out of range [0, 4,294,967,295]",
             )
         if Document.objects.filter(archive_serial_number=self.override_asn).exists():
             self._fail(
diff --git a/src/documents/tests/samples/barcodes/barcode-128-asn-too-large.pdf b/src/documents/tests/samples/barcodes/barcode-128-asn-too-large.pdf
new file mode 100644 (file)
index 0000000..2d190c8
Binary files /dev/null and b/src/documents/tests/samples/barcodes/barcode-128-asn-too-large.pdf differ
index b2d0824edad1ced74656e3805617a56dfcca0307..5bf12a0372d286e12f59f319b2133e62a9733d23 100644 (file)
@@ -9,6 +9,7 @@ from django.test import override_settings
 from django.test import TestCase
 from documents import barcodes
 from documents import tasks
+from documents.consumer import ConsumerError
 from documents.tests.utils import DirectoriesMixin
 from PIL import Image
 
@@ -779,3 +780,23 @@ class TestBarcode(DirectoriesMixin, TestCase):
             args, kwargs = mocked_call.call_args
 
             self.assertEqual(kwargs["override_asn"], 123)
+
+    @override_settings(CONSUMER_ENABLE_ASN_BARCODE=True)
+    def test_asn_too_large(self):
+
+        src = os.path.join(
+            os.path.dirname(__file__),
+            "samples",
+            "barcodes",
+            "barcode-128-asn-too-large.pdf",
+        )
+        dst = os.path.join(self.dirs.scratch_dir, "barcode-128-asn-too-large.pdf")
+        shutil.copy(src, dst)
+
+        with mock.patch("documents.consumer.Consumer._send_progress"):
+            self.assertRaisesMessage(
+                ConsumerError,
+                "Given ASN 4294967296 is out of range [0, 4,294,967,295]",
+                tasks.consume_file,
+                dst,
+            )