Skip to content

Commit

Permalink
testing for ticket 305
Browse files Browse the repository at this point in the history
  • Loading branch information
richm committed Sep 14, 2012
1 parent fef44fa commit 9985dff
Showing 1 changed file with 43 additions and 120 deletions.
163 changes: 43 additions & 120 deletions ticket-305.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,65 +15,28 @@
'newrootpw': 'password',
'newhost': host1,
'newport': port1,
'newinst': 'm1',
'newinst': 'ds',
'newsuffix': basedn,
'no_admin': True
}

m1replargs = {
'suffix': basedn,
'bename': "userRoot",
'binddn': "cn=replrepl,cn=config",
'bindcn': "replrepl",
'bindpw': "replrepl"
}

#os.environ['USE_DBX'] = "1"
m1 = DSAdmin.createAndSetupReplica(createargs, m1replargs)
#del os.environ['USE_DBX']

createargs['newinst'] = "m2"
createargs['newhost'] = host2
createargs['newport'] = port2

m2replargs = m1replargs

#os.environ['USE_DBX'] = 1
m2 = DSAdmin.createAndSetupReplica(createargs, m2replargs)
#del os.environ['USE_DBX']
os.environ['USE_VALGRIND'] = "1"
ds = DSAdmin.createInstance(createargs)
del os.environ['USE_VALGRIND']

initfile = ''
if os.environ.has_key('SERVER_ROOT'):
initfile = "%s/slapd-%s/ldif/Example.ldif" % (m1.sroot,m1.inst)
initfile = "%s/slapd-%s/ldif/Example.ldif" % (ds.sroot,ds.inst)
else:
initfile = "%s/share/dirsrv/data/Example.ldif" % os.environ.get('PREFIX', '/usr')
m1.importLDIF(initfile, '', "userRoot", True)

print "create agreements and init consumers"
agmtm1tom2 = m1.setupAgreement(m2, m1replargs)
time.sleep(5)
m1.startReplication_async(agmtm1tom2)
print "waiting for init to finish"
time.sleep(5)
m1.waitForReplInit(agmtm1tom2)
agmtm2tom1 = m2.setupAgreement(m1, m2replargs)
ds.importLDIF(initfile, '', "userRoot", True)

userdn = "uid=scarter,ou=people," + basedn
print "do a mod to see if replication is working . . ."
mymod = [(ldap.MOD_REPLACE, "description", "changed")]
m1.modify_s(userdn, mymod)
time.sleep(5)
ent = m2.getEntry(userdn, ldap.SCOPE_BASE)
if ent.description == "changed":
print "replication is working"
else:
print "replication is not working"
sys.exit(1)
userpw = "sprain"

print "Allow local password policy"
p = {'nsslapd-pwpolicy-local':'on'}
m1.setPwdPolicy(p)
m2.setPwdPolicy(p)
ds.setPwdPolicy(p)
print "Set up password policy . . ."
nattempts = 5
pwdpolicy = {
Expand All @@ -91,80 +54,40 @@
'passwordMaxFailure': nattempts,
'passwordLockout': 'on'
}
m1.subtreePwdPolicy(basedn, pwdpolicy)
ds.subtreePwdPolicy(basedn, pwdpolicy)
pwdpolicy['passwordMaxFailure'] = nattempts-1
m1.subtreePwdPolicy("ou=people," + basedn, pwdpolicy)
ds.subtreePwdPolicy("ou=people," + basedn, pwdpolicy)
pwdpolicy['passwordMaxFailure'] = nattempts-2
m1.userPwdPolicy(userdn, pwdpolicy)

print "see what the pwpolicy settings are from m1 . . ."
ents = m1.search_s(userdn, ldap.SCOPE_BASE, '(objectclass=*)', ['*', 'pwdpolicysubentry'])
u1 = ents[0]
ents = m1.search_s("uid=alutz,ou=people," + basedn, ldap.SCOPE_BASE, '(objectclass=*)', ['*', 'pwdpolicysubentry'])
u2 = ents[0]

print u1.dn, "password policy is", u1.pwdpolicysubentry
print u2.dn, "password policy is", u2.pwdpolicysubentry

print "see what the pwpolicy settings are from m2 . . ."
ents = m2.search_s(userdn, ldap.SCOPE_BASE, '(objectclass=*)', ['*', 'pwdpolicysubentry'])
u1 = ents[0]
ents = m2.search_s("uid=alutz,ou=people," + basedn, ldap.SCOPE_BASE, '(objectclass=*)', ['*', 'pwdpolicysubentry'])
u2 = ents[0]

print u1.dn, "password policy is", u1.pwdpolicysubentry
print u2.dn, "password policy is", u2.pwdpolicysubentry

opattrs = [ 'passwordRetryCount', 'retryCountResetTime', 'accountUnlockTime', 'passwordExpirationTime', 'modifyTimestamp', 'modifiersName' ]
print "Do %d attempts to bind with incorrect password . . ." % nattempts
userconn = DSAdmin(host1, port1)
for xx in range(0, nattempts+1):
try:
userconn.simple_bind_s(userdn, "boguspassword")
except ldap.INVALID_CREDENTIALS: print "password was not correct"
except ldap.CONSTRAINT_VIOLATION: print "too many password attempts"
print "m1 pwd attrs"
print "%s" % m1.getEntry(userdn, ldap.SCOPE_BASE, "(objectclass=*)", opattrs)
print "m2 pwd attrs"
print "%s" % m2.getEntry(userdn, ldap.SCOPE_BASE, "(objectclass=*)", opattrs)
mymod = [(ldap.MOD_REPLACE, "description", "changed %d" % xx)]
m1.modify_s(userdn, mymod)
userconn.unbind()

print "sleep to let repl propagate . . ."
time.sleep(5)

print "do a mod to see if replication is still working . . ."
mymod = [(ldap.MOD_REPLACE, "description", "changed back")]
m1.modify_s(userdn, mymod)
time.sleep(5)
ent = m2.getEntry(userdn, ldap.SCOPE_BASE)
if ent.description == "changed back":
print "replication is still working"
else:
print "replication is not working any longer"
sys.exit(1)

nents = 1000
svrs = (m1, m2)
nsvrs = len(svrs)
print "Add %d entries alternately . . ." % nents
for ii in range(0,nents):
dn = "cn=%d, %s" % (ii, basedn)
ent = Entry(dn)
ent.setValues('objectclass', 'person')
ent.setValues('sn', 'testuser')
svr = svrs[ii % nsvrs]
svr.add_s(ent)
print "Added %s to %s" % (dn, svr)

print "see if all entries are on both servers . . ."
time.sleep(10)
for ii in range(0,nents):
dn = "cn=%d, %s" % (ii, basedn)
try:
ent = m1.getEntry(dn, ldap.SCOPE_BASE)
ent = m2.getEntry(dn, ldap.SCOPE_BASE)
except:
print "Could not read entry", dn
raise
ds.userPwdPolicy(userdn, pwdpolicy)

print "get pwpolicy settings"
ents = ds.search_s(basedn, ldap.SCOPE_SUBTREE, '(&(objectclass=ldapsubentry)(objectclass=passwordpolicy))')
poldns = [ent.dn for ent in ents]
print "policy entries: " + str(poldns)
otherdn = "uid=alutz,ou=people," + basedn

cmpattrs = ["pwdpolicysubentry", 'nsrole']
#cmpattrs = ["pwdpolicysubentry"]
cmpvals = poldns
#cmpvals = poldns[0:1]
dns = [userdn, otherdn, "ou=people," + basedn, basedn]
#dns = [userdn]

for iters in xrange(0,1):
msgids = []
for dn in dns:
for attr in cmpattrs:
for val in cmpvals:
print "send compare for %s %s %s" % (dn, attr, val)
msgid = ds.compare(dn, attr, val)
msgids.append((msgid,dn,attr,val))
for msgid,dn,attr,val in msgids:
print "read result for %s %s %s %d" % (dn, attr, val, msgid)
try:
rtype, rdata = ds.result(msgid)
except ldap.COMPARE_TRUE:
print "COMPARE TRUE for val [%s] for attr [%s] in DN [%s]" % (val, attr, dn)
except ldap.COMPARE_FALSE:
print "COMPARE FALSE for val [%s] for attr [%s] in DN [%s]" % (val, attr, dn)
except ldap.NO_SUCH_ATTRIBUTE:
print "NOT FOUND for val [%s] for attr [%s] in DN [%s]" % (val, attr, dn)

0 comments on commit 9985dff

Please sign in to comment.