ticket49095_test.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import time
  2. import ldap
  3. import logging
  4. import pytest
  5. from lib389 import DirSrv, Entry, tools, tasks
  6. from lib389.tools import DirSrvTools
  7. from lib389._constants import *
  8. from lib389.properties import *
  9. from lib389.tasks import *
  10. from lib389.utils import *
  11. from lib389.topologies import topology_st as topo
  12. DEBUGGING = os.getenv("DEBUGGING", default=False)
  13. if DEBUGGING:
  14. logging.getLogger(__name__).setLevel(logging.DEBUG)
  15. else:
  16. logging.getLogger(__name__).setLevel(logging.INFO)
  17. log = logging.getLogger(__name__)
  18. USER_DN = 'uid=testuser,dc=example,dc=com'
  19. acis = ['(targetattr != "tele*") (version 3.0;acl "test case";allow (read,compare,search)(userdn = "ldap:///anyone");)',
  20. '(targetattr != "TELE*") (version 3.0;acl "test case";allow (read,compare,search)(userdn = "ldap:///anyone");)',
  21. '(targetattr != "telephonenum*") (version 3.0;acl "test case";allow (read,compare,search)(userdn = "ldap:///anyone");)',
  22. '(targetattr != "TELEPHONENUM*") (version 3.0;acl "test case";allow (read,compare,search)(userdn = "ldap:///anyone");)']
  23. def test_ticket49095(topo):
  24. """Check that target attrbiutes with wildcards are case insensitive
  25. """
  26. # Add an entry
  27. try:
  28. topo.standalone.add_s(Entry((USER_DN, {
  29. 'objectclass': 'top extensibleObject'.split(),
  30. 'uid': 'testuser',
  31. 'telephonenumber': '555-555-5555'
  32. })))
  33. except ldap.LDAPError as e:
  34. log.fatal('Failed to add test user: ' + e.message['desc'])
  35. assert False
  36. for aci in acis:
  37. # Add ACI
  38. try:
  39. topo.standalone.modify_s(DEFAULT_SUFFIX,
  40. [(ldap.MOD_REPLACE, 'aci', aci)])
  41. except ldap.LDAPError as e:
  42. log.fatal('Failed to set aci: ' + aci + ': ' + e.message['desc'])
  43. assert False
  44. # Set Anonymous Bind to test aci
  45. try:
  46. topo.standalone.simple_bind_s("", "")
  47. except ldap.LDAPError as e:
  48. log.fatal('Failed to bind anonymously: ' + e.message['desc'])
  49. assert False
  50. # Search for entry - should not get any results
  51. try:
  52. entry = topo.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_BASE,
  53. 'telephonenumber=*')
  54. if entry:
  55. log.fatal('The entry was incorrectly returned')
  56. assert False
  57. except ldap.LDAPError as e:
  58. log.fatal('Failed to search anonymously: ' + e.message['desc'])
  59. assert False
  60. # Set root DN Bind so we can update aci's
  61. try:
  62. topo.standalone.simple_bind_s(DN_DM, PASSWORD)
  63. except ldap.LDAPError as e:
  64. log.fatal('Failed to bind anonymously: ' + e.message['desc'])
  65. assert False
  66. log.info("Test Passed")
  67. if __name__ == '__main__':
  68. # Run isolated
  69. # -s for DEBUG mode
  70. CURRENT_FILE = os.path.realpath(__file__)
  71. pytest.main("-s %s" % CURRENT_FILE)