ticket47640_test.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 pytest
  10. from lib389.tasks import *
  11. from lib389.utils import *
  12. from lib389.topologies import topology_st
  13. logging.getLogger(__name__).setLevel(logging.DEBUG)
  14. log = logging.getLogger(__name__)
  15. def test_ticket47640(topology_st):
  16. '''
  17. Linked Attrs Plugins - verify that if the plugin fails to update the link entry
  18. that the entire operation is aborted
  19. '''
  20. # Enable Dynamic plugins, and the linked Attrs plugin
  21. try:
  22. topology_st.standalone.modify_s(DN_CONFIG, [(ldap.MOD_REPLACE, 'nsslapd-dynamic-plugins', 'on')])
  23. except ldap.LDAPError as e:
  24. ldap.fatal('Failed to enable dynamic plugin!' + e.message['desc'])
  25. assert False
  26. try:
  27. topology_st.standalone.plugins.enable(name=PLUGIN_LINKED_ATTRS)
  28. except ValueError as e:
  29. ldap.fatal('Failed to enable linked attributes plugin!' + e.message['desc'])
  30. assert False
  31. # Add the plugin config entry
  32. try:
  33. topology_st.standalone.add_s(Entry(('cn=manager link,cn=Linked Attributes,cn=plugins,cn=config', {
  34. 'objectclass': 'top extensibleObject'.split(),
  35. 'cn': 'Manager Link',
  36. 'linkType': 'seeAlso',
  37. 'managedType': 'seeAlso'
  38. })))
  39. except ldap.LDAPError as e:
  40. log.fatal('Failed to add linked attr config entry: error ' + e.message['desc'])
  41. assert False
  42. # Add an entry who has a link to an entry that does not exist
  43. OP_REJECTED = False
  44. try:
  45. topology_st.standalone.add_s(Entry(('uid=manager,' + DEFAULT_SUFFIX, {
  46. 'objectclass': 'top extensibleObject'.split(),
  47. 'uid': 'manager',
  48. 'seeAlso': 'uid=user,dc=example,dc=com'
  49. })))
  50. except ldap.UNWILLING_TO_PERFORM:
  51. # Success
  52. log.info('Add operation correctly rejected.')
  53. OP_REJECTED = True
  54. except ldap.LDAPError as e:
  55. log.fatal('Add operation incorrectly rejected: error %s - ' +
  56. 'expected "unwilling to perform"' % e.message['desc'])
  57. assert False
  58. if not OP_REJECTED:
  59. log.fatal('Add operation incorrectly allowed')
  60. assert False
  61. log.info('Test complete')
  62. if __name__ == '__main__':
  63. # Run isolated
  64. # -s for DEBUG mode
  65. CURRENT_FILE = os.path.realpath(__file__)
  66. pytest.main("-s %s" % CURRENT_FILE)