From: Joseph Sutton Date: Tue, 23 May 2023 22:31:53 +0000 (+1200) Subject: tests/auth_log: Factor out isRemote() X-Git-Tag: talloc-2.4.1~402 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=97a5ee4bbb7971ee98c0a8cf314cd39f655f2182;p=thirdparty%2Fsamba.git tests/auth_log: Factor out isRemote() This makes waitForMessages() easier to read. View with ‘git show -b’. Signed-off-by: Joseph Sutton Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/tests/auth_log_base.py b/python/samba/tests/auth_log_base.py index 586719980cb..9c600ff1f39 100644 --- a/python/samba/tests/auth_log_base.py +++ b/python/samba/tests/auth_log_base.py @@ -83,6 +83,26 @@ class AuthLogTestBase(samba.tests.TestCase): super(AuthLogTestBase, self).setUp() type(self).discardMessages() + def isRemote(self, message): + if self.remoteAddress is None: + return True + + supported_types = { + "Authentication", + "Authorization", + } + message_type = message["type"] + if message_type in supported_types: + remote = message[message_type]["remoteAddress"] + else: + return False + + try: + addr = remote.split(":") + return addr[1] == self.remoteAddress + except IndexError: + return False + def waitForMessages(self, isLastExpectedMessage, connection=None): """Wait for all the expected messages to arrive The connection is passed through to keep the connection alive @@ -91,30 +111,10 @@ class AuthLogTestBase(samba.tests.TestCase): def completed(messages): for message in messages: - if isRemote(message) and isLastExpectedMessage(message): + if self.isRemote(message) and isLastExpectedMessage(message): return True return False - def isRemote(message): - if self.remoteAddress is None: - return True - - supported_types = { - "Authentication", - "Authorization", - } - message_type = message["type"] - if message_type in supported_types: - remote = message[message_type]["remoteAddress"] - else: - return False - - try: - addr = remote.split(":") - return addr[1] == self.remoteAddress - except IndexError: - return False - self.connection = connection start_time = time.time() @@ -125,7 +125,7 @@ class AuthLogTestBase(samba.tests.TestCase): return [] self.connection = None - return list(filter(isRemote, self.context["messages"])) + return list(filter(self.isRemote, self.context["messages"])) # Discard any previously queued messages. @classmethod