From ba2e54d5c5fe22a3ba1481c890fc49bcdfa38781 Mon Sep 17 00:00:00 2001 From: Joseph Sutton Date: Thu, 15 Jun 2023 14:33:37 +1200 Subject: [PATCH] tests/auth_log: Ensure tests continue to pass when new log types are added Signed-off-by: Joseph Sutton Reviewed-by: Andrew Bartlett --- python/samba/tests/auth_log_base.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/python/samba/tests/auth_log_base.py b/python/samba/tests/auth_log_base.py index 9f611893cd6..36304ecf796 100644 --- a/python/samba/tests/auth_log_base.py +++ b/python/samba/tests/auth_log_base.py @@ -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 [] -- 2.11.4.GIT