| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- import os
- import ldap
- import logging
- import pytest
- from lib389 import DirSrv, Entry
- from lib389._constants import *
- from lib389.properties import *
- from lib389.tasks import *
- from lib389.utils import *
- logging.getLogger(__name__).setLevel(logging.DEBUG)
- log = logging.getLogger(__name__)
- installation1_prefix = None
- class TopologyStandalone(object):
- def __init__(self, standalone):
- standalone.open()
- self.standalone = standalone
- @pytest.fixture(scope="module")
- def topology(request):
- global installation1_prefix
- if installation1_prefix:
- args_instance[SER_DEPLOYED_DIR] = installation1_prefix
- # Creating standalone instance ...
- standalone = DirSrv(verbose=False)
- args_instance[SER_HOST] = HOST_STANDALONE
- args_instance[SER_PORT] = PORT_STANDALONE
- args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
- args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
- args_standalone = args_instance.copy()
- standalone.allocate(args_standalone)
- instance_standalone = standalone.exists()
- if instance_standalone:
- standalone.delete()
- standalone.create()
- standalone.open()
- # Delete each instance in the end
- def fin():
- standalone.delete()
- request.addfinalizer(fin)
- # Clear out the tmp dir
- standalone.clearTmpDir(__file__)
- return TopologyStandalone(standalone)
- def test_ticket48370(topology):
- """
- Deleting attirbute values and readding a value does not properly update
- the pres index. The values are not actually deleted from the index
- """
- DN = 'uid=user0099,' + DEFAULT_SUFFIX
- #
- # Add an entry
- #
- topology.standalone.add_s(Entry((DN, {
- 'objectclass': ['top', 'person',
- 'organizationalPerson',
- 'inetorgperson',
- 'posixAccount'],
- 'givenname': 'test',
- 'sn': 'user',
- 'loginshell': '/bin/bash',
- 'uidNumber': '10099',
- 'gidNumber': '10099',
- 'gecos': 'Test User',
- 'mail': ['[email protected]',
- '[email protected]',
- '[email protected]'],
- 'cn': 'Test User',
- 'homeDirectory': '/home/user0099',
- 'uid': 'admin2',
- 'userpassword': 'password'})))
- #
- # Perform modify (delete & add mail attributes)
- #
- try:
- topology.standalone.modify_s(DN, [(ldap.MOD_DELETE,
- 'mail',
- '[email protected]'),
- (ldap.MOD_DELETE,
- 'mail',
- '[email protected]'),
- (ldap.MOD_ADD,
- 'mail', '[email protected]')])
- except ldap.LDAPError as e:
- log.fatal('Failedto modify user: ' + str(e))
- assert False
- #
- # Search using deleted attribute value- no entries should be returned
- #
- try:
- entry = topology.standalone.search_s(DEFAULT_SUFFIX,
- ldap.SCOPE_SUBTREE,
- '[email protected]')
- if entry:
- log.fatal('Entry incorrectly returned')
- assert False
- except ldap.LDAPError as e:
- log.fatal('Failed to search for user: ' + str(e))
- assert False
- #
- # Search using existing attribute value - the entry should be returned
- #
- try:
- entry = topology.standalone.search_s(DEFAULT_SUFFIX,
- ldap.SCOPE_SUBTREE,
- '[email protected]')
- if entry is None:
- log.fatal('Entry not found, but it should have been')
- assert False
- except ldap.LDAPError as e:
- log.fatal('Failed to search for user: ' + str(e))
- assert False
- #
- # Delete the last values
- #
- try:
- topology.standalone.modify_s(DN, [(ldap.MOD_DELETE,
- 'mail',
- '[email protected]'),
- (ldap.MOD_DELETE,
- 'mail',
- '[email protected]')
- ])
- except ldap.LDAPError as e:
- log.fatal('Failed to modify user: ' + str(e))
- assert False
- #
- # Search using deleted attribute value - no entries should be returned
- #
- try:
- entry = topology.standalone.search_s(DEFAULT_SUFFIX,
- ldap.SCOPE_SUBTREE,
- '[email protected]')
- if entry:
- log.fatal('Entry incorrectly returned')
- assert False
- except ldap.LDAPError as e:
- log.fatal('Failed to search for user: ' + str(e))
- assert False
- #
- # Make sure presence index is correctly updated - no entries should be
- # returned
- #
- try:
- entry = topology.standalone.search_s(DEFAULT_SUFFIX,
- ldap.SCOPE_SUBTREE,
- 'mail=*')
- if entry:
- log.fatal('Entry incorrectly returned')
- assert False
- except ldap.LDAPError as e:
- log.fatal('Failed to search for user: ' + str(e))
- assert False
- #
- # Now add the attributes back, and lets run a different set of tests with
- # a different number of attributes
- #
- try:
- topology.standalone.modify_s(DN, [(ldap.MOD_ADD,
- 'mail',
- ['[email protected]',
- '[email protected]'])])
- except ldap.LDAPError as e:
- log.fatal('Failedto modify user: ' + str(e))
- assert False
- #
- # Remove and readd some attibutes
- #
- try:
- topology.standalone.modify_s(DN, [(ldap.MOD_DELETE,
- 'mail',
- '[email protected]'),
- (ldap.MOD_DELETE,
- 'mail',
- '[email protected]'),
- (ldap.MOD_ADD,
- 'mail', '[email protected]')])
- except ldap.LDAPError as e:
- log.fatal('Failedto modify user: ' + str(e))
- assert False
- #
- # Search using deleted attribute value - no entries should be returned
- #
- try:
- entry = topology.standalone.search_s(DEFAULT_SUFFIX,
- ldap.SCOPE_SUBTREE,
- '[email protected]')
- if entry:
- log.fatal('Entry incorrectly returned')
- assert False
- except ldap.LDAPError as e:
- log.fatal('Failed to search for user: ' + str(e))
- assert False
- #
- # Search using existing attribute value - the entry should be returned
- #
- try:
- entry = topology.standalone.search_s(DEFAULT_SUFFIX,
- ldap.SCOPE_SUBTREE,
- '[email protected]')
- if entry is None:
- log.fatal('Entry not found, but it should have been')
- assert False
- except ldap.LDAPError as e:
- log.fatal('Failed to search for user: ' + str(e))
- assert False
- log.info('Test PASSED')
- if __name__ == '__main__':
- # Run isolated
- # -s for DEBUG mode
- CURRENT_FILE = os.path.realpath(__file__)
- pytest.main("-s %s" % CURRENT_FILE)
|