ticket47815_test.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # --- BEGIN COPYRIGHT BLOCK ---
  2. # Copyright (C) 2016 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 logging
  10. import time
  11. import ldap
  12. import pytest
  13. from lib389 import Entry
  14. from lib389._constants import *
  15. from lib389.topologies import topology_st
  16. log = logging.getLogger(__name__)
  17. def test_ticket47815(topology_st):
  18. """
  19. Test betxn plugins reject an invalid option, and make sure that the rejected entry
  20. is not in the entry cache.
  21. Enable memberOf, automember, and retrocl plugins
  22. Add the automember config entry
  23. Add the automember group
  24. Add a user that will be rejected by a betxn plugin - result error 53
  25. Attempt the same add again, and it should result in another error 53 (not error 68)
  26. """
  27. result = 0
  28. result2 = 0
  29. log.info(
  30. 'Testing Ticket 47815 - Add entries that should be rejected by the betxn plugins, and are not left in the entry cache')
  31. # Enabled the plugins
  32. topology_st.standalone.plugins.enable(name=PLUGIN_MEMBER_OF)
  33. topology_st.standalone.plugins.enable(name=PLUGIN_AUTOMEMBER)
  34. topology_st.standalone.plugins.enable(name=PLUGIN_RETRO_CHANGELOG)
  35. # configure automember config entry
  36. log.info('Adding automember config')
  37. try:
  38. topology_st.standalone.add_s(Entry(('cn=group cfg,cn=Auto Membership Plugin,cn=plugins,cn=config', {
  39. 'objectclass': 'top autoMemberDefinition'.split(),
  40. 'autoMemberScope': 'dc=example,dc=com',
  41. 'autoMemberFilter': 'cn=user',
  42. 'autoMemberDefaultGroup': 'cn=group,dc=example,dc=com',
  43. 'autoMemberGroupingAttr': 'member:dn',
  44. 'cn': 'group cfg'})))
  45. except:
  46. log.error('Failed to add automember config')
  47. exit(1)
  48. topology_st.standalone.stop(timeout=120)
  49. time.sleep(1)
  50. topology_st.standalone.start(timeout=120)
  51. time.sleep(3)
  52. # need to reopen a connection toward the instance
  53. topology_st.standalone.open()
  54. # add automember group
  55. log.info('Adding automember group')
  56. try:
  57. topology_st.standalone.add_s(Entry(('cn=group,dc=example,dc=com', {
  58. 'objectclass': 'top groupOfNames'.split(),
  59. 'cn': 'group'})))
  60. except:
  61. log.error('Failed to add automember group')
  62. exit(1)
  63. # add user that should result in an error 53
  64. log.info('Adding invalid entry')
  65. try:
  66. topology_st.standalone.add_s(Entry(('cn=user,dc=example,dc=com', {
  67. 'objectclass': 'top person'.split(),
  68. 'sn': 'user',
  69. 'cn': 'user'})))
  70. except ldap.UNWILLING_TO_PERFORM:
  71. log.debug('Adding invalid entry failed as expected')
  72. result = 53
  73. except ldap.LDAPError as e:
  74. log.error('Unexpected result ' + e.message['desc'])
  75. assert False
  76. if result == 0:
  77. log.error('Add operation unexpectedly succeeded')
  78. assert False
  79. # Attempt to add user again, should result in error 53 again
  80. try:
  81. topology_st.standalone.add_s(Entry(('cn=user,dc=example,dc=com', {
  82. 'objectclass': 'top person'.split(),
  83. 'sn': 'user',
  84. 'cn': 'user'})))
  85. except ldap.UNWILLING_TO_PERFORM:
  86. log.debug('2nd add of invalid entry failed as expected')
  87. result2 = 53
  88. except ldap.LDAPError as e:
  89. log.error('Unexpected result ' + e.message['desc'])
  90. assert False
  91. if result2 == 0:
  92. log.error('2nd Add operation unexpectedly succeeded')
  93. assert False
  94. if __name__ == '__main__':
  95. # Run isolated
  96. # -s for DEBUG mode
  97. CURRENT_FILE = os.path.realpath(__file__)
  98. pytest.main("-s %s" % CURRENT_FILE)