ticket48170_test.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import os
  2. import sys
  3. import time
  4. import ldap
  5. import logging
  6. import pytest
  7. from lib389 import DirSrv, Entry, tools, tasks
  8. from lib389.tools import DirSrvTools
  9. from lib389._constants import *
  10. from lib389.properties import *
  11. from lib389.tasks import *
  12. from lib389.utils import *
  13. logging.getLogger(__name__).setLevel(logging.DEBUG)
  14. log = logging.getLogger(__name__)
  15. installation1_prefix = None
  16. class TopologyStandalone(object):
  17. def __init__(self, standalone):
  18. standalone.open()
  19. self.standalone = standalone
  20. @pytest.fixture(scope="module")
  21. def topology(request):
  22. global installation1_prefix
  23. if installation1_prefix:
  24. args_instance[SER_DEPLOYED_DIR] = installation1_prefix
  25. # Creating standalone instance ...
  26. standalone = DirSrv(verbose=False)
  27. args_instance[SER_HOST] = HOST_STANDALONE
  28. args_instance[SER_PORT] = PORT_STANDALONE
  29. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  30. args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
  31. args_standalone = args_instance.copy()
  32. standalone.allocate(args_standalone)
  33. instance_standalone = standalone.exists()
  34. if instance_standalone:
  35. standalone.delete()
  36. standalone.create()
  37. standalone.open()
  38. # Clear out the tmp dir
  39. standalone.clearTmpDir(__file__)
  40. return TopologyStandalone(standalone)
  41. def test_ticket48170(topology):
  42. '''
  43. Attempt to add a nsIndexType wikth an invalid value: "eq,pres"
  44. '''
  45. INDEX_DN = 'cn=cn,cn=index,cn=userroot,cn=ldbm database,cn=plugins,cn=config'
  46. REJECTED = False
  47. try:
  48. topology.standalone.modify_s(INDEX_DN, [(ldap.MOD_ADD, 'nsINdexType', 'eq,pres')])
  49. except ldap.UNWILLING_TO_PERFORM:
  50. log.info('Index update correctly rejected')
  51. REJECTED = True
  52. if not REJECTED:
  53. log.fatal('Invalid nsIndexType value was incorrectly accepted.')
  54. assert False
  55. log.info('Test complete')
  56. def test_ticket48170_final(topology):
  57. topology.standalone.delete()
  58. log.info('Testcase PASSED')
  59. def run_isolated():
  60. global installation1_prefix
  61. installation1_prefix = None
  62. topo = topology(True)
  63. test_ticket48170(topo)
  64. test_ticket48170_final(topo)
  65. if __name__ == '__main__':
  66. run_isolated()