tests (audit_auth)_log: PEP8 cleanup.
authorGary Lockyer <gary@catalyst.net.nz>
Sun, 16 Dec 2018 21:04:42 +0000 (10:04 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 20 Dec 2018 22:40:26 +0000 (23:40 +0100)
Remove Flake8 warnings from the audit and authentication JSON log
tests.

Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/audit_log_dsdb.py
python/samba/tests/audit_log_pass_change.py
python/samba/tests/auth_log.py
python/samba/tests/auth_log_base.py
python/samba/tests/auth_log_ncalrpc.py
python/samba/tests/auth_log_netlogon.py
python/samba/tests/auth_log_netlogon_bad_creds.py
python/samba/tests/auth_log_samlogon.py

index 883d27e42e7b31ff5dfaf0e61dfe26f104e5bea5..0471c22f2435c6e1bb27f3f32a446bb501a07842 100644 (file)
@@ -40,7 +40,7 @@ class AuditLogDsdbTests(AuditLogTestBase):
 
     def setUp(self):
         self.message_type = MSG_DSDB_LOG
-        self.event_type   = DSDB_EVENT_NAME
+        self.event_type = DSDB_EVENT_NAME
         super(AuditLogDsdbTests, self).setUp()
 
         self.remoteAddress = os.environ["CLIENT_IP"]
index 8ece235f55855f790af05a043a293f810ec97a6a..d580698b3ba7f8e8a78a6059da012208dd237829 100644 (file)
@@ -45,7 +45,7 @@ class AuditLogPassChangeTests(AuditLogTestBase):
 
     def setUp(self):
         self.message_type = MSG_DSDB_PWD_LOG
-        self.event_type   = DSDB_PWD_EVENT_NAME
+        self.event_type = DSDB_PWD_EVENT_NAME
         super(AuditLogPassChangeTests, self).setUp()
 
         self.remoteAddress = os.environ["CLIENT_IP"]
@@ -97,7 +97,7 @@ class AuditLogPassChangeTests(AuditLogTestBase):
     # Discard the messages from the setup code
     #
     def discardSetupMessages(self, dn):
-        messages = self.waitForMessages(1, dn=dn)
+        self.waitForMessages(1, dn=dn)
         self.discardMessages()
 
     def tearDown(self):
index 14da516f200fdfefa03e7df52cfcd084bb9d6ab5..c0d0aab94aa6d8120abeca31c6bbeac6f876a4e5 100644 (file)
@@ -77,7 +77,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
         # Turn "[foo,bar]" into a list ("foo", "bar") to test
         # lambda x: x removes anything that evaluates to False,
         # including empty strings, so we handle "" as well
-        binding_list = list(filter(lambda x: x, re.compile('[\[,\]]').split(binding)))
+        binding_list = \
+            list(filter(lambda x: x, re.compile('[\[,\]]').split(binding)))
 
         # Handle explicit smb2, smb1 or auto negotiation
         if "smb2" in binding_list:
@@ -103,16 +104,16 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
             EVT_ID_SUCCESSFUL_LOGON, msg["Authentication"]["eventId"])
         self.assertEquals(
             EVT_LOGON_NETWORK, msg["Authentication"]["logonType"])
-        self._assert_ncacn_np_serviceDescription(binding,
-                                                 msg["Authentication"]["serviceDescription"])
+        self._assert_ncacn_np_serviceDescription(
+            binding, msg["Authentication"]["serviceDescription"])
         self.assertEquals(authTypes[1],
                           msg["Authentication"]["authDescription"])
 
         # Check the second message it should be an Authorization
         msg = messages[1]
         self.assertEquals("Authorization", msg["type"])
-        self._assert_ncacn_np_serviceDescription(binding,
-                                                 msg["Authorization"]["serviceDescription"])
+        self._assert_ncacn_np_serviceDescription(
+            binding, msg["Authorization"]["serviceDescription"])
         self.assertEquals(authTypes[2], msg["Authorization"]["authType"])
         self.assertEquals("SMB", msg["Authorization"]["transportProtection"])
         self.assertTrue(self.is_guid(msg["Authorization"]["sessionId"]))
@@ -183,8 +184,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
         # Check the third message it should be an Authorization
         msg = messages[2]
         self.assertEquals("Authorization", msg["type"])
-        self._assert_ncacn_np_serviceDescription(binding,
-                                                 msg["Authorization"]["serviceDescription"])
+        self._assert_ncacn_np_serviceDescription(
+            binding, msg["Authorization"]["serviceDescription"])
         self.assertEquals(authTypes[3], msg["Authorization"]["authType"])
         self.assertEquals("SMB", msg["Authorization"]["transportProtection"])
         self.assertTrue(self.is_guid(msg["Authorization"]["sessionId"]))
@@ -674,7 +675,7 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
     def test_ldap_anonymous_access(self):
         def isLastExpectedMessage(msg):
             return (msg["type"] == "Authorization" and
-                    msg["Authorization"]["serviceDescription"]  == "LDAP" and
+                    msg["Authorization"]["serviceDescription"] == "LDAP" and
                     msg["Authorization"]["transportProtection"] == "TLS" and
                     msg["Authorization"]["account"] == "ANONYMOUS LOGON" and
                     msg["Authorization"]["authType"] == "no bind")
@@ -808,7 +809,7 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     msg["Authorization"]["account"] == "ANONYMOUS LOGON" and
                     msg["Authorization"]["transportProtection"] == "SMB")
 
-        server   = os.environ["SERVER"]
+        server = os.environ["SERVER"]
 
         path = "//%s/IPC$" % server
         auth = "-N"
@@ -861,7 +862,7 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     msg["Authorization"]["account"] == "ANONYMOUS LOGON" and
                     msg["Authorization"]["transportProtection"] == "SMB")
 
-        server   = os.environ["SERVER"]
+        server = os.environ["SERVER"]
 
         path = "//%s/IPC$" % server
         auth = "-N"
@@ -1124,8 +1125,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     (msg["Authentication"]["logonType"] ==
                         EVT_LOGON_INTERACTIVE))
 
-        server   = os.environ["SERVER"]
-        user     = os.environ["USERNAME"]
+        server = os.environ["SERVER"]
+        user = os.environ["USERNAME"]
         password = os.environ["PASSWORD"]
         samlogon = "samlogon %s %s %s %d" % (user, password, workstation, 1)
 
@@ -1157,8 +1158,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     (msg["Authentication"]["logonType"] ==
                         EVT_LOGON_INTERACTIVE))
 
-        server   = os.environ["SERVER"]
-        user     = os.environ["USERNAME"]
+        server = os.environ["SERVER"]
+        user = os.environ["USERNAME"]
         password = "badPassword"
         samlogon = "samlogon %s %s %s %d" % (user, password, workstation, 1)
 
@@ -1190,8 +1191,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     (msg["Authentication"]["logonType"] ==
                         EVT_LOGON_INTERACTIVE))
 
-        server   = os.environ["SERVER"]
-        user     = "badUser"
+        server = os.environ["SERVER"]
+        user = "badUser"
         password = os.environ["PASSWORD"]
         samlogon = "samlogon %s %s %s %d" % (user, password, workstation, 1)
 
@@ -1221,8 +1222,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     (msg["Authentication"]["logonType"] ==
                         EVT_LOGON_NETWORK))
 
-        server   = os.environ["SERVER"]
-        user     = os.environ["USERNAME"]
+        server = os.environ["SERVER"]
+        user = os.environ["USERNAME"]
         password = os.environ["PASSWORD"]
         samlogon = "samlogon %s %s %s %d" % (user, password, workstation, 2)
 
@@ -1253,8 +1254,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     (msg["Authentication"]["logonType"] ==
                         EVT_LOGON_NETWORK))
 
-        server   = os.environ["SERVER"]
-        user     = os.environ["USERNAME"]
+        server = os.environ["SERVER"]
+        user = os.environ["USERNAME"]
         password = "badPassword"
         samlogon = "samlogon %s %s %s %d" % (user, password, workstation, 2)
 
@@ -1285,8 +1286,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     (msg["Authentication"]["logonType"] ==
                         EVT_LOGON_NETWORK))
 
-        server   = os.environ["SERVER"]
-        user     = "badUser"
+        server = os.environ["SERVER"]
+        user = "badUser"
         password = os.environ["PASSWORD"]
         samlogon = "samlogon %s %s %s %d" % (user, password, workstation, 2)
 
@@ -1317,8 +1318,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     (msg["Authentication"]["logonType"] ==
                         EVT_LOGON_NETWORK))
 
-        server   = os.environ["SERVER"]
-        user     = os.environ["USERNAME"]
+        server = os.environ["SERVER"]
+        user = os.environ["USERNAME"]
         password = os.environ["PASSWORD"]
         samlogon = "samlogon %s %s %s %d 0x00010000" % (
             user, password, workstation, 2)
@@ -1351,8 +1352,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     (msg["Authentication"]["logonType"] ==
                         EVT_LOGON_NETWORK))
 
-        server   = os.environ["SERVER"]
-        user     = os.environ["USERNAME"]
+        server = os.environ["SERVER"]
+        user = os.environ["USERNAME"]
         password = "badPassword"
         samlogon = "samlogon %s %s %s %d 0x00010000" % (
             user, password, workstation, 2)
@@ -1385,8 +1386,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     (msg["Authentication"]["logonType"] ==
                         EVT_LOGON_NETWORK))
 
-        server   = os.environ["SERVER"]
-        user     = "badUser"
+        server = os.environ["SERVER"]
+        user = "badUser"
         password = os.environ["PASSWORD"]
         samlogon = "samlogon %s %s %s %d 0x00010000" % (
             user, password, workstation, 2)
@@ -1417,8 +1418,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     (msg["Authentication"]["logonType"] ==
                         EVT_LOGON_NETWORK))
 
-        server   = os.environ["SERVER"]
-        user     = os.environ["USERNAME"]
+        server = os.environ["SERVER"]
+        user = os.environ["USERNAME"]
         password = os.environ["PASSWORD"]
         samlogon = "schannel;samlogon %s %s %s" % (user, password, workstation)
 
@@ -1459,8 +1460,8 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase):
                     (msg["Authentication"]["logonType"] ==
                         EVT_LOGON_NETWORK))
 
-        server   = os.environ["SERVER"]
-        user     = os.environ["USERNAME"]
+        server = os.environ["SERVER"]
+        user = os.environ["USERNAME"]
         password = os.environ["PASSWORD"]
         samlogon = "schannelsign;samlogon %s %s %s" % (
             user, password, workstation)
index 374ee4586394342332c6b911eb4be6bc00d8e4db..38f5eb5175d3fc7e3a78b35020d1ce9a849a3d4a 100644 (file)
@@ -29,6 +29,7 @@ import re
 
 msg_ctxs = []
 
+
 class AuthLogTestBase(samba.tests.TestCase):
 
     def setUp(self):
index d5b8735bcdbd415ffed1ff52022b32103dd8fbf9..1281d28040ef1fd0403c450a97330ffe4fde2835 100644 (file)
@@ -44,8 +44,8 @@ class AuthLogTestsNcalrpc(samba.tests.auth_log_base.AuthLogTestBase):
         def isLastExpectedMessage(msg):
             return (
                 msg["type"] == "Authorization" and
-                msg["Authorization"]["serviceDescription"]  == "DCE/RPC" and
-                msg["Authorization"]["authType"]            == authTypes[0] and
+                msg["Authorization"]["serviceDescription"] == "DCE/RPC" and
+                msg["Authorization"]["authType"] == authTypes[0] and
                 msg["Authorization"]["transportProtection"] == protection)
 
         if binding:
index a52bd28191b0f8bbeba3a7597641fa89b2f15fc0..83ffd33c1a64142e2f04192e0f0241255df75a47 100644 (file)
@@ -46,8 +46,8 @@ class AuthLogTestsNetLogon(samba.tests.auth_log_base.AuthLogTestBase):
 
     def setUp(self):
         super(AuthLogTestsNetLogon, self).setUp()
-        self.lp      = samba.tests.env_loadparm()
-        self.creds   = Credentials()
+        self.lp = samba.tests.env_loadparm()
+        self.creds = Credentials()
 
         self.session = system_session()
         self.ldb = SamDB(
@@ -55,13 +55,12 @@ class AuthLogTestsNetLogon(samba.tests.auth_log_base.AuthLogTestBase):
             credentials=self.creds,
             lp=self.lp)
 
-        self.domain        = os.environ["DOMAIN"]
-        self.netbios_name  = "NetLogonGood"
-        self.machinepass   = "abcdefghij"
+        self.domain = os.environ["DOMAIN"]
+        self.netbios_name = "NetLogonGood"
+        self.machinepass = "abcdefghij"
         self.remoteAddress = AS_SYSTEM_MAGIC_PATH_TOKEN
-        self.base_dn       = self.ldb.domain_dn()
-        self.dn            = ("cn=%s,cn=users,%s" %
-                              (self.netbios_name, self.base_dn))
+        self.base_dn = self.ldb.domain_dn()
+        self.dn = ("cn=%s,cn=users,%s" % (self.netbios_name, self.base_dn))
 
         utf16pw = text_type('"' + self.machinepass + '"').encode('utf-16-le')
         self.ldb.add({
@@ -81,8 +80,8 @@ class AuthLogTestsNetLogon(samba.tests.auth_log_base.AuthLogTestBase):
         def isLastExpectedMessage(msg):
             return (
                 msg["type"] == "Authorization" and
-                msg["Authorization"]["serviceDescription"]  == "DCE/RPC" and
-                msg["Authorization"]["authType"]            == "schannel" and
+                msg["Authorization"]["serviceDescription"] == "DCE/RPC" and
+                msg["Authorization"]["authType"] == "schannel" and
                 msg["Authorization"]["transportProtection"] == "SEAL")
 
         if binding:
index 01cb8cd6af09de212e47955588332f893525faa7..3b699bb6505463ad2a729bb0448664a8990a8597 100644 (file)
@@ -48,8 +48,8 @@ class AuthLogTestsNetLogonBadCreds(samba.tests.auth_log_base.AuthLogTestBase):
 
     def setUp(self):
         super(AuthLogTestsNetLogonBadCreds, self).setUp()
-        self.lp      = samba.tests.env_loadparm()
-        self.creds   = Credentials()
+        self.lp = samba.tests.env_loadparm()
+        self.creds = Credentials()
 
         self.session = system_session()
         self.ldb = SamDB(
@@ -57,13 +57,12 @@ class AuthLogTestsNetLogonBadCreds(samba.tests.auth_log_base.AuthLogTestBase):
             credentials=self.creds,
             lp=self.lp)
 
-        self.domain        = os.environ["DOMAIN"]
-        self.netbios_name  = "NetLogonBad"
-        self.machinepass   = "abcdefghij"
+        self.domain = os.environ["DOMAIN"]
+        self.netbios_name = "NetLogonBad"
+        self.machinepass = "abcdefghij"
         self.remoteAddress = AS_SYSTEM_MAGIC_PATH_TOKEN
-        self.base_dn       = self.ldb.domain_dn()
-        self.dn            = ("cn=%s,cn=users,%s" %
-                              (self.netbios_name, self.base_dn))
+        self.base_dn = self.ldb.domain_dn()
+        self.dn = ("cn=%s,cn=users,%s" % (self.netbios_name, self.base_dn))
 
         utf16pw = get_string('"' + self.machinepass + '"').encode('utf-16-le')
         self.ldb.add({
@@ -147,8 +146,8 @@ class AuthLogTestsNetLogonBadCreds(samba.tests.auth_log_base.AuthLogTestBase):
                 msg["Authentication"]["authDescription"] ==
                 "ServerAuthenticate" and
                 msg["Authentication"]["passwordType"] == "DES" and
-                msg["Authentication"]["eventId"] ==
-                    EVT_ID_UNSUCCESSFUL_LOGON and
+                (msg["Authentication"]["eventId"] ==
+                    EVT_ID_UNSUCCESSFUL_LOGON) and
                 msg["Authentication"]["logonType"] == EVT_LOGON_NETWORK)
 
         c = netlogon.netlogon("ncalrpc:[schannel]", self.get_loadparm())
index 35f121e5bf095fe12ce6cd43277681787e6e53d6..eeb64df41eb86f11faaed099b00be189fecc2372 100644 (file)
@@ -46,8 +46,8 @@ class AuthLogTestsSamLogon(samba.tests.auth_log_base.AuthLogTestBase):
 
     def setUp(self):
         super(AuthLogTestsSamLogon, self).setUp()
-        self.lp      = samba.tests.env_loadparm()
-        self.creds   = Credentials()
+        self.lp = samba.tests.env_loadparm()
+        self.creds = Credentials()
 
         self.session = system_session()
         self.ldb = SamDB(
@@ -55,13 +55,13 @@ class AuthLogTestsSamLogon(samba.tests.auth_log_base.AuthLogTestBase):
             credentials=self.creds,
             lp=self.lp)
 
-        self.domain        = os.environ["DOMAIN"]
-        self.netbios_name  = "SamLogonTest"
-        self.machinepass   = "abcdefghij"
+        self.domain = os.environ["DOMAIN"]
+        self.netbios_name = "SamLogonTest"
+        self.machinepass = "abcdefghij"
         self.remoteAddress = AS_SYSTEM_MAGIC_PATH_TOKEN
-        self.base_dn       = self.ldb.domain_dn()
-        self.samlogon_dn   = ("cn=%s,cn=users,%s" %
-                              (self.netbios_name, self.base_dn))
+        self.base_dn = self.ldb.domain_dn()
+        self.samlogon_dn = ("cn=%s,cn=users,%s" %
+                           (self.netbios_name, self.base_dn))
 
     def tearDown(self):
         super(AuthLogTestsSamLogon, self).tearDown()
@@ -72,9 +72,9 @@ class AuthLogTestsSamLogon(samba.tests.auth_log_base.AuthLogTestBase):
         def isLastExpectedMessage(msg):
             return (
                 msg["type"] == "Authentication" and
-                msg["Authentication"]["serviceDescription"]  == "SamLogon" and
-                msg["Authentication"]["authDescription"]     == "network" and
-                msg["Authentication"]["passwordType"]        == "NTLMv2" and
+                msg["Authentication"]["serviceDescription"] == "SamLogon" and
+                msg["Authentication"]["authDescription"] == "network" and
+                msg["Authentication"]["passwordType"] == "NTLMv2" and
                 (msg["Authentication"]["eventId"] ==
                     EVT_ID_SUCCESSFUL_LOGON) and
                 (msg["Authentication"]["logonType"] == EVT_LOGON_NETWORK))
@@ -130,10 +130,14 @@ class AuthLogTestsSamLogon(samba.tests.auth_log_base.AuthLogTestBase):
         logon_level = netlogon.NetlogonNetworkTransitiveInformation
         logon = samba.dcerpc.netlogon.netr_NetworkInfo()
 
-        logon.challenge = [x if isinstance(x,int) else ord(x) for x in challenge]
+        logon.challenge = [
+            x if isinstance(x, int) else ord(x) for x in challenge]
         logon.nt = netlogon.netr_ChallengeResponse()
         logon.nt.length = len(response["nt_response"])
-        logon.nt.data = [x if isinstance(x,int) else ord(x) for x in response["nt_response"]]
+        logon.nt.data = [
+            x if isinstance(x, int) else ord(x) for
+            x in response["nt_response"]
+        ]
         logon.identity_info = samba.dcerpc.netlogon.netr_IdentityInfo()
         (username, domain) = creds.get_ntlm_username_domain()