From 914e9d359010361c7fcaae8f17ef6404d5c18805 Mon Sep 17 00:00:00 2001 From: Tim Beale Date: Wed, 16 Jan 2019 13:20:12 +1300 Subject: [PATCH] tests: Refactor auth_log SMB connection to be in a single place This should not alter the behaviour of the tests at all. It just makes it easier to switch over the underlying SMB client bindings. Signed-off-by: Tim Beale Reviewed-by: Jeremy Allison --- python/samba/tests/auth_log.py | 62 +++++++++++----------------------- 1 file changed, 20 insertions(+), 42 deletions(-) diff --git a/python/samba/tests/auth_log.py b/python/samba/tests/auth_log.py index 9c93589638e..e0738770f9f 100644 --- a/python/samba/tests/auth_log.py +++ b/python/samba/tests/auth_log.py @@ -47,6 +47,11 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase): def tearDown(self): super(AuthLogTests, self).tearDown() + def smb_connection(self, creds, use_spnego=True, ntlmv2_auth=True): + lp = self.get_loadparm() + return smb.SMB(self.server, "sysvol", lp=lp, creds=creds, + use_spnego=use_spnego, ntlmv2_auth=ntlmv2_auth) + def _test_rpc_ncacn_np(self, authTypes, creds, service, binding, protection, checkFunction): def isLastExpectedMessage(msg): @@ -706,10 +711,7 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase): msg["Authorization"]["transportProtection"] == "SMB") creds = self.insta_creds(template=self.get_credentials()) - smb.SMB(self.server, - "sysvol", - lp=self.get_loadparm(), - creds=creds) + self.smb_connection(creds) messages = self.waitForMessages(isLastExpectedMessage) self.assertEquals(3, @@ -757,10 +759,7 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase): thrown = False try: - smb.SMB(self.server, - "sysvol", - lp=self.get_loadparm(), - creds=creds) + self.smb_connection(creds) except NTSTATUSError: thrown = True self.assertEquals(thrown, True) @@ -790,10 +789,7 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase): thrown = False try: - smb.SMB(self.server, - "sysvol", - lp=self.get_loadparm(), - creds=creds) + self.smb_connection(creds) except NTSTATUSError: thrown = True self.assertEquals(thrown, True) @@ -918,10 +914,7 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase): creds = self.insta_creds(template=self.get_credentials(), kerberos_state=DONT_USE_KERBEROS) - smb.SMB(self.server, - "sysvol", - lp=self.get_loadparm(), - creds=creds) + self.smb_connection(creds) messages = self.waitForMessages(isLastExpectedMessage) self.assertEquals(2, @@ -961,10 +954,7 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase): thrown = False try: - smb.SMB(self.server, - "sysvol", - lp=self.get_loadparm(), - creds=creds) + self.smb_connection(creds) except NTSTATUSError: thrown = True self.assertEquals(thrown, True) @@ -993,10 +983,7 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase): thrown = False try: - smb.SMB(self.server, - "sysvol", - lp=self.get_loadparm(), - creds=creds) + self.smb_connection(creds) except NTSTATUSError: thrown = True self.assertEquals(thrown, True) @@ -1015,12 +1002,9 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase): creds = self.insta_creds(template=self.get_credentials(), kerberos_state=DONT_USE_KERBEROS) - smb.SMB(self.server, - "sysvol", - lp=self.get_loadparm(), - creds=creds, - ntlmv2_auth=False, - use_spnego=False) + self.smb_connection(creds, + ntlmv2_auth=False, + use_spnego=False) messages = self.waitForMessages(isLastExpectedMessage) self.assertEquals(2, @@ -1060,12 +1044,9 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase): thrown = False try: - smb.SMB(self.server, - "sysvol", - lp=self.get_loadparm(), - creds=creds, - ntlmv2_auth=False, - use_spnego=False) + self.smb_connection(creds, + ntlmv2_auth=False, + use_spnego=False) except NTSTATUSError: thrown = True self.assertEquals(thrown, True) @@ -1094,12 +1075,9 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase): thrown = False try: - smb.SMB(self.server, - "sysvol", - lp=self.get_loadparm(), - creds=creds, - ntlmv2_auth=False, - use_spnego=False) + self.smb_connection(creds, + ntlmv2_auth=False, + use_spnego=False) except NTSTATUSError: thrown = True self.assertEquals(thrown, True)