Refactor for PEP8 warning E501 line too long
authorTim Beale <timbeale@catalyst.net.nz>
Fri, 27 Jul 2018 03:27:09 +0000 (15:27 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 17 Aug 2018 00:58:28 +0000 (02:58 +0200)
Add a wrapper function to avoid long lines. This also helps
a little to manage/contain the complexity of the code.

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Signed-off-by: Joe Guo <joeg@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
source4/dsdb/tests/python/password_settings.py

index 88d7c3d38c1fc18ac85aeffc3b050ff3810bcd6d..87c00f41419d5e06dbd40d376ad59261da90999a 100644 (file)
@@ -710,6 +710,11 @@ class PasswordSettingsTestCase(PasswordTestCase):
             self.set_attribute(priv_pso.dn, "msDS-PSOAppliesTo", user.dn,
                                samdb=self.ldb, operation=oper)
 
+    def format_password_for_ldif(self, password):
+        """Encodes/decodes the password so that it's accepted in an LDIF"""
+        pwd = '"{}"'.format(password)
+        return base64.b64encode(pwd.encode('utf-16-le')).decode('utf8')
+
     # The 'user add' case is a bit more complicated as you can't really query
     # the msDS-ResultantPSO attribute on a user that doesn't exist yet (it
     # won't have any group membership or PSOs applied directly against it yet).
@@ -735,7 +740,7 @@ class PasswordSettingsTestCase(PasswordTestCase):
         # defaults, to prove that the DC will reject bad passwords during a
         # user add
         userdn = "CN=testuser,%s" % self.ou
-        password = base64.b64encode('"abcdef"'.encode('utf-16-le')).decode('utf8')
+        password = self.format_password_for_ldif('abcdef')
 
         # Note we use an LDIF operation to ensure that the password gets set
         # as part of the 'add' operation (whereas self.add_user() adds the user
@@ -759,7 +764,7 @@ unicodePwd:: %s
         # now use a password that meets the domain defaults, but doesn't meet
         # the PSO requirements. Note that Windows allows this, i.e. it doesn't
         # honour the PSO during the add operation
-        password = base64.b64encode('"abcde12#"'.encode('utf-16-le')).decode('utf8')
+        password = self.format_password_for_ldif('abcde12#')
         ldif = """
 dn: %s
 objectClass: user
@@ -795,7 +800,7 @@ unicodePwd:: %s
                 self.assertTrue('0000052D' in msg, msg)
 
         # check setting a password that meets the PSO settings works
-        password = base64.b64encode('"abcdefghijkl"'.encode('utf-16-le')).decode('utf8')
+        password = self.format_password_for_ldif('abcdefghijkl')
         ldif = """
 dn: %s
 changetype: modify