CVE-2020-25722 pytest: assertRaisesLdbError invents a message if you're lazy
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Sun, 24 Oct 2021 02:18:05 +0000 (15:18 +1300)
committerJule Anger <janger@samba.org>
Tue, 9 Nov 2021 19:45:33 +0000 (19:45 +0000)
This makes it easier to convert tests that don't have good messages.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14564

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/__init__.py

index 1b43359e3e86aabfb1da7d2a1af05a09d9fb13f2..ab366c7ed30ebe497acf598738a81d43a443d4fa 100644 (file)
@@ -208,6 +208,8 @@ class TestCase(unittest.TestCase):
 
     def assertRaisesLdbError(self, errcode, message, f, *args, **kwargs):
         """Assert a function raises a particular LdbError."""
+        if message is None:
+            message = f"{f.__name__}(*{args}, **{kwargs})"
         try:
             f(*args, **kwargs)
         except ldb.LdbError as e: