mirror of
https://github.com/samba-team/samba.git
synced 2025-07-27 07:42:04 +03:00
Fix PEP8 warning E501 line too long
Mostly involves splitting up long strings or comments so that they span multiple lines. Some place-holder variables have been added in a few places to avoid exceeding 80 chars. Signed-off-by: Tim Beale <timbeale@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
This commit is contained in:
committed by
Andrew Bartlett
parent
7065f5299f
commit
68f8a1c274
@ -26,7 +26,8 @@
|
||||
# Usage:
|
||||
# export SERVER_IP=target_dc
|
||||
# export SUBUNITRUN=$samba4srcdir/scripting/bin/subunitrun
|
||||
# PYTHONPATH="$PYTHONPATH:$samba4srcdir/dsdb/tests/python" $SUBUNITRUN password_settings -U"$DOMAIN/$DC_USERNAME"%"$DC_PASSWORD"
|
||||
# PYTHONPATH="$PYTHONPATH:$samba4srcdir/dsdb/tests/python" $SUBUNITRUN \
|
||||
# password_settings -U"$DOMAIN/$DC_USERNAME"%"$DC_PASSWORD"
|
||||
#
|
||||
|
||||
import samba.tests
|
||||
@ -37,6 +38,7 @@ import time
|
||||
from samba.tests.password_test import PasswordTestCase
|
||||
from samba.tests.pso import TestUser
|
||||
from samba.tests.pso import PasswordSettings
|
||||
from samba.tests import env_get_var_value
|
||||
from samba.credentials import Credentials
|
||||
from samba import gensec
|
||||
import base64
|
||||
@ -46,7 +48,7 @@ class PasswordSettingsTestCase(PasswordTestCase):
|
||||
def setUp(self):
|
||||
super(PasswordSettingsTestCase, self).setUp()
|
||||
|
||||
self.host_url = "ldap://%s" % samba.tests.env_get_var_value("SERVER_IP")
|
||||
self.host_url = "ldap://%s" % env_get_var_value("SERVER_IP")
|
||||
self.ldb = samba.tests.connect_samdb(self.host_url)
|
||||
|
||||
# create a temp OU to put this test's users into
|
||||
@ -65,7 +67,7 @@ class PasswordSettingsTestCase(PasswordTestCase):
|
||||
# remove all objects under the top-level OU
|
||||
self.ldb.delete(self.ou, ["tree_delete:1"])
|
||||
|
||||
# PSOs can't reside within an OU so they need to be cleaned up separately
|
||||
# PSOs can't reside within an OU so they get cleaned up separately
|
||||
for obj in self.test_objs:
|
||||
self.ldb.delete(obj)
|
||||
|
||||
@ -79,7 +81,8 @@ class PasswordSettingsTestCase(PasswordTestCase):
|
||||
self.ldb.add({"dn": dn, "objectclass": "group"})
|
||||
return dn
|
||||
|
||||
def set_attribute(self, dn, attr, value, operation=FLAG_MOD_ADD, samdb=None):
|
||||
def set_attribute(self, dn, attr, value, operation=FLAG_MOD_ADD,
|
||||
samdb=None):
|
||||
"""Modifies an attribute for an object"""
|
||||
if samdb is None:
|
||||
samdb = self.ldb
|
||||
@ -114,7 +117,8 @@ class PasswordSettingsTestCase(PasswordTestCase):
|
||||
except ldb.LdbError as e:
|
||||
(num, msg) = e.args
|
||||
# fail the test (rather than throw an error)
|
||||
self.fail("Password '%s' unexpectedly rejected: %s" % (password, msg))
|
||||
self.fail("Password '%s' unexpectedly rejected: %s" % (password,
|
||||
msg))
|
||||
|
||||
def assert_PSO_applied(self, user, pso):
|
||||
"""
|
||||
@ -191,7 +195,7 @@ class PasswordSettingsTestCase(PasswordTestCase):
|
||||
self.assert_password_valid(user, password)
|
||||
|
||||
def test_pso_basics(self):
|
||||
"""Simple tests that a PSO takes effect when applied to a group or user"""
|
||||
"""Simple tests that a PSO takes effect when applied to a group/user"""
|
||||
|
||||
# create some PSOs that vary in priority and basic password-len
|
||||
best_pso = PasswordSettings("highest-priority-PSO", self.ldb,
|
||||
@ -237,7 +241,8 @@ class PasswordSettingsTestCase(PasswordTestCase):
|
||||
self.assert_PSO_applied(user, best_pso)
|
||||
|
||||
# delete a group membership and check the PSO changes
|
||||
self.set_attribute(group3, "member", user.dn, operation=FLAG_MOD_DELETE)
|
||||
self.set_attribute(group3, "member", user.dn,
|
||||
operation=FLAG_MOD_DELETE)
|
||||
self.assert_PSO_applied(user, medium_pso)
|
||||
|
||||
# apply the low-precedence PSO directly to the user
|
||||
@ -311,7 +316,8 @@ class PasswordSettingsTestCase(PasswordTestCase):
|
||||
self.assert_PSO_applied(user, group2_pso)
|
||||
|
||||
def get_guid(self, dn):
|
||||
res = self.ldb.search(base=dn, attrs=["objectGUID"], scope=ldb.SCOPE_BASE)
|
||||
res = self.ldb.search(base=dn, attrs=["objectGUID"],
|
||||
scope=ldb.SCOPE_BASE)
|
||||
return res[0]['objectGUID'][0]
|
||||
|
||||
def guid_string(self, guid):
|
||||
@ -333,7 +339,8 @@ class PasswordSettingsTestCase(PasswordTestCase):
|
||||
best_guid = guid_list[0]
|
||||
|
||||
# sanity-check the mapping between GUID and DN is correct
|
||||
self.assertEqual(self.guid_string(self.get_guid(mapping[best_guid].dn)),
|
||||
best_pso_dn = mapping[best_guid].dn
|
||||
self.assertEqual(self.guid_string(self.get_guid(best_pso_dn)),
|
||||
self.guid_string(best_guid))
|
||||
|
||||
# return the PSO that this GUID corresponds to
|
||||
@ -457,7 +464,8 @@ class PasswordSettingsTestCase(PasswordTestCase):
|
||||
pso.apply_to(user.dn)
|
||||
self.assertTrue(user.get_resultant_PSO() == pso.dn)
|
||||
|
||||
# changing the password immediately should fail, even if password is valid
|
||||
# changing the password immediately should fail, even if the password
|
||||
# is valid
|
||||
valid_password = "min-age-passwd"
|
||||
self.assert_password_invalid(user, valid_password)
|
||||
# then trying the same password later should succeed
|
||||
@ -481,8 +489,9 @@ class PasswordSettingsTestCase(PasswordTestCase):
|
||||
|
||||
user = self.add_user("testuser")
|
||||
|
||||
# we can't wait around long enough for the max-age to expire, so instead
|
||||
# just check the msDS-UserPasswordExpiryTimeComputed for the user
|
||||
# we can't wait around long enough for the max-age to expire, so
|
||||
# instead just check the msDS-UserPasswordExpiryTimeComputed for
|
||||
# the user
|
||||
attrs = ['msDS-UserPasswordExpiryTimeComputed']
|
||||
res = self.ldb.search(user.dn, attrs=attrs)
|
||||
domain_expiry = int(res[0]['msDS-UserPasswordExpiryTimeComputed'][0])
|
||||
@ -519,9 +528,10 @@ class PasswordSettingsTestCase(PasswordTestCase):
|
||||
precedence=2, password_len=10)
|
||||
self.add_obj_cleanup([default_pso.dn, guest_pso.dn, admin_pso.dn,
|
||||
builtin_pso.dn])
|
||||
domain_users = "CN=Domain Users,CN=Users,%s" % self.ldb.domain_dn()
|
||||
domain_guests = "CN=Domain Guests,CN=Users,%s" % self.ldb.domain_dn()
|
||||
admin_users = "CN=Domain Admins,CN=Users,%s" % self.ldb.domain_dn()
|
||||
base_dn = self.ldb.domain_dn()
|
||||
domain_users = "CN=Domain Users,CN=Users,%s" % base_dn
|
||||
domain_guests = "CN=Domain Guests,CN=Users,%s" % base_dn
|
||||
admin_users = "CN=Domain Admins,CN=Users,%s" % base_dn
|
||||
|
||||
# if we apply a PSO to Domain Users (which all users are a member of)
|
||||
# then that PSO should take effect on a new user
|
||||
@ -532,8 +542,8 @@ class PasswordSettingsTestCase(PasswordTestCase):
|
||||
# Apply a PSO to a builtin group. 'Domain Users' should be a member of
|
||||
# Builtin/Users, but builtin groups should be excluded from the PSO
|
||||
# calculation, so this should have no effect
|
||||
builtin_pso.apply_to("CN=Users,CN=Builtin,%s" % self.ldb.domain_dn())
|
||||
builtin_pso.apply_to("CN=Administrators,CN=Builtin,%s" % self.ldb.domain_dn())
|
||||
builtin_pso.apply_to("CN=Users,CN=Builtin,%s" % base_dn)
|
||||
builtin_pso.apply_to("CN=Administrators,CN=Builtin,%s" % base_dn)
|
||||
self.assert_PSO_applied(user, default_pso)
|
||||
|
||||
# change the user's primary group to another group (the primaryGroupID
|
||||
@ -798,7 +808,9 @@ unicodePwd:: %s
|
||||
def set_domain_pwdHistoryLength(self, value):
|
||||
m = ldb.Message()
|
||||
m.dn = ldb.Dn(self.ldb, self.ldb.domain_dn())
|
||||
m["pwdHistoryLength"] = ldb.MessageElement(value, ldb.FLAG_MOD_REPLACE, "pwdHistoryLength")
|
||||
m["pwdHistoryLength"] = ldb.MessageElement(value,
|
||||
ldb.FLAG_MOD_REPLACE,
|
||||
"pwdHistoryLength")
|
||||
self.ldb.modify(m)
|
||||
|
||||
def test_domain_pwd_history(self):
|
||||
@ -852,8 +864,3 @@ unicodePwd:: %s
|
||||
# *next* time the user's password changes.
|
||||
self.set_domain_pwdHistoryLength("1")
|
||||
self.assert_password_invalid(user, "NewPwd12#")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user