ticket47808_test.py 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 ldap
  11. import pytest
  12. from lib389 import Entry
  13. from lib389._constants import *
  14. from lib389.topologies import topology_st
  15. log = logging.getLogger(__name__)
  16. ATTRIBUTE_UNIQUENESS_PLUGIN = 'cn=attribute uniqueness,cn=plugins,cn=config'
  17. ENTRY_NAME = 'test_entry'
  18. def test_ticket47808_run(topology_st):
  19. """
  20. It enables attribute uniqueness plugin with sn as a unique attribute
  21. Add an entry 1 with sn = ENTRY_NAME
  22. Add an entry 2 with sn = ENTRY_NAME
  23. If the second add does not crash the server and the following search found none,
  24. the bug is fixed.
  25. """
  26. # bind as directory manager
  27. topology_st.standalone.log.info("Bind as %s" % DN_DM)
  28. topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
  29. topology_st.standalone.log.info("\n\n######################### SETUP ATTR UNIQ PLUGIN ######################\n")
  30. # enable attribute uniqueness plugin
  31. mod = [(ldap.MOD_REPLACE, 'nsslapd-pluginEnabled', 'on'), (ldap.MOD_REPLACE, 'nsslapd-pluginarg0', 'sn'),
  32. (ldap.MOD_REPLACE, 'nsslapd-pluginarg1', SUFFIX)]
  33. topology_st.standalone.modify_s(ATTRIBUTE_UNIQUENESS_PLUGIN, mod)
  34. topology_st.standalone.log.info("\n\n######################### ADD USER 1 ######################\n")
  35. # Prepare entry 1
  36. entry_name = '%s 1' % (ENTRY_NAME)
  37. entry_dn_1 = 'cn=%s, %s' % (entry_name, SUFFIX)
  38. entry_1 = Entry(entry_dn_1)
  39. entry_1.setValues('objectclass', 'top', 'person')
  40. entry_1.setValues('sn', ENTRY_NAME)
  41. entry_1.setValues('cn', entry_name)
  42. topology_st.standalone.log.info("Try to add Add %s: %r" % (entry_1, entry_1))
  43. topology_st.standalone.add_s(entry_1)
  44. topology_st.standalone.log.info("\n\n######################### Restart Server ######################\n")
  45. topology_st.standalone.stop(timeout=10)
  46. topology_st.standalone.start(timeout=10)
  47. topology_st.standalone.log.info("\n\n######################### ADD USER 2 ######################\n")
  48. # Prepare entry 2 having the same sn, which crashes the server
  49. entry_name = '%s 2' % (ENTRY_NAME)
  50. entry_dn_2 = 'cn=%s, %s' % (entry_name, SUFFIX)
  51. entry_2 = Entry(entry_dn_2)
  52. entry_2.setValues('objectclass', 'top', 'person')
  53. entry_2.setValues('sn', ENTRY_NAME)
  54. entry_2.setValues('cn', entry_name)
  55. topology_st.standalone.log.info("Try to add Add %s: %r" % (entry_2, entry_2))
  56. try:
  57. topology_st.standalone.add_s(entry_2)
  58. except:
  59. topology_st.standalone.log.warn("Adding %s failed" % entry_dn_2)
  60. pass
  61. topology_st.standalone.log.info("\n\n######################### IS SERVER UP? ######################\n")
  62. ents = topology_st.standalone.search_s(entry_dn_1, ldap.SCOPE_BASE, '(objectclass=*)')
  63. assert len(ents) == 1
  64. topology_st.standalone.log.info("Yes, it's up.")
  65. topology_st.standalone.log.info("\n\n######################### CHECK USER 2 NOT ADDED ######################\n")
  66. topology_st.standalone.log.info("Try to search %s" % entry_dn_2)
  67. try:
  68. ents = topology_st.standalone.search_s(entry_dn_2, ldap.SCOPE_BASE, '(objectclass=*)')
  69. except ldap.NO_SUCH_OBJECT:
  70. topology_st.standalone.log.info("Found none")
  71. topology_st.standalone.log.info("\n\n######################### DELETE USER 1 ######################\n")
  72. topology_st.standalone.log.info("Try to delete %s " % entry_dn_1)
  73. topology_st.standalone.delete_s(entry_dn_1)
  74. log.info('Testcase PASSED')
  75. if __name__ == '__main__':
  76. # Run isolated
  77. # -s for DEBUG mode
  78. CURRENT_FILE = os.path.realpath(__file__)
  79. pytest.main("-s %s" % CURRENT_FILE)