| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013 |
- import os
- import sys
- import time
- import ldap
- import logging
- import pytest
- import re
- import shutil
- from lib389 import DirSrv, Entry, tools
- from lib389.tools import DirSrvTools
- from lib389._constants import *
- from lib389.properties import *
- log = logging.getLogger(__name__)
- installation_prefix = None
- PROVISIONING_CN = "provisioning"
- PROVISIONING_DN = "cn=%s,%s" % (PROVISIONING_CN, SUFFIX)
- ACTIVE_CN = "accounts"
- STAGE_CN = "staged users"
- DELETE_CN = "deleted users"
- ACTIVE_DN = "cn=%s,%s" % (ACTIVE_CN, SUFFIX)
- STAGE_DN = "cn=%s,%s" % (STAGE_CN, PROVISIONING_DN)
- DELETE_DN = "cn=%s,%s" % (DELETE_CN, PROVISIONING_DN)
- STAGE_USER_CN = "stage guy"
- STAGE_USER_DN = "cn=%s,%s" % (STAGE_USER_CN, STAGE_DN)
- ACTIVE_USER_CN = "active guy"
- ACTIVE_USER_DN = "cn=%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN)
- ACTIVE_USER_1_CN = "test_1"
- ACTIVE_USER_1_DN = "cn=%s,%s" % (ACTIVE_USER_1_CN, ACTIVE_DN)
- ACTIVE_USER_2_CN = "test_2"
- ACTIVE_USER_2_DN = "cn=%s,%s" % (ACTIVE_USER_2_CN, ACTIVE_DN)
- STAGE_USER_1_CN = ACTIVE_USER_1_CN
- STAGE_USER_1_DN = "cn=%s,%s" % (STAGE_USER_1_CN, STAGE_DN)
- STAGE_USER_2_CN = ACTIVE_USER_2_CN
- STAGE_USER_2_DN = "cn=%s,%s" % (STAGE_USER_2_CN, STAGE_DN)
- ALL_CONFIG_ATTRS = ['nsslapd-pluginarg0', 'nsslapd-pluginarg1', 'nsslapd-pluginarg2',
- 'uniqueness-attribute-name', 'uniqueness-subtrees', 'uniqueness-across-all-subtrees']
- class TopologyStandalone(object):
- def __init__(self, standalone):
- standalone.open()
- self.standalone = standalone
- @pytest.fixture(scope="module")
- def topology(request):
- '''
- This fixture is used to standalone topology for the 'module'.
- '''
- global installation_prefix
- standalone = DirSrv(verbose=False)
- if installation_prefix:
- args_instance[SER_DEPLOYED_DIR] = installation_prefix
- # Args for the standalone instance
- args_instance[SER_HOST] = HOST_STANDALONE
- args_instance[SER_PORT] = PORT_STANDALONE
- args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
- args_standalone = args_instance.copy()
- standalone.allocate(args_standalone)
- # Get the status of the instance and restart it if it exists
- instance_standalone = standalone.exists()
- # Remove the instance
- if instance_standalone:
- standalone.delete()
- # Create the instance
- standalone.create()
- # Used to retrieve configuration information (dbdir, confdir...)
- standalone.open()
- # clear the tmp directory
- standalone.clearTmpDir(__file__)
- # Here we have standalone instance up and running
- return TopologyStandalone(standalone)
- def _header(topology, label):
- topology.standalone.log.info("\n\n###############################################")
- topology.standalone.log.info("#######")
- topology.standalone.log.info("####### %s" % label)
- topology.standalone.log.info("#######")
- topology.standalone.log.info("###############################################")
- def _uniqueness_config_entry(topology, name=None):
- if not name:
- return None
- ent = topology.standalone.getEntry("cn=%s,%s" % (PLUGIN_ATTR_UNIQUENESS, DN_PLUGIN), ldap.SCOPE_BASE,
- "(objectclass=nsSlapdPlugin)",
- ['objectClass', 'cn', 'nsslapd-pluginPath', 'nsslapd-pluginInitfunc',
- 'nsslapd-pluginType', 'nsslapd-pluginEnabled', 'nsslapd-plugin-depends-on-type',
- 'nsslapd-pluginId', 'nsslapd-pluginVersion', 'nsslapd-pluginVendor',
- 'nsslapd-pluginDescription'])
- ent.dn = "cn=%s uniqueness,%s" % (name, DN_PLUGIN)
- return ent
- def _build_config(topology, attr_name='cn', subtree_1=None, subtree_2=None, type_config='old', across_subtrees=False):
- assert topology
- assert attr_name
- assert subtree_1
- if type_config == 'old':
- # enable the 'cn' uniqueness on Active
- config = _uniqueness_config_entry(topology, attr_name)
- config.setValue('nsslapd-pluginarg0', attr_name)
- config.setValue('nsslapd-pluginarg1', subtree_1)
- if subtree_2:
- config.setValue('nsslapd-pluginarg2', subtree_2)
- else:
- # prepare the config entry
- config = _uniqueness_config_entry(topology, attr_name)
- config.setValue('uniqueness-attribute-name', attr_name)
- config.setValue('uniqueness-subtrees', subtree_1)
- if subtree_2:
- config.setValue('uniqueness-subtrees', subtree_2)
- if across_subtrees:
- config.setValue('uniqueness-across-all-subtrees', 'on')
- return config
- def _active_container_invalid_cfg_add(topology):
- '''
- Check uniqueness is not enforced with ADD (invalid config)
- '''
- topology.standalone.add_s(Entry((ACTIVE_USER_1_DN, {
- 'objectclass': "top person".split(),
- 'sn': ACTIVE_USER_1_CN,
- 'cn': ACTIVE_USER_1_CN})))
- topology.standalone.add_s(Entry((ACTIVE_USER_2_DN, {
- 'objectclass': "top person".split(),
- 'sn': ACTIVE_USER_2_CN,
- 'cn': [ACTIVE_USER_1_CN, ACTIVE_USER_2_CN]})))
- topology.standalone.delete_s(ACTIVE_USER_1_DN)
- topology.standalone.delete_s(ACTIVE_USER_2_DN)
- def _active_container_add(topology, type_config='old'):
- '''
- Check uniqueness in a single container (Active)
- Add an entry with a given 'cn', then check we can not add an entry with the same 'cn' value
- '''
- config = _build_config(topology, attr_name='cn', subtree_1=ACTIVE_DN, subtree_2=None, type_config=type_config, across_subtrees=False)
- # remove the 'cn' uniqueness entry
- try:
- topology.standalone.delete_s(config.dn)
- except ldap.NO_SUCH_OBJECT:
- pass
- topology.standalone.restart(timeout=120)
- topology.standalone.log.info('Uniqueness not enforced: create the entries')
- topology.standalone.add_s(Entry((ACTIVE_USER_1_DN, {
- 'objectclass': "top person".split(),
- 'sn': ACTIVE_USER_1_CN,
- 'cn': ACTIVE_USER_1_CN})))
- topology.standalone.add_s(Entry((ACTIVE_USER_2_DN, {
- 'objectclass': "top person".split(),
- 'sn': ACTIVE_USER_2_CN,
- 'cn': [ACTIVE_USER_1_CN, ACTIVE_USER_2_CN]})))
- topology.standalone.delete_s(ACTIVE_USER_1_DN)
- topology.standalone.delete_s(ACTIVE_USER_2_DN)
- topology.standalone.log.info('Uniqueness enforced: checks second entry is rejected')
- # enable the 'cn' uniqueness on Active
- topology.standalone.add_s(config)
- topology.standalone.restart(timeout=120)
- topology.standalone.add_s(Entry((ACTIVE_USER_1_DN, {
- 'objectclass': "top person".split(),
- 'sn': ACTIVE_USER_1_CN,
- 'cn': ACTIVE_USER_1_CN})))
- try:
- topology.standalone.add_s(Entry((ACTIVE_USER_2_DN, {
- 'objectclass': "top person".split(),
- 'sn': ACTIVE_USER_2_CN,
- 'cn': [ACTIVE_USER_1_CN, ACTIVE_USER_2_CN]})))
- except ldap.CONSTRAINT_VIOLATION:
- # yes it is expected
- pass
- # cleanup the stuff now
- topology.standalone.delete_s(config.dn)
- topology.standalone.delete_s(ACTIVE_USER_1_DN)
- def _active_container_mod(topology, type_config='old'):
- '''
- Check uniqueness in a single container (active)
- Add and entry with a given 'cn', then check we can not modify an entry with the same 'cn' value
- '''
- config = _build_config(topology, attr_name='cn', subtree_1=ACTIVE_DN, subtree_2=None, type_config=type_config, across_subtrees=False)
- # enable the 'cn' uniqueness on Active
- topology.standalone.add_s(config)
- topology.standalone.restart(timeout=120)
- topology.standalone.log.info('Uniqueness enforced: checks MOD ADD entry is rejected')
- topology.standalone.add_s(Entry((ACTIVE_USER_1_DN, {
- 'objectclass': "top person".split(),
- 'sn': ACTIVE_USER_1_CN,
- 'cn': ACTIVE_USER_1_CN})))
- topology.standalone.add_s(Entry((ACTIVE_USER_2_DN, {
- 'objectclass': "top person".split(),
- 'sn': ACTIVE_USER_2_CN,
- 'cn': ACTIVE_USER_2_CN})))
- try:
- topology.standalone.modify_s(ACTIVE_USER_2_DN, [(ldap.MOD_ADD, 'cn', ACTIVE_USER_1_CN)])
- except ldap.CONSTRAINT_VIOLATION:
- # yes it is expected
- pass
- topology.standalone.log.info('Uniqueness enforced: checks MOD REPLACE entry is rejected')
- try:
- topology.standalone.modify_s(ACTIVE_USER_2_DN, [(ldap.MOD_REPLACE, 'cn', [ACTIVE_USER_1_CN, ACTIVE_USER_2_CN])])
- except ldap.CONSTRAINT_VIOLATION:
- # yes it is expected
- pass
- # cleanup the stuff now
- topology.standalone.delete_s(config.dn)
- topology.standalone.delete_s(ACTIVE_USER_1_DN)
- topology.standalone.delete_s(ACTIVE_USER_2_DN)
- def _active_container_modrdn(topology, type_config='old'):
- '''
- Check uniqueness in a single container
- Add and entry with a given 'cn', then check we can not modrdn an entry with the same 'cn' value
- '''
- config = _build_config(topology, attr_name='cn', subtree_1=ACTIVE_DN, subtree_2=None, type_config=type_config, across_subtrees=False)
- # enable the 'cn' uniqueness on Active
- topology.standalone.add_s(config)
- topology.standalone.restart(timeout=120)
- topology.standalone.log.info('Uniqueness enforced: checks MODRDN entry is rejected')
- topology.standalone.add_s(Entry((ACTIVE_USER_1_DN, {
- 'objectclass': "top person".split(),
- 'sn': ACTIVE_USER_1_CN,
- 'cn': [ACTIVE_USER_1_CN, 'dummy']})))
- topology.standalone.add_s(Entry((ACTIVE_USER_2_DN, {
- 'objectclass': "top person".split(),
- 'sn': ACTIVE_USER_2_CN,
- 'cn': ACTIVE_USER_2_CN})))
- try:
- topology.standalone.rename_s(ACTIVE_USER_2_DN, 'cn=dummy', delold=0)
- except ldap.CONSTRAINT_VIOLATION:
- # yes it is expected
- pass
- # cleanup the stuff now
- topology.standalone.delete_s(config.dn)
- topology.standalone.delete_s(ACTIVE_USER_1_DN)
- topology.standalone.delete_s(ACTIVE_USER_2_DN)
- def _active_stage_containers_add(topology, type_config='old', across_subtrees=False):
- '''
- Check uniqueness in several containers
- Add an entry on a container with a given 'cn'
- with across_subtrees=False check we CAN add an entry with the same 'cn' value on the other container
- with across_subtrees=True check we CAN NOT add an entry with the same 'cn' value on the other container
- '''
- config = _build_config(topology, attr_name='cn', subtree_1=ACTIVE_DN, subtree_2=STAGE_DN, type_config=type_config, across_subtrees=False)
- topology.standalone.add_s(config)
- topology.standalone.restart(timeout=120)
- topology.standalone.add_s(Entry((ACTIVE_USER_1_DN, {
- 'objectclass': "top person".split(),
- 'sn': ACTIVE_USER_1_CN,
- 'cn': ACTIVE_USER_1_CN})))
- try:
- # adding an entry on a separated contains with the same 'cn'
- topology.standalone.add_s(Entry((STAGE_USER_1_DN, {
- 'objectclass': "top person".split(),
- 'sn': STAGE_USER_1_CN,
- 'cn': ACTIVE_USER_1_CN})))
- except ldap.CONSTRAINT_VIOLATION:
- assert across_subtrees
- # cleanup the stuff now
- topology.standalone.delete_s(config.dn)
- topology.standalone.delete_s(ACTIVE_USER_1_DN)
- topology.standalone.delete_s(STAGE_USER_1_DN)
- def _active_stage_containers_mod(topology, type_config='old', across_subtrees=False):
- '''
- Check uniqueness in a several containers
- Add an entry on a container with a given 'cn', then check we CAN mod an entry with the same 'cn' value on the other container
- '''
- config = _build_config(topology, attr_name='cn', subtree_1=ACTIVE_DN, subtree_2=STAGE_DN, type_config=type_config, across_subtrees=False)
- topology.standalone.add_s(config)
- topology.standalone.restart(timeout=120)
- # adding an entry on active with a different 'cn'
- topology.standalone.add_s(Entry((ACTIVE_USER_1_DN, {
- 'objectclass': "top person".split(),
- 'sn': ACTIVE_USER_1_CN,
- 'cn': ACTIVE_USER_2_CN})))
- # adding an entry on a stage with a different 'cn'
- topology.standalone.add_s(Entry((STAGE_USER_1_DN, {
- 'objectclass': "top person".split(),
- 'sn': STAGE_USER_1_CN,
- 'cn': STAGE_USER_1_CN})))
- try:
- # modify add same value
- topology.standalone.modify_s(STAGE_USER_1_DN, [(ldap.MOD_ADD, 'cn', [ACTIVE_USER_2_CN])])
- except ldap.CONSTRAINT_VIOLATION:
- assert across_subtrees
- topology.standalone.delete_s(STAGE_USER_1_DN)
- topology.standalone.add_s(Entry((STAGE_USER_1_DN, {
- 'objectclass': "top person".split(),
- 'sn': STAGE_USER_1_CN,
- 'cn': STAGE_USER_2_CN})))
- try:
- # modify replace same value
- topology.standalone.modify_s(STAGE_USER_1_DN, [(ldap.MOD_REPLACE, 'cn', [STAGE_USER_2_CN, ACTIVE_USER_1_CN])])
- except ldap.CONSTRAINT_VIOLATION:
- assert across_subtrees
- # cleanup the stuff now
- topology.standalone.delete_s(config.dn)
- topology.standalone.delete_s(ACTIVE_USER_1_DN)
- topology.standalone.delete_s(STAGE_USER_1_DN)
- def _active_stage_containers_modrdn(topology, type_config='old', across_subtrees=False):
- '''
- Check uniqueness in a several containers
- Add and entry with a given 'cn', then check we CAN modrdn an entry with the same 'cn' value on the other container
- '''
- config = _build_config(topology, attr_name='cn', subtree_1=ACTIVE_DN, subtree_2=STAGE_DN, type_config=type_config, across_subtrees=False)
- # enable the 'cn' uniqueness on Active and Stage
- topology.standalone.add_s(config)
- topology.standalone.restart(timeout=120)
- topology.standalone.add_s(Entry((ACTIVE_USER_1_DN, {
- 'objectclass': "top person".split(),
- 'sn': ACTIVE_USER_1_CN,
- 'cn': [ACTIVE_USER_1_CN, 'dummy']})))
- topology.standalone.add_s(Entry((STAGE_USER_1_DN, {
- 'objectclass': "top person".split(),
- 'sn': STAGE_USER_1_CN,
- 'cn': STAGE_USER_1_CN})))
- try:
- topology.standalone.rename_s(STAGE_USER_1_DN, 'cn=dummy', delold=0)
- # check stage entry has 'cn=dummy'
- stage_ent = topology.standalone.getEntry("cn=dummy,%s" % (STAGE_DN), ldap.SCOPE_BASE, "objectclass=*", ['cn'])
- assert stage_ent.hasAttr('cn')
- found = False
- for value in stage_ent.getValues('cn'):
- if value == 'dummy':
- found = True
- assert found
- # check active entry has 'cn=dummy'
- active_ent = topology.standalone.getEntry(ACTIVE_USER_1_DN, ldap.SCOPE_BASE, "objectclass=*", ['cn'])
- assert active_ent.hasAttr('cn')
- found = False
- for value in stage_ent.getValues('cn'):
- if value == 'dummy':
- found = True
- assert found
- topology.standalone.delete_s("cn=dummy,%s" % (STAGE_DN))
- except ldap.CONSTRAINT_VIOLATION:
- assert across_subtrees
- topology.standalone.delete_s(STAGE_USER_1_DN)
- # cleanup the stuff now
- topology.standalone.delete_s(config.dn)
- topology.standalone.delete_s(ACTIVE_USER_1_DN)
- def _config_file(topology, action='save'):
- dse_ldif = topology.standalone.confdir + '/dse.ldif'
- sav_file = topology.standalone.confdir + '/dse.ldif.ticket47823'
- if action == 'save':
- shutil.copy(dse_ldif, sav_file)
- else:
- shutil.copy(sav_file, dse_ldif)
- def _pattern_errorlog(file, log_pattern):
- try:
- _pattern_errorlog.last_pos += 1
- except AttributeError:
- _pattern_errorlog.last_pos = 0
- found = None
- log.debug("_pattern_errorlog: start at offset %d" % _pattern_errorlog.last_pos)
- file.seek(_pattern_errorlog.last_pos)
- # Use a while true iteration because 'for line in file: hit a
- # python bug that break file.tell()
- while True:
- line = file.readline()
- log.debug("_pattern_errorlog: [%d] %s" % (file.tell(), line))
- found = log_pattern.search(line)
- if ((line == '') or (found)):
- break
- log.debug("_pattern_errorlog: end at offset %d" % file.tell())
- _pattern_errorlog.last_pos = file.tell()
- return found
- def test_ticket47823_init(topology):
- """
- """
- # Enabled the plugins
- topology.standalone.plugins.enable(name=PLUGIN_ATTR_UNIQUENESS)
- topology.standalone.restart(timeout=120)
- topology.standalone.add_s(Entry((PROVISIONING_DN, {'objectclass': "top nscontainer".split(),
- 'cn': PROVISIONING_CN})))
- topology.standalone.add_s(Entry((ACTIVE_DN, {'objectclass': "top nscontainer".split(),
- 'cn': ACTIVE_CN})))
- topology.standalone.add_s(Entry((STAGE_DN, {'objectclass': "top nscontainer".split(),
- 'cn': STAGE_CN})))
- topology.standalone.add_s(Entry((DELETE_DN, {'objectclass': "top nscontainer".split(),
- 'cn': DELETE_CN})))
- topology.standalone.errorlog_file = open(topology.standalone.errlog, "r")
- topology.standalone.stop(timeout=120)
- time.sleep(1)
- topology.standalone.start(timeout=120)
- time.sleep(3)
- def test_ticket47823_one_container_add(topology):
- '''
- Check uniqueness in a single container
- Add and entry with a given 'cn', then check we can not add an entry with the same 'cn' value
- '''
- _header(topology, "With former config (args), check attribute uniqueness with 'cn' (ADD) ")
- _active_container_add(topology, type_config='old')
- _header(topology, "With new config (args), check attribute uniqueness with 'cn' (ADD) ")
- _active_container_add(topology, type_config='new')
- def test_ticket47823_one_container_mod(topology):
- '''
- Check uniqueness in a single container
- Add and entry with a given 'cn', then check we can not modify an entry with the same 'cn' value
- '''
- _header(topology, "With former config (args), check attribute uniqueness with 'cn' (MOD)")
- _active_container_mod(topology, type_config='old')
- _header(topology, "With new config (args), check attribute uniqueness with 'cn' (MOD)")
- _active_container_mod(topology, type_config='new')
- def test_ticket47823_one_container_modrdn(topology):
- '''
- Check uniqueness in a single container
- Add and entry with a given 'cn', then check we can not modrdn an entry with the same 'cn' value
- '''
- _header(topology, "With former config (args), check attribute uniqueness with 'cn' (MODRDN)")
- _active_container_modrdn(topology, type_config='old')
- _header(topology, "With former config (args), check attribute uniqueness with 'cn' (MODRDN)")
- _active_container_modrdn(topology, type_config='new')
- def test_ticket47823_multi_containers_add(topology):
- '''
- Check uniqueness in a several containers
- Add and entry with a given 'cn', then check we can not add an entry with the same 'cn' value
- '''
- _header(topology, "With former config (args), check attribute uniqueness with 'cn' (ADD) ")
- _active_stage_containers_add(topology, type_config='old', across_subtrees=False)
- _header(topology, "With new config (args), check attribute uniqueness with 'cn' (ADD) ")
- _active_stage_containers_add(topology, type_config='new', across_subtrees=False)
- def test_ticket47823_multi_containers_mod(topology):
- '''
- Check uniqueness in a several containers
- Add an entry on a container with a given 'cn', then check we CAN mod an entry with the same 'cn' value on the other container
- '''
- _header(topology, "With former config (args), check attribute uniqueness with 'cn' (MOD) on separated container")
- topology.standalone.log.info('Uniqueness not enforced: if same \'cn\' modified (add/replace) on separated containers')
- _active_stage_containers_mod(topology, type_config='old', across_subtrees=False)
- _header(topology, "With new config (args), check attribute uniqueness with 'cn' (MOD) on separated container")
- topology.standalone.log.info('Uniqueness not enforced: if same \'cn\' modified (add/replace) on separated containers')
- _active_stage_containers_mod(topology, type_config='new', across_subtrees=False)
- def test_ticket47823_multi_containers_modrdn(topology):
- '''
- Check uniqueness in a several containers
- Add and entry with a given 'cn', then check we CAN modrdn an entry with the same 'cn' value on the other container
- '''
- _header(topology, "With former config (args), check attribute uniqueness with 'cn' (MODRDN) on separated containers")
- topology.standalone.log.info('Uniqueness not enforced: checks MODRDN entry is accepted on separated containers')
- _active_stage_containers_modrdn(topology, type_config='old', across_subtrees=False)
- topology.standalone.log.info('Uniqueness not enforced: checks MODRDN entry is accepted on separated containers')
- _active_stage_containers_modrdn(topology, type_config='old')
- def test_ticket47823_across_multi_containers_add(topology):
- '''
- Check uniqueness across several containers, uniquely with the new configuration
- Add and entry with a given 'cn', then check we can not add an entry with the same 'cn' value
- '''
- _header(topology, "With new config (args), check attribute uniqueness with 'cn' (ADD) across several containers")
- _active_stage_containers_add(topology, type_config='old', across_subtrees=True)
- def test_ticket47823_across_multi_containers_mod(topology):
- '''
- Check uniqueness across several containers, uniquely with the new configuration
- Add and entry with a given 'cn', then check we can not modifiy an entry with the same 'cn' value
- '''
- _header(topology, "With new config (args), check attribute uniqueness with 'cn' (MOD) across several containers")
- _active_stage_containers_mod(topology, type_config='old', across_subtrees=True)
- def test_ticket47823_across_multi_containers_modrdn(topology):
- '''
- Check uniqueness across several containers, uniquely with the new configuration
- Add and entry with a given 'cn', then check we can not modrdn an entry with the same 'cn' value
- '''
- _header(topology, "With new config (args), check attribute uniqueness with 'cn' (MODRDN) across several containers")
- _active_stage_containers_modrdn(topology, type_config='old', across_subtrees=True)
- def test_ticket47823_invalid_config_1(topology):
- '''
- Check that an invalid config is detected. No uniqueness enforced
- Using old config: arg0 is missing
- '''
- _header(topology, "Invalid config (old): arg0 is missing")
- _config_file(topology, action='save')
- # create an invalid config without arg0
- config = _build_config(topology, attr_name='cn', subtree_1=ACTIVE_DN, subtree_2=None, type_config='old', across_subtrees=False)
- del config.data['nsslapd-pluginarg0']
- # replace 'cn' uniqueness entry
- try:
- topology.standalone.delete_s(config.dn)
- except ldap.NO_SUCH_OBJECT:
- pass
- topology.standalone.add_s(config)
- topology.standalone.getEntry(config.dn, ldap.SCOPE_BASE, "(objectclass=nsSlapdPlugin)", ALL_CONFIG_ATTRS)
- # Check the server did not restart
- topology.standalone.modify_s(DN_CONFIG, [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', '65536')])
- try:
- topology.standalone.restart(timeout=5)
- ent = topology.standalone.getEntry(config.dn, ldap.SCOPE_BASE, "(objectclass=nsSlapdPlugin)", ALL_CONFIG_ATTRS)
- if ent:
- # be sure to restore a valid config before assert
- _config_file(topology, action='restore')
- assert not ent
- except ldap.SERVER_DOWN:
- pass
- # Check the expected error message
- regex = re.compile("Config fail: unable to parse old style")
- res = _pattern_errorlog(topology.standalone.errorlog_file, regex)
- if not res:
- # be sure to restore a valid config before assert
- _config_file(topology, action='restore')
- assert res
- # Check we can restart the server
- _config_file(topology, action='restore')
- topology.standalone.start(timeout=5)
- try:
- topology.standalone.getEntry(config.dn, ldap.SCOPE_BASE, "(objectclass=nsSlapdPlugin)", ALL_CONFIG_ATTRS)
- except ldap.NO_SUCH_OBJECT:
- pass
- def test_ticket47823_invalid_config_2(topology):
- '''
- Check that an invalid config is detected. No uniqueness enforced
- Using old config: arg1 is missing
- '''
- _header(topology, "Invalid config (old): arg1 is missing")
- _config_file(topology, action='save')
- # create an invalid config without arg0
- config = _build_config(topology, attr_name='cn', subtree_1=ACTIVE_DN, subtree_2=None, type_config='old', across_subtrees=False)
- del config.data['nsslapd-pluginarg1']
- # replace 'cn' uniqueness entry
- try:
- topology.standalone.delete_s(config.dn)
- except ldap.NO_SUCH_OBJECT:
- pass
- topology.standalone.add_s(config)
- topology.standalone.getEntry(config.dn, ldap.SCOPE_BASE, "(objectclass=nsSlapdPlugin)", ALL_CONFIG_ATTRS)
- # Check the server did not restart
- try:
- topology.standalone.restart(timeout=5)
- ent = topology.standalone.getEntry(config.dn, ldap.SCOPE_BASE, "(objectclass=nsSlapdPlugin)", ALL_CONFIG_ATTRS)
- if ent:
- # be sure to restore a valid config before assert
- _config_file(topology, action='restore')
- assert not ent
- except ldap.SERVER_DOWN:
- pass
- # Check the expected error message
- regex = re.compile("Config info: No valid subtree is defined")
- res = _pattern_errorlog(topology.standalone.errorlog_file, regex)
- if not res:
- # be sure to restore a valid config before assert
- _config_file(topology, action='restore')
- assert res
- # Check we can restart the server
- _config_file(topology, action='restore')
- topology.standalone.start(timeout=5)
- try:
- topology.standalone.getEntry(config.dn, ldap.SCOPE_BASE, "(objectclass=nsSlapdPlugin)", ALL_CONFIG_ATTRS)
- except ldap.NO_SUCH_OBJECT:
- pass
- def test_ticket47823_invalid_config_3(topology):
- '''
- Check that an invalid config is detected. No uniqueness enforced
- Using old config: arg0 is missing
- '''
- _header(topology, "Invalid config (old): arg0 is missing but new config attrname exists")
- _config_file(topology, action='save')
- # create an invalid config without arg0
- config = _build_config(topology, attr_name='cn', subtree_1=ACTIVE_DN, subtree_2=None, type_config='old', across_subtrees=False)
- del config.data['nsslapd-pluginarg0']
- config.data['uniqueness-attribute-name'] = 'cn'
- # replace 'cn' uniqueness entry
- try:
- topology.standalone.delete_s(config.dn)
- except ldap.NO_SUCH_OBJECT:
- pass
- topology.standalone.add_s(config)
- topology.standalone.getEntry(config.dn, ldap.SCOPE_BASE, "(objectclass=nsSlapdPlugin)", ALL_CONFIG_ATTRS)
- # Check the server did not restart
- topology.standalone.modify_s(DN_CONFIG, [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', '65536')])
- try:
- topology.standalone.restart(timeout=5)
- ent = topology.standalone.getEntry(config.dn, ldap.SCOPE_BASE, "(objectclass=nsSlapdPlugin)", ALL_CONFIG_ATTRS)
- if ent:
- # be sure to restore a valid config before assert
- _config_file(topology, action='restore')
- assert not ent
- except ldap.SERVER_DOWN:
- pass
- # Check the expected error message
- regex = re.compile("Config fail: unable to parse old style")
- res = _pattern_errorlog(topology.standalone.errorlog_file, regex)
- if not res:
- # be sure to restore a valid config before assert
- _config_file(topology, action='restore')
- assert res
- # Check we can restart the server
- _config_file(topology, action='restore')
- topology.standalone.start(timeout=5)
- try:
- topology.standalone.getEntry(config.dn, ldap.SCOPE_BASE, "(objectclass=nsSlapdPlugin)", ALL_CONFIG_ATTRS)
- except ldap.NO_SUCH_OBJECT:
- pass
- def test_ticket47823_invalid_config_4(topology):
- '''
- Check that an invalid config is detected. No uniqueness enforced
- Using old config: arg1 is missing
- '''
- _header(topology, "Invalid config (old): arg1 is missing but new config exist")
- _config_file(topology, action='save')
- # create an invalid config without arg0
- config = _build_config(topology, attr_name='cn', subtree_1=ACTIVE_DN, subtree_2=None, type_config='old', across_subtrees=False)
- del config.data['nsslapd-pluginarg1']
- config.data['uniqueness-subtrees'] = ACTIVE_DN
- # replace 'cn' uniqueness entry
- try:
- topology.standalone.delete_s(config.dn)
- except ldap.NO_SUCH_OBJECT:
- pass
- topology.standalone.add_s(config)
- topology.standalone.getEntry(config.dn, ldap.SCOPE_BASE, "(objectclass=nsSlapdPlugin)", ALL_CONFIG_ATTRS)
- # Check the server did not restart
- try:
- topology.standalone.restart(timeout=5)
- ent = topology.standalone.getEntry(config.dn, ldap.SCOPE_BASE, "(objectclass=nsSlapdPlugin)", ALL_CONFIG_ATTRS)
- if ent:
- # be sure to restore a valid config before assert
- _config_file(topology, action='restore')
- assert not ent
- except ldap.SERVER_DOWN:
- pass
- # Check the expected error message
- regex = re.compile("Config info: No valid subtree is defined")
- res = _pattern_errorlog(topology.standalone.errorlog_file, regex)
- if not res:
- # be sure to restore a valid config before assert
- _config_file(topology, action='restore')
- assert res
- # Check we can restart the server
- _config_file(topology, action='restore')
- topology.standalone.start(timeout=5)
- try:
- topology.standalone.getEntry(config.dn, ldap.SCOPE_BASE, "(objectclass=nsSlapdPlugin)", ALL_CONFIG_ATTRS)
- except ldap.NO_SUCH_OBJECT:
- pass
- def test_ticket47823_invalid_config_5(topology):
- '''
- Check that an invalid config is detected. No uniqueness enforced
- Using new config: uniqueness-attribute-name is missing
- '''
- _header(topology, "Invalid config (new): uniqueness-attribute-name is missing")
- _config_file(topology, action='save')
- # create an invalid config without arg0
- config = _build_config(topology, attr_name='cn', subtree_1=ACTIVE_DN, subtree_2=None, type_config='new', across_subtrees=False)
- del config.data['uniqueness-attribute-name']
- # replace 'cn' uniqueness entry
- try:
- topology.standalone.delete_s(config.dn)
- except ldap.NO_SUCH_OBJECT:
- pass
- topology.standalone.add_s(config)
- topology.standalone.getEntry(config.dn, ldap.SCOPE_BASE, "(objectclass=nsSlapdPlugin)", ALL_CONFIG_ATTRS)
- # Check the server did not restart
- try:
- topology.standalone.restart(timeout=5)
- ent = topology.standalone.getEntry(config.dn, ldap.SCOPE_BASE, "(objectclass=nsSlapdPlugin)", ALL_CONFIG_ATTRS)
- if ent:
- # be sure to restore a valid config before assert
- _config_file(topology, action='restore')
- assert not ent
- except ldap.SERVER_DOWN:
- pass
- # Check the expected error message
- regex = re.compile("Config info: attribute name not defined")
- res = _pattern_errorlog(topology.standalone.errorlog_file, regex)
- if not res:
- # be sure to restore a valid config before assert
- _config_file(topology, action='restore')
- assert res
- # Check we can restart the server
- _config_file(topology, action='restore')
- topology.standalone.start(timeout=5)
- try:
- topology.standalone.getEntry(config.dn, ldap.SCOPE_BASE, "(objectclass=nsSlapdPlugin)", ALL_CONFIG_ATTRS)
- except ldap.NO_SUCH_OBJECT:
- pass
- def test_ticket47823_invalid_config_6(topology):
- '''
- Check that an invalid config is detected. No uniqueness enforced
- Using new config: uniqueness-subtrees is missing
- '''
- _header(topology, "Invalid config (new): uniqueness-subtrees is missing")
- _config_file(topology, action='save')
- # create an invalid config without arg0
- config = _build_config(topology, attr_name='cn', subtree_1=ACTIVE_DN, subtree_2=None, type_config='new', across_subtrees=False)
- del config.data['uniqueness-subtrees']
- # replace 'cn' uniqueness entry
- try:
- topology.standalone.delete_s(config.dn)
- except ldap.NO_SUCH_OBJECT:
- pass
- topology.standalone.add_s(config)
- topology.standalone.getEntry(config.dn, ldap.SCOPE_BASE, "(objectclass=nsSlapdPlugin)", ALL_CONFIG_ATTRS)
- # Check the server did not restart
- try:
- topology.standalone.restart(timeout=5)
- ent = topology.standalone.getEntry(config.dn, ldap.SCOPE_BASE, "(objectclass=nsSlapdPlugin)", ALL_CONFIG_ATTRS)
- if ent:
- # be sure to restore a valid config before assert
- _config_file(topology, action='restore')
- assert not ent
- except ldap.SERVER_DOWN:
- pass
- # Check the expected error message
- regex = re.compile("Config info: objectclass for subtree entries is not defined")
- res = _pattern_errorlog(topology.standalone.errorlog_file, regex)
- if not res:
- # be sure to restore a valid config before assert
- _config_file(topology, action='restore')
- assert res
- # Check we can restart the server
- _config_file(topology, action='restore')
- topology.standalone.start(timeout=5)
- try:
- topology.standalone.getEntry(config.dn, ldap.SCOPE_BASE, "(objectclass=nsSlapdPlugin)", ALL_CONFIG_ATTRS)
- except ldap.NO_SUCH_OBJECT:
- pass
- def test_ticket47823_invalid_config_7(topology):
- '''
- Check that an invalid config is detected. No uniqueness enforced
- Using new config: uniqueness-subtrees is missing
- '''
- _header(topology, "Invalid config (new): uniqueness-subtrees are invalid")
- _config_file(topology, action='save')
- # create an invalid config without arg0
- config = _build_config(topology, attr_name='cn', subtree_1="this_is dummy DN", subtree_2="an other=dummy DN", type_config='new', across_subtrees=False)
- topology.standalone.modify_s(DN_CONFIG, [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', '65536')])
- # replace 'cn' uniqueness entry
- try:
- topology.standalone.delete_s(config.dn)
- except ldap.NO_SUCH_OBJECT:
- pass
- topology.standalone.add_s(config)
- topology.standalone.getEntry(config.dn, ldap.SCOPE_BASE, "(objectclass=nsSlapdPlugin)", ALL_CONFIG_ATTRS)
- # Check the server did not restart
- try:
- topology.standalone.restart(timeout=5)
- ent = topology.standalone.getEntry(config.dn, ldap.SCOPE_BASE, "(objectclass=nsSlapdPlugin)", ALL_CONFIG_ATTRS)
- if ent:
- # be sure to restore a valid config before assert
- _config_file(topology, action='restore')
- assert not ent
- except ldap.SERVER_DOWN:
- pass
- # Check the expected error message
- regex = re.compile("Config info: No valid subtree is defined")
- res = _pattern_errorlog(topology.standalone.errorlog_file, regex)
- if not res:
- # be sure to restore a valid config before assert
- _config_file(topology, action='restore')
- assert res
- # Check we can restart the server
- _config_file(topology, action='restore')
- topology.standalone.start(timeout=5)
- try:
- topology.standalone.getEntry(config.dn, ldap.SCOPE_BASE, "(objectclass=nsSlapdPlugin)", ALL_CONFIG_ATTRS)
- except ldap.NO_SUCH_OBJECT:
- pass
- def test_ticket47823_final(topology):
- topology.standalone.delete()
- log.info('Testcase PASSED')
- def run_isolated():
- '''
- run_isolated is used to run these test cases independently of a test scheduler (xunit, py.test..)
- To run isolated without py.test, you need to
- - edit this file and comment '@pytest.fixture' line before 'topology' function.
- - set the installation prefix
- - run this program
- '''
- global installation_prefix
- installation_prefix = None
- topo = topology(True)
- test_ticket47823_init(topo)
- # run old/new config style that makes uniqueness checking on one subtree
- test_ticket47823_one_container_add(topo)
- test_ticket47823_one_container_mod(topo)
- test_ticket47823_one_container_modrdn(topo)
- # run old config style that makes uniqueness checking on each defined subtrees
- test_ticket47823_multi_containers_add(topo)
- test_ticket47823_multi_containers_mod(topo)
- test_ticket47823_multi_containers_modrdn(topo)
- test_ticket47823_across_multi_containers_add(topo)
- test_ticket47823_across_multi_containers_mod(topo)
- test_ticket47823_across_multi_containers_modrdn(topo)
- test_ticket47823_invalid_config_1(topo)
- test_ticket47823_invalid_config_2(topo)
- test_ticket47823_invalid_config_3(topo)
- test_ticket47823_invalid_config_4(topo)
- test_ticket47823_invalid_config_5(topo)
- test_ticket47823_invalid_config_6(topo)
- test_ticket47823_invalid_config_7(topo)
- test_ticket47823_final(topo)
- if __name__ == '__main__':
- run_isolated()
|