From 07b367ea6240b3be4752a44548c4cee39b7803c1 Mon Sep 17 00:00:00 2001 From: Akshay Adhikari Date: Dec 17 2018 07:45:12 +0000 Subject: Issue 49588 - Add py3 support for tickets : part-5 Description: Added py3 support by explicitly changing strings to bytes. Fixed old legacy objects. https://pagure.io/389-ds-base/issue/49588 Reviewed by: mreynolds (Thanks!) --- diff --git a/dirsrvtests/tests/tickets/ticket48252_test.py b/dirsrvtests/tests/tickets/ticket48252_test.py index b54c899..0d2962d 100644 --- a/dirsrvtests/tests/tickets/ticket48252_test.py +++ b/dirsrvtests/tests/tickets/ticket48252_test.py @@ -10,6 +10,7 @@ import logging import pytest from lib389.tasks import * +from lib389.utils import * from lib389.topologies import topology_st from lib389.idm.user import UserAccounts @@ -52,8 +53,7 @@ def in_index_file(topology_st, id, index): key = "%s%s" % (TEST_USER, id) log.info(" dbscan - checking %s is in index file %s..." % (key, index)) dbscanOut = topology_st.standalone.dbscan(DEFAULT_BENAME, index) - - if key in dbscanOut: + if ensure_bytes(key) in ensure_bytes(dbscanOut): found = True topology_st.standalone.log.info("Found key %s in dbscan output" % key) else: @@ -76,10 +76,10 @@ def test_ticket48252_run_0(topology_st): del_entry.delete() assert in_index_file(topology_st, 0, 'cn') is False - log.info(" db2index - reindexing %s ..." % 'cn') - assert topology_st.standalone.db2index(DEFAULT_BENAME, 'cn') - + topology_st.standalone.stop() + assert topology_st.standalone.db2index(bename=None, suffixes='cn') + topology_st.standalone.start() assert in_index_file(topology_st, 0, 'cn') is False log.info(" entry %s is not in the cn index file after reindexed." % del_rdn) log.info('Case 1 - PASSED') @@ -102,8 +102,9 @@ def test_ticket48252_run_1(topology_st): log.info(" entry %s is in the objectclass index file." % del_rdn) log.info(" db2index - reindexing %s ..." % 'objectclass') - assert topology_st.standalone.db2index(DEFAULT_BENAME, 'objectclass') - + topology_st.standalone.stop() + assert topology_st.standalone.db2index(bename=None, suffixes='objectclass') + topology_st.standalone.start() entry = topology_st.standalone.search_s(SUFFIX, ldap.SCOPE_SUBTREE, '(&(objectclass=nstombstone)(%s))' % del_rdn) assert len(entry) == 1 log.info(" entry %s is in the objectclass index file after reindexed." % del_rdn) diff --git a/dirsrvtests/tests/tickets/ticket48266_test.py b/dirsrvtests/tests/tickets/ticket48266_test.py index c64ba99..47fef09 100644 --- a/dirsrvtests/tests/tickets/ticket48266_test.py +++ b/dirsrvtests/tests/tickets/ticket48266_test.py @@ -2,6 +2,7 @@ import pytest from lib389.tasks import * from lib389.utils import * from lib389.topologies import topology_m2 +from lib389.replica import ReplicationManager from lib389._constants import SUFFIX, DEFAULT_SUFFIX, HOST_MASTER_2, PORT_MASTER_2 @@ -36,8 +37,8 @@ def test_ticket48266_fractional(topology_m2, entries): ents = topology_m2.ms["master1"].agreement.list(suffix=SUFFIX) assert len(ents) == 1 - mod = [(ldap.MOD_REPLACE, 'nsDS5ReplicatedAttributeList', ['(objectclass=*) $ EXCLUDE telephonenumber']), - (ldap.MOD_REPLACE, 'nsds5ReplicaStripAttrs', ['modifiersname modifytimestamp'])] + mod = [(ldap.MOD_REPLACE, 'nsDS5ReplicatedAttributeList', [b'(objectclass=*) $ EXCLUDE telephonenumber']), + (ldap.MOD_REPLACE, 'nsds5ReplicaStripAttrs', [b'modifiersname modifytimestamp'])] ents = topology_m2.ms["master1"].agreement.list(suffix=SUFFIX) assert len(ents) == 1 m1_m2_agmt = ents[0].dn @@ -50,20 +51,21 @@ def test_ticket48266_fractional(topology_m2, entries): topology_m2.ms["master1"].restart() topology_m2.ms["master2"].restart() - topology_m2.ms["master1"].agreement.init(SUFFIX, HOST_MASTER_2, PORT_MASTER_2) - topology_m2.ms["master1"].waitForReplInit(m1_m2_agmt) + repl = ReplicationManager(DEFAULT_SUFFIX) + repl.ensure_agreement(topology_m2.ms["master1"], topology_m2.ms["master2"]) + repl.test_replication(topology_m2.ms["master1"], topology_m2.ms["master2"]) def test_ticket48266_check_repl_desc(topology_m2, entries): name = "cn=%s1,%s" % (NEW_ACCOUNT, SUFFIX) value = 'check repl. description' - mod = [(ldap.MOD_REPLACE, 'description', value)] + mod = [(ldap.MOD_REPLACE, 'description', ensure_bytes(value))] topology_m2.ms["master1"].modify_s(name, mod) loop = 0 while loop <= 10: ent = topology_m2.ms["master2"].getEntry(name, ldap.SCOPE_BASE, "(objectclass=*)") - if ent.hasAttr('description') and ent.getValue('description') == value: + if ent.hasAttr('description') and ent.getValue('description') == ensure_bytes(value): break time.sleep(1) loop += 1 @@ -77,7 +79,7 @@ def _get_last_not_replicated_csn(topology_m2): name = "cn=%s5,%s" % (NEW_ACCOUNT, SUFFIX) # read the first CSN that will not be replicated - mod = [(ldap.MOD_REPLACE, 'telephonenumber', str(123456))] + mod = [(ldap.MOD_REPLACE, 'telephonenumber', ensure_bytes('123456'))] topology_m2.ms["master1"].modify_s(name, mod) msgid = topology_m2.ms["master1"].search_ext(name, ldap.SCOPE_SUBTREE, 'objectclass=*', ['nscpentrywsi']) rtype, rdata, rmsgid = topology_m2.ms["master1"].result2(msgid) @@ -88,7 +90,7 @@ def _get_last_not_replicated_csn(topology_m2): attrs = raw_attrs['nscpentrywsi'] assert attrs for attr in attrs: - if attr.lower().startswith('telephonenumber'): + if ensure_str(attr.lower()).startswith('telephonenumber'): break assert attr @@ -112,7 +114,7 @@ def _get_first_not_replicated_csn(topology_m2): name = "cn=%s2,%s" % (NEW_ACCOUNT, SUFFIX) # read the first CSN that will not be replicated - mod = [(ldap.MOD_REPLACE, 'telephonenumber', str(123456))] + mod = [(ldap.MOD_REPLACE, 'telephonenumber', ensure_bytes('123456'))] topology_m2.ms["master1"].modify_s(name, mod) msgid = topology_m2.ms["master1"].search_ext(name, ldap.SCOPE_SUBTREE, 'objectclass=*', ['nscpentrywsi']) rtype, rdata, rmsgid = topology_m2.ms["master1"].result2(msgid) @@ -123,7 +125,7 @@ def _get_first_not_replicated_csn(topology_m2): attrs = raw_attrs['nscpentrywsi'] assert attrs for attr in attrs: - if attr.lower().startswith('telephonenumber'): + if ensure_str(attr.lower()).startswith('telephonenumber'): break assert attr @@ -177,7 +179,7 @@ def test_ticket48266_count_csn_evaluation(topology_m2, entries): topology_m2.ms["master1"].agreement.pause(ents[0].dn) # now do a set of updates that will NOT be replicated for telNumber in range(NB_SESSION): - mod = [(ldap.MOD_REPLACE, 'telephonenumber', str(telNumber))] + mod = [(ldap.MOD_REPLACE, 'telephonenumber', ensure_bytes(str(telNumber)))] topology_m2.ms["master1"].modify_s(name, mod) topology_m2.ms["master1"].agreement.resume(ents[0].dn) diff --git a/dirsrvtests/tests/tickets/ticket48325_test.py b/dirsrvtests/tests/tickets/ticket48325_test.py index d02e9e6..fe70e2e 100644 --- a/dirsrvtests/tests/tickets/ticket48325_test.py +++ b/dirsrvtests/tests/tickets/ticket48325_test.py @@ -1,11 +1,13 @@ import pytest from lib389.utils import * +from lib389.tasks import * from lib389.topologies import topology_m1h1c1 +from lib389.replica import ReplicationManager from lib389._constants import (DEFAULT_SUFFIX, REPLICA_RUV_FILTER, defaultProperties, - REPLICATION_BIND_DN, REPLICATION_BIND_PW, REPLICATION_BIND_METHOD, - REPLICATION_TRANSPORT, SUFFIX, RA_NAME, RA_BINDDN, RA_BINDPW, - RA_METHOD, RA_TRANSPORT_PROT, SUFFIX) + REPLICATION_BIND_DN, REPLICATION_BIND_PW, REPLICATION_BIND_METHOD, + REPLICATION_TRANSPORT, RA_NAME, RA_BINDDN, RA_BINDPW, + RA_METHOD, RA_TRANSPORT_PROT, SUFFIX) logging.getLogger(__name__).setLevel(logging.DEBUG) log = logging.getLogger(__name__) @@ -27,7 +29,7 @@ def checkFirstElement(ds, rid): assert False ruv_elements = entry.getValues('nsds50ruv') - if ('replica %s ' % rid) in ruv_elements[1]: + if ('replica %s ' % rid) in ensure_str(ruv_elements[1]): return True else: return False @@ -42,21 +44,21 @@ def test_ticket48325(topology_m1h1c1): # # Promote consumer to master # - try: - topology_m1h1c1.cs["consumer1"].changelog.create() - DN = topology_m1h1c1.cs["consumer1"].replica._get_mt_entry(DEFAULT_SUFFIX) - topology_m1h1c1.cs["consumer1"].modify_s(DN, [(ldap.MOD_REPLACE, - 'nsDS5ReplicaType', - '3'), - (ldap.MOD_REPLACE, - 'nsDS5ReplicaID', - '1234'), - (ldap.MOD_REPLACE, - 'nsDS5Flags', - '1')]) - except ldap.LDAPError as e: - log.fatal('Failed to promote consuemr to master: error %s' % str(e)) - assert False + C1 = topology_m1h1c1.cs["consumer1"] + M1 = topology_m1h1c1.ms["master1"] + H1 = topology_m1h1c1.hs["hub1"] + repl = ReplicationManager(DEFAULT_SUFFIX) + repl._ensure_changelog(C1) + DN = topology_m1h1c1.cs["consumer1"].replica._get_mt_entry(DEFAULT_SUFFIX) + topology_m1h1c1.cs["consumer1"].modify_s(DN, [(ldap.MOD_REPLACE, + 'nsDS5ReplicaType', + b'3'), + (ldap.MOD_REPLACE, + 'nsDS5ReplicaID', + b'1234'), + (ldap.MOD_REPLACE, + 'nsDS5Flags', + b'1')]) time.sleep(1) # @@ -66,9 +68,17 @@ def test_ticket48325(topology_m1h1c1): log.fatal('RUV was not reordered') assert False + topology_m1h1c1.ms["master1"].add_s(Entry((defaultProperties[REPLICATION_BIND_DN], + {'objectclass': 'top netscapeServer'.split(), + 'cn': 'replication manager', + 'userPassword': 'password'}))) + + DN = topology_m1h1c1.ms["master1"].replica._get_mt_entry(DEFAULT_SUFFIX) + topology_m1h1c1.ms["master1"].modify_s(DN, [(ldap.MOD_REPLACE, + 'nsDS5ReplicaBindDN', ensure_bytes(defaultProperties[REPLICATION_BIND_DN]))]) # # Create repl agreement from the newly promoted master to master1 - # + properties = {RA_NAME: 'meTo_{}:{}'.format(topology_m1h1c1.ms["master1"].host, str(topology_m1h1c1.ms["master1"].port)), RA_BINDDN: defaultProperties[REPLICATION_BIND_DN], @@ -84,29 +94,19 @@ def test_ticket48325(topology_m1h1c1): log.fatal("Fail to create new agmt from old consumer to the master") assert False - # # Test replication is working - # - if topology_m1h1c1.cs["consumer1"].testReplication(DEFAULT_SUFFIX, topology_m1h1c1.ms["master1"]): - log.info('Replication is working.') - else: - log.fatal('Replication is not working.') - assert False + repl.test_replication(C1, M1) # # Promote hub to master # - try: - DN = topology_m1h1c1.hs["hub1"].replica._get_mt_entry(DEFAULT_SUFFIX) - topology_m1h1c1.hs["hub1"].modify_s(DN, [(ldap.MOD_REPLACE, - 'nsDS5ReplicaType', - '3'), - (ldap.MOD_REPLACE, - 'nsDS5ReplicaID', - '5678')]) - except ldap.LDAPError as e: - log.fatal('Failed to promote consuemr to master: error %s' % str(e)) - assert False + DN = topology_m1h1c1.hs["hub1"].replica._get_mt_entry(DEFAULT_SUFFIX) + topology_m1h1c1.hs["hub1"].modify_s(DN, [(ldap.MOD_REPLACE, + 'nsDS5ReplicaType', + b'3'), + (ldap.MOD_REPLACE, + 'nsDS5ReplicaID', + b'5678')]) time.sleep(1) # @@ -116,14 +116,8 @@ def test_ticket48325(topology_m1h1c1): log.fatal('RUV was not reordered') assert False - # # Test replication is working - # - if topology_m1h1c1.hs["hub1"].testReplication(DEFAULT_SUFFIX, topology_m1h1c1.ms["master1"]): - log.info('Replication is working.') - else: - log.fatal('Replication is not working.') - assert False + repl.test_replication(M1, H1) # Done log.info('Test complete') diff --git a/dirsrvtests/tests/tickets/ticket48759_test.py b/dirsrvtests/tests/tickets/ticket48759_test.py index ebc2757..0989c87 100644 --- a/dirsrvtests/tests/tickets/ticket48759_test.py +++ b/dirsrvtests/tests/tickets/ticket48759_test.py @@ -10,10 +10,12 @@ import logging import pytest from lib389.tasks import * +from lib389.utils import * from lib389.topologies import topology_st +from lib389.replica import ReplicationManager,Replicas from lib389._constants import (PLUGIN_MEMBER_OF, DEFAULT_SUFFIX, ReplicaRole, REPLICAID_MASTER_1, - DN_CONFIG, PLUGIN_RETRO_CHANGELOG, REPLICA_PRECISE_PURGING, REPLICA_PURGE_DELAY, + PLUGIN_RETRO_CHANGELOG, REPLICA_PRECISE_PURGING, REPLICA_PURGE_DELAY, REPLICA_PURGE_INTERVAL) log = logging.getLogger(__name__) @@ -30,7 +32,7 @@ def _add_group_with_members(topology_st): {'objectclass': 'top groupofnames'.split(), 'cn': 'group'}))) except ldap.LDAPError as e: - log.fatal('Failed to add group: error ' + e.message['desc']) + log.fatal('Failed to add group: error ' + e.args[0]['desc']) assert False # Add members to the group - set timeout @@ -41,10 +43,10 @@ def _add_group_with_members(topology_st): topology_st.standalone.modify_s(GROUP_DN, [(ldap.MOD_ADD, 'member', - MEMBER_VAL)]) + ensure_bytes(MEMBER_VAL))]) except ldap.LDAPError as e: log.fatal('Failed to update group: member (%s) - error: %s' % - (MEMBER_VAL, e.message['desc'])) + (MEMBER_VAL, e.args[0]['desc'])) assert False @@ -60,7 +62,7 @@ def _find_memberof(topology_st, user_dn=None, group_dn=None, find_result=True): for val in ent.getValues('memberof'): topology_st.standalone.log.info("!!!!!!! %s: memberof->%s" % (user_dn, val)) - if val == group_dn: + if ensure_str(val) == group_dn: found = True break @@ -105,20 +107,16 @@ def test_ticket48759(topology_st): # Setup Replication # log.info('Setting up replication...') - topology_st.standalone.replica.enableReplication(suffix=DEFAULT_SUFFIX, role=ReplicaRole.MASTER, - replicaId=REPLICAID_MASTER_1) - + repl = ReplicationManager(DEFAULT_SUFFIX) + repl.create_first_master(topology_st.standalone) # # enable dynamic plugins, memberof and retro cl plugin # log.info('Enable plugins...') try: - topology_st.standalone.modify_s(DN_CONFIG, - [(ldap.MOD_REPLACE, - 'nsslapd-dynamic-plugins', - 'on')]) + topology_st.standalone.config.set('nsslapd-dynamic-plugins', 'on') except ldap.LDAPError as e: - ldap.error('Failed to enable dynamic plugins! ' + e.message['desc']) + ldap.error('Failed to enable dynamic plugins! ' + e.args[0]['desc']) assert False topology_st.standalone.plugins.enable(name=PLUGIN_MEMBER_OF) @@ -128,9 +126,9 @@ def test_ticket48759(topology_st): topology_st.standalone.modify_s(MEMBEROF_PLUGIN_DN, [(ldap.MOD_REPLACE, 'memberofgroupattr', - 'member')]) + b'member')]) except ldap.LDAPError as e: - log.fatal('Failed to configure memberOf plugin: error ' + e.message['desc']) + log.fatal('Failed to configure memberOf plugin: error ' + e.args[0]['desc']) assert False # @@ -144,7 +142,7 @@ def test_ticket48759(topology_st): {'objectclass': 'top extensibleObject'.split(), 'uid': 'member%d' % (idx)}))) except ldap.LDAPError as e: - log.fatal('Failed to add user (%s): error %s' % (USER_DN, e.message['desc'])) + log.fatal('Failed to add user (%s): error %s' % (USER_DN, e.args[0]['desc'])) assert False _add_group_with_members(topology_st) @@ -158,7 +156,7 @@ def test_ticket48759(topology_st): try: topology_st.standalone.delete_s(GROUP_DN) except ldap.LDAPError as e: - log.error('Failed to delete entry: ' + e.message['desc']) + log.error('Failed to delete entry: ' + e.args[0]['desc']) assert False time.sleep(1) @@ -177,10 +175,14 @@ def test_ticket48759(topology_st): # configure tombstone purging args = {REPLICA_PRECISE_PURGING: 'on', - REPLICA_PURGE_DELAY: '5', - REPLICA_PURGE_INTERVAL: '5'} + REPLICA_PURGE_DELAY: '5', + REPLICA_PURGE_INTERVAL: '5'} try: - topology_st.standalone.replica.setProperties(DEFAULT_SUFFIX, None, None, args) + Repl_DN = 'cn=replica,cn=dc\\3Dexample\\2Cdc\\3Dcom,cn=mapping tree,cn=config' + topology_st.standalone.modify_s(Repl_DN, + [(ldap.MOD_ADD, 'nsDS5ReplicaPreciseTombstonePurging', b'on'), + (ldap.MOD_ADD, 'nsDS5ReplicaPurgeDelay', b'5'), + (ldap.MOD_ADD, 'nsDS5ReplicaTombstonePurgeInterval', b'5')]) except: log.fatal('Failed to configure replica') assert False @@ -197,7 +199,7 @@ def test_ticket48759(topology_st): 'sn': 'user', 'cn': 'entry1'}))) except ldap.LDAPError as e: - log.error('Failed to add entry: ' + e.message['desc']) + log.error('Failed to add entry: ' + e.args[0]['desc']) assert False # check memberof is still correct diff --git a/dirsrvtests/tests/tickets/ticket48906_test.py b/dirsrvtests/tests/tickets/ticket48906_test.py index c02e231..3e10b20 100644 --- a/dirsrvtests/tests/tickets/ticket48906_test.py +++ b/dirsrvtests/tests/tickets/ticket48906_test.py @@ -67,7 +67,7 @@ def test_ticket48906_setup(topology_st): assert entry[0] assert entry[0].hasAttr('nsslapd-workingdir') path = entry[0].getValue('nsslapd-workingdir') - cores = fnmatch.filter(os.listdir(path), 'core.*') + cores = fnmatch.filter(os.listdir(path), b'core.*') assert len(cores) == 0 # add dummy entries on backend @@ -95,12 +95,12 @@ def _check_configured_value(topology_st, attr=DBLOCK_ATTR_CONFIG, expected_value if required: assert (entries[0].hasValue(attr)) elif entries[0].hasValue(attr): - assert (entries[0].getValue(attr) == expected_value) + assert (entries[0].getValue(attr) == ensure_bytes(expected_value)) def _check_monitored_value(topology_st, expected_value): entries = topology_st.standalone.search_s(ldbm_monitor, ldap.SCOPE_BASE, '(objectclass=*)') - assert (entries[0].hasValue(DBLOCK_ATTR_MONITOR) and entries[0].getValue(DBLOCK_ATTR_MONITOR) == expected_value) + assert (entries[0].hasValue(DBLOCK_ATTR_MONITOR) and entries[0].getValue(DBLOCK_ATTR_MONITOR) == ensure_bytes(expected_value)) def _check_dse_ldif_value(topology_st, attr=DBLOCK_ATTR_CONFIG, expected_value=DBLOCK_LDAP_UPDATE): @@ -170,7 +170,7 @@ def test_ticket48906_dblock_ldap_update(topology_st): topology_st.standalone.log.info('###') topology_st.standalone.log.info('###################################') - topology_st.standalone.modify_s(ldbm_config, [(ldap.MOD_REPLACE, DBLOCK_ATTR_CONFIG, DBLOCK_LDAP_UPDATE)]) + topology_st.standalone.modify_s(ldbm_config, [(ldap.MOD_REPLACE, DBLOCK_ATTR_CONFIG, ensure_bytes(DBLOCK_LDAP_UPDATE))]) _check_monitored_value(topology_st, DBLOCK_DEFAULT) _check_configured_value(topology_st, attr=DBLOCK_ATTR_CONFIG, expected_value=DBLOCK_LDAP_UPDATE, required=True) @@ -256,7 +256,7 @@ def test_ticket48906_dblock_robust(topology_st): # Check negative value try: - topology_st.standalone.modify_s(ldbm_config, [(ldap.MOD_REPLACE, DBLOCK_ATTR_CONFIG, "-1")]) + topology_st.standalone.modify_s(ldbm_config, [(ldap.MOD_REPLACE, DBLOCK_ATTR_CONFIG, b"-1")]) except ldap.UNWILLING_TO_PERFORM: pass _check_monitored_value(topology_st, DBLOCK_EDIT_UPDATE) @@ -265,7 +265,7 @@ def test_ticket48906_dblock_robust(topology_st): # Check insuffisant value too_small = int(DBLOCK_MIN_UPDATE) - 1 try: - topology_st.standalone.modify_s(ldbm_config, [(ldap.MOD_REPLACE, DBLOCK_ATTR_CONFIG, str(too_small))]) + topology_st.standalone.modify_s(ldbm_config, [(ldap.MOD_REPLACE, DBLOCK_ATTR_CONFIG, ensure_bytes(str(too_small)))]) except ldap.UNWILLING_TO_PERFORM: pass _check_monitored_value(topology_st, DBLOCK_EDIT_UPDATE) @@ -273,14 +273,14 @@ def test_ticket48906_dblock_robust(topology_st): # Check invalid value try: - topology_st.standalone.modify_s(ldbm_config, [(ldap.MOD_REPLACE, DBLOCK_ATTR_CONFIG, "dummy")]) + topology_st.standalone.modify_s(ldbm_config, [(ldap.MOD_REPLACE, DBLOCK_ATTR_CONFIG, b"dummy")]) except ldap.UNWILLING_TO_PERFORM: pass _check_monitored_value(topology_st, DBLOCK_EDIT_UPDATE) _check_configured_value(topology_st, attr=DBLOCK_ATTR_CONFIG, expected_value=DBLOCK_LDAP_UPDATE, required=True) # now check the minimal value - topology_st.standalone.modify_s(ldbm_config, [(ldap.MOD_REPLACE, DBLOCK_ATTR_CONFIG, DBLOCK_MIN_UPDATE)]) + topology_st.standalone.modify_s(ldbm_config, [(ldap.MOD_REPLACE, DBLOCK_ATTR_CONFIG, ensure_bytes(DBLOCK_MIN_UPDATE))]) _check_monitored_value(topology_st, DBLOCK_EDIT_UPDATE) _check_configured_value(topology_st, attr=DBLOCK_ATTR_CONFIG, expected_value=DBLOCK_MIN_UPDATE, required=True) diff --git a/dirsrvtests/tests/tickets/ticket49020_test.py b/dirsrvtests/tests/tickets/ticket49020_test.py index f4fc8df..c4f94d5 100644 --- a/dirsrvtests/tests/tickets/ticket49020_test.py +++ b/dirsrvtests/tests/tickets/ticket49020_test.py @@ -9,6 +9,7 @@ from lib389.properties import * from lib389.tasks import * from lib389.utils import * from lib389.topologies import topology_m3 as T +import socket # Skip on older versions pytestmark = pytest.mark.skipif(ds_is_older('1.3.6'), reason="Not implemented") @@ -42,8 +43,7 @@ def test_ticket49020(T): A.add_s(Entry((dn, {'objectclass': "top person".split(), 'sn': name,'cn': name}))) - A.agreement.init(DEFAULT_SUFFIX, HOST_MASTER_3, PORT_MASTER_3) - + A.agreement.init(DEFAULT_SUFFIX, socket.gethostname(), PORT_MASTER_3) time.sleep(5) for i in range(1,11): name = "userY{}".format(i) @@ -70,4 +70,3 @@ if __name__ == '__main__': # -s for DEBUG mode CURRENT_FILE = os.path.realpath(__file__) pytest.main("-s %s" % CURRENT_FILE) - diff --git a/dirsrvtests/tests/tickets/ticket49039_test.py b/dirsrvtests/tests/tickets/ticket49039_test.py index f6b768c..377940c 100644 --- a/dirsrvtests/tests/tickets/ticket49039_test.py +++ b/dirsrvtests/tests/tickets/ticket49039_test.py @@ -9,6 +9,7 @@ from lib389.properties import * from lib389.tasks import * from lib389.utils import * from lib389.topologies import topology_st as topo +from lib389.pwpolicy import PwPolicyManager DEBUGGING = os.getenv("DEBUGGING", default=False) @@ -19,46 +20,6 @@ else: log = logging.getLogger(__name__) USER_DN = 'uid=user,dc=example,dc=com' -CONFIG_DN = 'cn=config' -ENCRYPTION_DN = 'cn=encryption,%s' % CONFIG_DN -RSA = 'RSA' -RSA_DN = 'cn=%s,%s' % (RSA, ENCRYPTION_DN) -ISSUER = 'cn=CAcert' -CACERT = 'CAcertificate' -SERVERCERT = 'Server-Cert' - - -def ssl_init(topo): - """ Setup TLS - """ - topo.standalone.stop() - topo.standalone.nss_ssl.reinit() - topo.standalone.nss_ssl.create_rsa_ca() - topo.standalone.nss_ssl.create_rsa_key_and_cert() - topo.standalone.start() - - topo.standalone.modify_s(ENCRYPTION_DN, - [(ldap.MOD_REPLACE, 'nsSSL3', 'off'), - (ldap.MOD_REPLACE, 'nsTLS1', 'on'), - (ldap.MOD_REPLACE, 'nsSSLClientAuth', 'allowed'), - (ldap.MOD_REPLACE, 'allowWeakCipher', 'on'), - (ldap.MOD_REPLACE, 'nsSSL3Ciphers', '+all')]) - - time.sleep(1) - topo.standalone.modify_s(CONFIG_DN, [(ldap.MOD_REPLACE, 'nsslapd-security', 'on'), - (ldap.MOD_REPLACE, 'nsslapd-ssl-check-hostname', 'off'), - (ldap.MOD_REPLACE, 'nsslapd-secureport', '636')]) - - time.sleep(1) - topo.standalone.add_s(Entry((RSA_DN, {'objectclass': "top nsEncryptionModule".split(), - 'cn': RSA, - 'nsSSLPersonalitySSL': SERVERCERT, - 'nsSSLToken': 'internal (software)', - 'nsSSLActivation': 'on'}))) - time.sleep(1) - topo.standalone.restart() - - log.info("SSL setup complete\n") def test_ticket49039(topo): @@ -67,16 +28,17 @@ def test_ticket49039(topo): """ # Setup SSL (for ldappasswd test) - ssl_init(topo) + topo.standalone.enable_tls() # Configure password policy try: - topo.standalone.modify_s("cn=config", [(ldap.MOD_REPLACE, 'nsslapd-pwpolicy-local', 'on'), - (ldap.MOD_REPLACE, 'passwordMustChange', 'on'), - (ldap.MOD_REPLACE, 'passwordExp', 'on'), - (ldap.MOD_REPLACE, 'passwordMaxAge', '86400000'), - (ldap.MOD_REPLACE, 'passwordMinAge', '8640000'), - (ldap.MOD_REPLACE, 'passwordChange', 'on')]) + policy = PwPolicyManager(topo.standalone) + policy.set_global_policy(properties={'nsslapd-pwpolicy-local': 'on', + 'passwordMustChange': 'on', + 'passwordExp': 'on', + 'passwordMaxAge': '86400000', + 'passwordMinAge': '8640000', + 'passwordChange': 'on'}) except ldap.LDAPError as e: log.fatal('Failed to set password policy: ' + str(e)) @@ -88,14 +50,14 @@ def test_ticket49039(topo): 'userpassword': PASSWORD }))) except ldap.LDAPError as e: - log.fatal('Failed to add user: error ' + e.message['desc']) + log.fatal('Failed to add user: error ' + e.args[0]['desc']) assert False # Reset password as RootDN try: - topo.standalone.modify_s(USER_DN, [(ldap.MOD_REPLACE, 'userpassword', PASSWORD)]) + topo.standalone.modify_s(USER_DN, [(ldap.MOD_REPLACE, 'userpassword', ensure_bytes(PASSWORD))]) except ldap.LDAPError as e: - log.fatal('Failed to bind: error ' + e.message['desc']) + log.fatal('Failed to bind: error ' + e.args[0]['desc']) assert False time.sleep(1) @@ -104,13 +66,13 @@ def test_ticket49039(topo): try: topo.standalone.simple_bind_s(USER_DN, PASSWORD) except ldap.LDAPError as e: - log.fatal('Failed to bind: error ' + e.message['desc']) + log.fatal('Failed to bind: error ' + e.args[0]['desc']) assert False try: - topo.standalone.modify_s(USER_DN, [(ldap.MOD_REPLACE, 'userpassword', PASSWORD)]) + topo.standalone.modify_s(USER_DN, [(ldap.MOD_REPLACE, 'userpassword', ensure_bytes(PASSWORD))]) except ldap.LDAPError as e: - log.fatal('Failed to change password: error ' + e.message['desc']) + log.fatal('Failed to change password: error ' + e.args[0]['desc']) assert False ################################### @@ -121,13 +83,13 @@ def test_ticket49039(topo): try: topo.standalone.simple_bind_s(DN_DM, PASSWORD) except ldap.LDAPError as e: - log.fatal('Failed to bind as rootdn: error ' + e.message['desc']) + log.fatal('Failed to bind as rootdn: error ' + e.args[0]['desc']) assert False try: - topo.standalone.modify_s(USER_DN, [(ldap.MOD_REPLACE, 'userpassword', PASSWORD)]) + topo.standalone.modify_s(USER_DN, [(ldap.MOD_REPLACE, 'userpassword', ensure_bytes(PASSWORD))]) except ldap.LDAPError as e: - log.fatal('Failed to bind: error ' + e.message['desc']) + log.fatal('Failed to bind: error ' + e.args[0]['desc']) assert False time.sleep(1) @@ -142,7 +104,7 @@ def test_ticket49039(topo): try: topo.standalone.simple_bind_s(USER_DN, "password2") except ldap.LDAPError as e: - log.fatal('Failed to bind: error ' + e.message['desc']) + log.fatal('Failed to bind: error ' + e.args[0]['desc']) assert False log.info('Test Passed') @@ -153,4 +115,3 @@ if __name__ == '__main__': # -s for DEBUG mode CURRENT_FILE = os.path.realpath(__file__) pytest.main("-s %s" % CURRENT_FILE) - diff --git a/dirsrvtests/tests/tickets/ticket49121_test.py b/dirsrvtests/tests/tickets/ticket49121_test.py index 74ec611..931ab88 100644 --- a/dirsrvtests/tests/tickets/ticket49121_test.py +++ b/dirsrvtests/tests/tickets/ticket49121_test.py @@ -7,7 +7,6 @@ # --- END COPYRIGHT BLOCK --- # import pytest -import sys import codecs from lib389.tasks import * from lib389.utils import * @@ -26,7 +25,10 @@ else: logging.getLogger(__name__).setLevel(logging.INFO) log = logging.getLogger(__name__) +ds_paths = Paths() + +@pytest.mark.skipif(not ds_paths.asan_enabled, reason="Don't run if ASAN is not enabled") def test_ticket49121(topology_m2): """ Creating some users. @@ -35,16 +37,13 @@ def test_ticket49121(topology_m2): Under the conditions, it did not estimate the size of string format entry shorter than the real size and caused the Invalid write / server crash. """ - reload(sys) - sys.setdefaultencoding('utf-8') - log.info('DefaultEncoding: %s' % sys.getdefaultencoding()) - + utf8file = os.path.join(topology_m2.ms["master1"].getDir(__file__, DATA_DIR), "ticket49121/utf8str.txt") utf8obj = codecs.open(utf8file, 'r', 'utf-8') utf8strorig = utf8obj.readline() - utf8str = utf8strorig.encode('utf-8').rstrip('\n') + utf8str = ensure_bytes(utf8strorig).rstrip(b'\n') utf8obj.close() - assert(utf8str) + assert (utf8str) # Get the sbin directory so we know where to replace 'ns-slapd' sbin_dir = topology_m2.ms["master1"].get_sbin_dir() @@ -57,10 +56,6 @@ def test_ticket49121(topology_m2): # wait for the servers shutdown time.sleep(5) - # Enable valgrind - if not topology_m2.ms["master1"].has_asan(): - valgrind_enable(sbin_dir) - # start M1 to do the next updates topology_m2.ms["master1"].start() topology_m2.ms["master2"].start() @@ -70,11 +65,11 @@ def test_ticket49121(topology_m2): USER_DN = 'CN=user%d,ou=People,%s' % (idx, DEFAULT_SUFFIX) log.info('adding user %s...' % (USER_DN)) topology_m2.ms["master1"].add_s(Entry((USER_DN, - {'objectclass': 'top person extensibleObject'.split(' '), - 'cn': 'user%d' % idx, - 'sn': 'SN%d-%s' % (idx, utf8str)}))) + {'objectclass': 'top person extensibleObject'.split(' '), + 'cn': 'user%d' % idx, + 'sn': 'SN%d-%s' % (idx, utf8str)}))) except ldap.LDAPError as e: - log.fatal('Failed to add user (%s): error %s' % (USER_DN, e.message['desc'])) + log.fatal('Failed to add user (%s): error %s' % (USER_DN, e.args[0]['desc'])) assert False for i in range(1, 3): @@ -84,122 +79,115 @@ def test_ticket49121(topology_m2): USER_DN = 'CN=user%d,ou=People,%s' % (idx, DEFAULT_SUFFIX) log.info('[%d] modify user %s - replacing attrs...' % (i, USER_DN)) topology_m2.ms["master1"].modify_s( - USER_DN, [(ldap.MOD_REPLACE, 'cn', 'user%d' % idx), - (ldap.MOD_REPLACE, 'ABCDEFGH_ID', ['239001ad-06dd-e011-80fa-c00000ad5174', - '240f0878-c552-e411-b0f3-000006040037']), - (ldap.MOD_REPLACE, 'attr1', 'NEW_ATTR'), - (ldap.MOD_REPLACE, 'attr20000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr30000000000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr40000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr50000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr600000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr7000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr8000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr900000000000000000', None), - (ldap.MOD_REPLACE, 'attr1000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr110000000000000', None), - (ldap.MOD_REPLACE, 'attr120000000000000', None), - (ldap.MOD_REPLACE, 'attr130000000000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr140000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr150000000000000000000000000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr1600000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr17000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr18000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr1900000000000000000', None), - (ldap.MOD_REPLACE, 'attr2000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr210000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr220000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr230000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr240000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr25000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr260000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr270000000000000000000000000000000000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr280000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr29000000000000000000000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr3000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr310000000000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr320000000000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr330000000000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr340000000000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr350000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr360000000000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr370000000000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr380000000000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr390000000000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr4000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr410000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr420000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr430000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr440000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr4500000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr460000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr470000000000000000000000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr480000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr49000000000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr5000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr510000000000000', None), - (ldap.MOD_REPLACE, 'attr520000000000000', None), - (ldap.MOD_REPLACE, 'attr530000000000000', None), - (ldap.MOD_REPLACE, 'attr540000000000000', None), - (ldap.MOD_REPLACE, 'attr550000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr5600000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr57000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr58000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr5900000000000000000', None), - (ldap.MOD_REPLACE, 'attr6000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr6100000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr6200000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr6300000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr6400000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr65000000000000000000000000000000000000000000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr6600000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr6700000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr6800000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr690000000000000000000000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr7000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr71000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr72000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr73000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr74000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr750000000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr7600000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr77000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr78000000000000000000000000000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr79000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr800000000000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr81000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr82000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr83000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr84000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr85000000000000000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr8600000000000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr87000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr88000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr89000000000000000000000000000000000', None), - (ldap.MOD_REPLACE, 'attr9000000000000000000000000000000000000000000000000000', None)]) + USER_DN, [(ldap.MOD_REPLACE, 'cn', b'user%d' % idx), + (ldap.MOD_REPLACE, 'ABCDEFGH_ID', [b'239001ad-06dd-e011-80fa-c00000ad5174', + b'240f0878-c552-e411-b0f3-000006040037']), + (ldap.MOD_REPLACE, 'attr1', b'NEW_ATTR'), + (ldap.MOD_REPLACE, 'attr20000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr30000000000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr40000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr50000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr600000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr7000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr8000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr900000000000000000', None), + (ldap.MOD_REPLACE, 'attr1000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr110000000000000', None), + (ldap.MOD_REPLACE, 'attr120000000000000', None), + (ldap.MOD_REPLACE, 'attr130000000000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr140000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr150000000000000000000000000000000000000000000000000000000000000', + None), + (ldap.MOD_REPLACE, 'attr1600000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr17000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr18000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr1900000000000000000', None), + (ldap.MOD_REPLACE, 'attr2000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr210000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr220000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr230000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr240000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr25000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr260000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, + 'attr270000000000000000000000000000000000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr280000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr29000000000000000000000000000000000000000000000000000000000', + None), + (ldap.MOD_REPLACE, 'attr3000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr310000000000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr320000000000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr330000000000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr340000000000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr350000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr360000000000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr370000000000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr380000000000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr390000000000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr4000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr410000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr420000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr430000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr440000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr4500000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr460000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr470000000000000000000000000000000000000000000000000000000000', + None), + (ldap.MOD_REPLACE, 'attr480000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr49000000000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr5000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr510000000000000', None), + (ldap.MOD_REPLACE, 'attr520000000000000', None), + (ldap.MOD_REPLACE, 'attr530000000000000', None), + (ldap.MOD_REPLACE, 'attr540000000000000', None), + (ldap.MOD_REPLACE, 'attr550000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr5600000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr57000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr58000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr5900000000000000000', None), + (ldap.MOD_REPLACE, 'attr6000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr6100000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr6200000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr6300000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr6400000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, + 'attr65000000000000000000000000000000000000000000000000000000000000000000000000000000', + None), + (ldap.MOD_REPLACE, 'attr6600000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr6700000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr6800000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr690000000000000000000000000000000000000000000000000000000000', + None), + (ldap.MOD_REPLACE, 'attr7000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr71000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr72000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr73000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr74000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr750000000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr7600000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr77000000000000000000000000000000', None), + ( + ldap.MOD_REPLACE, 'attr78000000000000000000000000000000000000000000000000000000000000000', + None), + (ldap.MOD_REPLACE, 'attr79000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr800000000000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr81000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr82000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr83000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr84000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr85000000000000000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr8600000000000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr87000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr88000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr89000000000000000000000000000000000', None), + (ldap.MOD_REPLACE, 'attr9000000000000000000000000000000000000000000000000000', None)]) except ldap.LDAPError as e: - log.fatal('Failed to modify user - deleting attrs (%s): error %s' % (USER_DN, e.message['desc'])) - - if not topology_m2.ms["master1"].has_asan(): - results_file = valgrind_get_results_file(topology_m2.ms["master1"]) + log.fatal('Failed to modify user - deleting attrs (%s): error %s' % (USER_DN, e.args[0]['desc'])) # Stop master2 topology_m2.ms["master1"].stop(30) topology_m2.ms["master2"].stop(30) - # Check for leak - if not topology_m2.ms["master1"].has_asan(): - # Check for invalid read/write - if valgrind_check_file(results_file, VALGRIND_INVALID_STR): - log.info('Valgrind reported invalid!') - assert False - else: - log.info('Valgrind is happy!') - - # Disable valgrind - if not topology_m2.ms["master1"].has_asan(): - valgrind_disable(sbin_dir) - # start M1 to do the next updates topology_m2.ms["master1"].start() topology_m2.ms["master2"].start() @@ -209,6 +197,7 @@ def test_ticket49121(topology_m2): # Add debugging steps(if any)... pass + if __name__ == '__main__': # Run isolated # -s for DEBUG mode diff --git a/dirsrvtests/tests/tickets/ticket49180_test.py b/dirsrvtests/tests/tickets/ticket49180_test.py index c41c442..0c74a69 100644 --- a/dirsrvtests/tests/tickets/ticket49180_test.py +++ b/dirsrvtests/tests/tickets/ticket49180_test.py @@ -12,13 +12,9 @@ import pytest from lib389.tasks import * from lib389.utils import * from lib389.topologies import topology_m4 +from lib389.replica import ReplicationManager -from lib389._constants import (DEFAULT_SUFFIX, REPLICA_RUV_FILTER, ReplicaRole, - REPLICAID_MASTER_4, REPLICAID_MASTER_3, REPLICAID_MASTER_2, - REPLICAID_MASTER_1, REPLICATION_BIND_DN, REPLICATION_BIND_PW, - REPLICATION_BIND_METHOD, REPLICATION_TRANSPORT, SUFFIX, - RA_NAME, RA_BINDDN, RA_BINDPW, RA_METHOD, RA_TRANSPORT_PROT, - defaultProperties, args_instance) +from lib389._constants import (DEFAULT_SUFFIX, SUFFIX) from lib389 import DirSrv @@ -40,7 +36,7 @@ def remove_master4_agmts(msg, topology_m4): assert False -def restore_master4(topology_m4, newReplicaId=REPLICAID_MASTER_4): +def restore_master4(topology_m4): """In our tests will always be removing master 4, so we need a common way to restore it for another test """ @@ -48,56 +44,12 @@ def restore_master4(topology_m4, newReplicaId=REPLICAID_MASTER_4): log.info('Restoring master 4...') # Enable replication on master 4 - topology_m4.ms["master4"].replica.enableReplication(suffix=SUFFIX, role=ReplicaRole.MASTER, - replicaId=newReplicaId) - - for num in range(1, 4): - host_to = topology_m4.ms["master{}".format(num)].host - port_to = topology_m4.ms["master{}".format(num)].port - properties = {RA_NAME: 'meTo_{}:{}'.format(host_to, port_to), - RA_BINDDN: defaultProperties[REPLICATION_BIND_DN], - RA_BINDPW: defaultProperties[REPLICATION_BIND_PW], - RA_METHOD: defaultProperties[REPLICATION_BIND_METHOD], - RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]} - agmt = topology_m4.ms["master4"].agreement.create(suffix=SUFFIX, host=host_to, - port=port_to, properties=properties) - if not agmt: - log.fatal("Fail to create a master -> master replica agreement") - assert False - log.debug("%s created" % agmt) - - host_to = topology_m4.ms["master4"].host - port_to = topology_m4.ms["master4"].port - properties = {RA_NAME: 'meTo_{}:{}'.format(host_to, port_to), - RA_BINDDN: defaultProperties[REPLICATION_BIND_DN], - RA_BINDPW: defaultProperties[REPLICATION_BIND_PW], - RA_METHOD: defaultProperties[REPLICATION_BIND_METHOD], - RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]} - agmt = topology_m4.ms["master{}".format(num)].agreement.create(suffix=SUFFIX, host=host_to, - port=port_to, properties=properties) - if not agmt: - log.fatal("Fail to create a master -> master replica agreement") - assert False - log.debug("%s created" % agmt) - - # Stop the servers - this allows the rid(for master4) to be used again - for num in range(1, 5): - topology_m4.ms["master{}".format(num)].stop(timeout=30) - - # Initialize the agreements - topology_m4.ms["master1"].start(timeout=30) - for num in range(2, 5): - host_to = topology_m4.ms["master{}".format(num)].host - port_to = topology_m4.ms["master{}".format(num)].port - topology_m4.ms["master{}".format(num)].start(timeout=30) - time.sleep(5) - topology_m4.ms["master1"].agreement.init(SUFFIX, host_to, port_to) - agreement = topology_m4.ms["master1"].agreement.list(suffix=SUFFIX, - consumer_host=host_to, - consumer_port=port_to)[0].dn - topology_m4.ms["master1"].waitForReplInit(agreement) - - time.sleep(5) + M4 = topology_m4.ms["master4"] + M1 = topology_m4.ms["master1"] + repl = ReplicationManager(SUFFIX) + repl.join_master(M1, M4) + repl.ensure_agreement(M4, M1) + repl.ensure_agreement(M1, M4) # Test Replication is working for num in range(2, 5): @@ -145,24 +97,24 @@ def test_ticket49180(topology_m4): remove_master4_agmts("test_clean", topology_m4) # Cleanup - restore master 4 - restore_master4(topology_m4, 4444) - + restore_master4(topology_m4) attr_errors = os.popen('egrep "attrlist_replace" %s | wc -l' % topology_m4.ms["master1"].errlog) - ecount = int(attr_errors.readline().rstrip()) + ecount = int(attr_errors.readline().rstrip()) log.info("Errors found on m1: %d" % ecount) assert (ecount == 0) attr_errors = os.popen('egrep "attrlist_replace" %s | wc -l' % topology_m4.ms["master2"].errlog) - ecount = int(attr_errors.readline().rstrip()) + ecount = int(attr_errors.readline().rstrip()) log.info("Errors found on m2: %d" % ecount) assert (ecount == 0) attr_errors = os.popen('egrep "attrlist_replace" %s | wc -l' % topology_m4.ms["master3"].errlog) - ecount = int(attr_errors.readline().rstrip()) + ecount = int(attr_errors.readline().rstrip()) log.info("Errors found on m3: %d" % ecount) assert (ecount == 0) + if __name__ == '__main__': # Run isolated # -s for DEBUG mode diff --git a/dirsrvtests/tests/tickets/ticket49287_test.py b/dirsrvtests/tests/tickets/ticket49287_test.py index 21ccf60..e3da788 100644 --- a/dirsrvtests/tests/tickets/ticket49287_test.py +++ b/dirsrvtests/tests/tickets/ticket49287_test.py @@ -12,6 +12,7 @@ from lib389.utils import * from lib389.properties import RA_NAME, RA_BINDDN, RA_BINDPW, RA_METHOD, RA_TRANSPORT_PROT, BACKEND_NAME from lib389.topologies import topology_m2 from lib389._constants import * +from lib389.replica import ReplicationManager DEBUGGING = os.getenv('DEBUGGING', False) GROUP_DN = ("cn=group," + DEFAULT_SUFFIX) @@ -23,11 +24,11 @@ else: log = logging.getLogger(__name__) -def _add_repl_backend(s1, s2, be, rid): +def _add_repl_backend(s1, s2, be): suffix = 'ou=%s,dc=test,dc=com' % be create_backend(s1, s2, suffix, be) add_ou(s1, suffix) - replicate_backend(s1, s2, suffix, rid) + replicate_backend(s1, s2, suffix) def _wait_for_sync(s1, s2, testbase, final_db): @@ -68,7 +69,7 @@ def config_memberof(server): MEMBEROF_PLUGIN_DN = ('cn=' + PLUGIN_MEMBER_OF + ',cn=plugins,cn=config') server.modify_s(MEMBEROF_PLUGIN_DN, [(ldap.MOD_REPLACE, 'memberOfAllBackends', - 'on')]) + b'on')]) # Configure fractional to prevent total init to send memberof ents = server.agreement.list(suffix=DEFAULT_SUFFIX) log.info('update %s to add nsDS5ReplicatedAttributeListTotal' % ents[0].dn) @@ -76,22 +77,22 @@ def config_memberof(server): server.modify_s(ent.dn, [(ldap.MOD_REPLACE, 'nsDS5ReplicatedAttributeListTotal', - '(objectclass=*) $ EXCLUDE '), + b'(objectclass=*) $ EXCLUDE '), (ldap.MOD_REPLACE, 'nsDS5ReplicatedAttributeList', - '(objectclass=*) $ EXCLUDE memberOf')]) + b'(objectclass=*) $ EXCLUDE memberOf')]) def _disable_auto_oc_memberof(server): MEMBEROF_PLUGIN_DN = ('cn=' + PLUGIN_MEMBER_OF + ',cn=plugins,cn=config') server.modify_s(MEMBEROF_PLUGIN_DN, - [(ldap.MOD_REPLACE, 'memberOfAutoAddOC', 'nsContainer')]) + [(ldap.MOD_REPLACE, 'memberOfAutoAddOC', b'nsContainer')]) def _enable_auto_oc_memberof(server): MEMBEROF_PLUGIN_DN = ('cn=' + PLUGIN_MEMBER_OF + ',cn=plugins,cn=config') server.modify_s(MEMBEROF_PLUGIN_DN, - [(ldap.MOD_REPLACE, 'memberOfAutoAddOC', 'nsMemberOf')]) + [(ldap.MOD_REPLACE, 'memberOfAutoAddOC', b'nsMemberOf')]) def add_dc(server, dn): @@ -131,7 +132,8 @@ def add_multi_member(server, cn, mem_id, mem_usr, testbase, sleep=True): members = [] for usr in mem_usr: members.append('cn=a%d,ou=be_%d,%s' % (mem_id, usr, testbase)) - mod = [(ldap.MOD_ADD, 'member', members)] + for mem in members: + mod = [(ldap.MOD_ADD, 'member', ensure_bytes(mem))] try: server.modify_s(dn, mod) except ldap.OBJECT_CLASS_VIOLATION: @@ -144,7 +146,7 @@ def add_multi_member(server, cn, mem_id, mem_usr, testbase, sleep=True): def add_member(server, cn, mem, testbase, sleep=True): dn = 'cn=%s,ou=groups,%s' % (cn, testbase) mem_dn = 'cn=%s,ou=people,%s' % (mem, testbase) - mod = [(ldap.MOD_ADD, 'member', mem_dn)] + mod = [(ldap.MOD_ADD, 'member', ensure_bytes(mem_dn))] server.modify_s(dn, mod) if sleep: time.sleep(2) @@ -161,7 +163,7 @@ def add_group(server, testbase, nr, sleep=True): ], 'description': 'group %d' % nr}))) if sleep: - time.sleep(2) + time.sleep(2) def del_group(server, testbase, nr, sleep=True): @@ -174,7 +176,7 @@ def del_group(server, testbase, nr, sleep=True): def mod_entry(server, cn, testbase, desc): dn = 'cn=%s,%s' % (cn, testbase) - mod = [(ldap.MOD_ADD, 'description', desc)] + mod = [(ldap.MOD_ADD, 'description', ensure_bytes(desc))] server.modify_s(dn, mod) time.sleep(2) @@ -186,32 +188,14 @@ def del_entry(server, testbase, cn): def _disable_nunc_stans(server): - server.modify_s(DN_CONFIG, - [(ldap.MOD_REPLACE, 'nsslapd-enable-nunc-stans', 'off')]) + server.config.set('nsslapd-enable-nunc-stans', 'off') def _enable_spec_logging(server): - mods = [(ldap.MOD_REPLACE, 'nsslapd-accesslog-level', str(260)), # Internal op - (ldap.MOD_REPLACE, 'nsslapd-errorlog-level', str(8192 + 65536)), - # (ldap.MOD_REPLACE, 'nsslapd-errorlog-level', str(8192+32768+524288)), - # (ldap.MOD_REPLACE, 'nsslapd-errorlog-level', str(8192)), - (ldap.MOD_REPLACE, 'nsslapd-plugin-logging', 'on')] - server.modify_s(DN_CONFIG, mods) - server.modify_s(DN_CONFIG, - [(ldap.MOD_REPLACE, 'nsslapd-auditlog-logging-enabled', 'on')]) - - -def create_agmt(s1, s2, replSuffix): - properties = {RA_NAME: 'meTo_{}:{}'.format(s1.host, str(s2.port)), - RA_BINDDN: defaultProperties[REPLICATION_BIND_DN], - RA_BINDPW: defaultProperties[REPLICATION_BIND_PW], - RA_METHOD: defaultProperties[REPLICATION_BIND_METHOD], - RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]} - new_agmt = s1.agreement.create(suffix=replSuffix, - host=s2.host, - port=s2.port, - properties=properties) - return new_agmt + server.config.replace_many(('nsslapd-accesslog-level', '260'), + ('nsslapd-errorlog-level', str(8192 + 65536)), + ('nsslapd-plugin-logging', 'on'), + ('nsslapd-auditlog-logging-enabled', 'on')) def create_backend(s1, s2, beSuffix, beName): @@ -221,16 +205,14 @@ def create_backend(s1, s2, beSuffix, beName): s2.backend.create(beSuffix, {BACKEND_NAME: beName}) -def replicate_backend(s1, s2, beSuffix, rid): - s1.replica.enableReplication(suffix=beSuffix, role=ReplicaRole.MASTER, replicaId=rid) - s2.replica.enableReplication(suffix=beSuffix, role=ReplicaRole.MASTER, replicaId=rid + 1) - +def replicate_backend(s1, s2, beSuffix): + repl = ReplicationManager(beSuffix) + repl.create_first_master(s1) + repl.join_master(s1, s2) + repl.ensure_agreement(s1, s2) + repl.ensure_agreement(s2, s2) # agreement m2_m1_agmt is not needed... :p - - s1s2_agmt = create_agmt(s1, s2, beSuffix) - s2s1_agmt = create_agmt(s2, s1, beSuffix) - s1.agreement.init(beSuffix, s2.host, s2.port) - s1.waitForReplInit(s1s2_agmt) + # def check_group_mods(server1, server2, group, testbase): @@ -278,7 +260,6 @@ def test_ticket49287(topology_m2): """ # return - M1 = topology_m2.ms["master1"] M2 = topology_m2.ms["master2"] @@ -299,13 +280,13 @@ def test_ticket49287(topology_m2): create_backend(M1, M2, testbase, bename) add_dc(M1, testbase) add_ou(M1, 'ou=groups,%s' % testbase) - replicate_backend(M1, M2, testbase, 100) + replicate_backend(M1, M2, testbase) peoplebase = 'ou=people,dc=test,dc=com' peoplebe = 'people' create_backend(M1, M2, peoplebase, peoplebe) add_ou(M1, peoplebase) - replicate_backend(M1, M2, peoplebase, 100) + replicate_backend(M1, M2, peoplebase) for i in range(10): cn = 'a%d' % i @@ -325,7 +306,7 @@ def test_ticket49287(topology_m2): # test group with members in multiple backends for i in range(7): be = "be_%d" % i - _add_repl_backend(M1, M2, be, 300 + i) + _add_repl_backend(M1, M2, be) # add entries akllowing meberof for i in range(1, 7): diff --git a/dirsrvtests/tests/tickets/ticket49303_test.py b/dirsrvtests/tests/tickets/ticket49303_test.py index 89972a9..70cbfa6 100644 --- a/dirsrvtests/tests/tickets/ticket49303_test.py +++ b/dirsrvtests/tests/tickets/ticket49303_test.py @@ -12,6 +12,7 @@ import os import subprocess import pytest from lib389.topologies import topology_st as topo +from lib389.nss_ssl import NssSsl from lib389._constants import SECUREPORT_STANDALONE1, HOST_STANDALONE1 @@ -45,7 +46,7 @@ def try_reneg(host, port): proc.kill() # This 'R' command is intercepted by openssl and triggers a renegotiation - proc.communicate('R\n') + proc.communicate(b'R\n') # We rely on openssl returning 0 if no errors occured, and 1 if any did # (for example, the server rejecting renegotiation and terminating the @@ -55,11 +56,11 @@ def try_reneg(host, port): def enable_ssl(server, ldapsport): server.stop() - server.nss_ssl.reinit() - server.nss_ssl.create_rsa_ca() - server.nss_ssl.create_rsa_key_and_cert() + nss_ssl = NssSsl(dbpath=server.get_cert_dir()) + nss_ssl.reinit() + nss_ssl.create_rsa_ca() + nss_ssl.create_rsa_key_and_cert() server.start() - server.rsa.create() server.config.set('nsslapd-secureport', '%s' % ldapsport) server.config.set('nsslapd-security', 'on') server.sslport = SECUREPORT_STANDALONE1