]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
tests/auth_log: Ensure tests continue to pass when new log types are added
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Thu, 15 Jun 2023 02:33:37 +0000 (14:33 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 15 Jun 2023 05:29:28 +0000 (05:29 +0000)
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/auth_log_base.py

index 9f611893cd6923903dbc8e9cf22a4d5809c173b8..36304ecf79685654e9e2543a5de692a448060431 100644 (file)
@@ -28,6 +28,22 @@ import os
 import re
 
 
+def default_msg_filter(msg):
+    # When our authentication logging tests were written, these were the only
+    # supported message types. The tests were built on the assumption that no
+    # new types would be added, and violating this assumption will result in
+    # many tests failing as they receive messages that they weren’t
+    # expecting. To allow these tests to continue to pass, this default filter
+    # makes sure that only messages for which the tests are prepared pass
+    # though.
+    default_supported_types = {
+        "Authentication",
+        "Authorization",
+    }
+
+    return msg['type'] in default_supported_types
+
+
 class NoMessageException(Exception):
     pass
 
@@ -108,16 +124,22 @@ class AuthLogTestBase(samba.tests.TestCase):
         except IndexError:
             return False
 
-    def waitForMessages(self, isLastExpectedMessage, connection=None):
+    def waitForMessages(self, isLastExpectedMessage, connection=None, *,
+                        msgFilter=default_msg_filter):
         """Wait for all the expected messages to arrive
         The connection is passed through to keep the connection alive
         until all the logging messages have been received.
+
+        By default, only Authentication and Authorization messages will be
+        returned, so that old tests continue to pass. To receive all messages,
+        pass msgFilter=None.
+
         """
 
         messages = []
         while True:
             try:
-                msg = self.nextMessage()
+                msg = self.nextMessage(msgFilter=msgFilter)
             except NoMessageException:
                 return []