ticket48170_test.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # --- BEGIN COPYRIGHT BLOCK ---
  2. # Copyright (C) 2015 Red Hat, Inc.
  3. # All rights reserved.
  4. #
  5. # License: GPL (version 3 or any later version).
  6. # See LICENSE for details.
  7. # --- END COPYRIGHT BLOCK ---
  8. #
  9. import os
  10. import sys
  11. import time
  12. import ldap
  13. import logging
  14. import pytest
  15. from lib389 import DirSrv, Entry, tools, tasks
  16. from lib389.tools import DirSrvTools
  17. from lib389._constants import *
  18. from lib389.properties import *
  19. from lib389.tasks import *
  20. from lib389.utils import *
  21. logging.getLogger(__name__).setLevel(logging.DEBUG)
  22. log = logging.getLogger(__name__)
  23. installation1_prefix = None
  24. class TopologyStandalone(object):
  25. def __init__(self, standalone):
  26. standalone.open()
  27. self.standalone = standalone
  28. @pytest.fixture(scope="module")
  29. def topology(request):
  30. global installation1_prefix
  31. if installation1_prefix:
  32. args_instance[SER_DEPLOYED_DIR] = installation1_prefix
  33. # Creating standalone instance ...
  34. standalone = DirSrv(verbose=False)
  35. args_instance[SER_HOST] = HOST_STANDALONE
  36. args_instance[SER_PORT] = PORT_STANDALONE
  37. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  38. args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
  39. args_standalone = args_instance.copy()
  40. standalone.allocate(args_standalone)
  41. instance_standalone = standalone.exists()
  42. if instance_standalone:
  43. standalone.delete()
  44. standalone.create()
  45. standalone.open()
  46. def fin():
  47. standalone.delete()
  48. request.addfinalizer(fin)
  49. return TopologyStandalone(standalone)
  50. def test_ticket48170(topology):
  51. '''
  52. Attempt to add a nsIndexType wikth an invalid value: "eq,pres"
  53. '''
  54. INDEX_DN = 'cn=cn,cn=index,cn=userroot,cn=ldbm database,cn=plugins,cn=config'
  55. REJECTED = False
  56. try:
  57. topology.standalone.modify_s(INDEX_DN, [(ldap.MOD_ADD, 'nsINdexType', 'eq,pres')])
  58. except ldap.UNWILLING_TO_PERFORM:
  59. log.info('Index update correctly rejected')
  60. REJECTED = True
  61. if not REJECTED:
  62. log.fatal('Invalid nsIndexType value was incorrectly accepted.')
  63. assert False
  64. log.info('Test complete')
  65. if __name__ == '__main__':
  66. # Run isolated
  67. # -s for DEBUG mode
  68. CURRENT_FILE = os.path.realpath(__file__)
  69. pytest.main("-s %s" % CURRENT_FILE)